list admin actions

This commit is contained in:
Dovi Cowan 2023-10-19 01:20:42 +01:00
parent c148bc7586
commit 00aac119f1
Signed by: dcowan
GPG key ID: C110D77558FBC227
3 changed files with 50 additions and 4 deletions

View file

@ -39,7 +39,10 @@
>{list["name"]}</Link
><br />
{/each}
<Link class="text-blue-400" to="/lists/create">Create new list</Link>
<Link
class="text-blue-400 dark:bg-gray-600 bg-gray-400 border p-1 mt-4 rounded"
to="/lists/create">Create new list</Link
>
{/await}
</div>
</main>

View file

@ -27,6 +27,8 @@
let permissions = [
Permission.read(Role.user(loggedInUser["$id"])),
Permission.read(Role.team(r["$id"])),
Permission.write(Role.team(r["$id"], 'owner')),
Permission.delete(Role.team(r["$id"], 'owner'))
];
if (requireLoggedIn == false) {

View file

@ -1,8 +1,9 @@
<script>
import { ID, Permission, Query, Role } from "appwrite";
import Header from "../../lib/Header.svelte";
import { database, loggedInUser } from "../../lib/appwrite";
import { database, loggedInUser, teams } from "../../lib/appwrite";
import { Link } from "svelte-navigator";
import { navigate } from "svelte-navigator/src/history";
export let id;
@ -14,6 +15,16 @@
perakim = r.documents;
});
let teamDetails = teams.listMemberships(id);
const userIsAdmin = (users, id) => {
let index = users.memberships.findIndex((e) => e.userId == id);
if (users.memberships[index].roles.includes("owner")) {
return true;
}
return false;
};
const perekIndex = (i) => {
let index = perakim.findIndex((e) => e.perek == i);
return index;
@ -33,7 +44,7 @@
perek: perek,
taken: true,
taken_by: loggedInUser["$id"],
taken_by_name: loggedInUser['name']
taken_by_name: loggedInUser["name"],
},
[
Permission.read(Role.team(id)),
@ -51,6 +62,26 @@
});
}
function renameList() {
let newTitle = prompt("Enter new name");
if (newTitle !== "") {
database
.updateDocument("tehillim-split", "lists", id, {
title: newTitle,
})
.then(
() => (list = database.getDocument("tehillim-split", "lists", id)),
);
}
}
function deleteList() {
database
.deleteDocument("tehillim-split", "lists", id)
.then(() => teams.delete(id).then(() => navigate("/", {})));
}
function completePerek(perek) {
let perekDBId = perakim[perekIndex(perek)]["$id"];
@ -112,7 +143,17 @@
{:then list}
<h1 class="text-2xl">List {list.title}</h1>
<br />
<Link class="text-blue-400" to="/list/{id}/members">Members</Link><br />
<Link class="text-blue-400" to="/list/{id}/members">Members</Link>
{#await teamDetails then team}
{#if userIsAdmin(team, loggedInUser["$id"])}
| <Link class="text-blue-400" to="#" on:click={() => renameList()}
>Rename list</Link
>
| <Link class="text-blue-400" to="#" on:click={() => deleteList()}
>Delete list</Link
>
{/if}
{/await}<br />
{#await perakimPromise then perakimResolved}
{#each Array.from(Array(150 + 1).keys()).slice(1) as i}
{#if perekIndex(i) !== -1}