member admin actions

This commit is contained in:
Dovi Cowan 2023-10-19 01:06:41 +01:00
parent cfff09bd91
commit c148bc7586
Signed by: dcowan
GPG key ID: C110D77558FBC227
2 changed files with 57 additions and 11 deletions

View file

@ -23,7 +23,7 @@
owner_id: loggedInUser["$id"],
})
.then((r) => {
teams.create(r["$id"], listname, ["admin"]).then((r) => {
teams.create(r["$id"], listname, ["owner"]).then((r) => {
let permissions = [
Permission.read(Role.user(loggedInUser["$id"])),
Permission.read(Role.team(r["$id"])),

View file

@ -1,7 +1,7 @@
<script>
import { Link } from "svelte-navigator";
import Header from "../../lib/Header.svelte";
import { database, teams } from "../../lib/appwrite";
import { database, loggedInUser, teams } from "../../lib/appwrite";
export let id;
@ -13,19 +13,45 @@
return index;
};
const userIsAdmin = (users, id) => {
let index = users.memberships.findIndex((e) => e.userId == id);
if (users.memberships[index].roles.includes("owner")) {
return true;
}
return false;
};
function getData() {
members = teams.listMemberships(id);
}
function inviteMember() {
let email = prompt("Enter member email address");
if (email !== "") {
teams.createMembership(
id,
[],
email,
undefined,
undefined,
"http://localhost:5173/accept_list_invitation",
);
teams
.createMembership(
id,
[],
email,
undefined,
undefined,
"http://localhost:5173/accept_list_invitation",
)
.then(() => getData());
}
}
function removeFromList(membershipId) {
teams.deleteMembership(id, membershipId).then(() => getData());
}
function makeAdmin(membershipId) {
teams.updateMembership(id, membershipId, ["owner"]).then(() => getData());
}
function removeAdmin(membershipId) {
teams.updateMembership(id, membershipId, []).then(() => getData());
}
</script>
<main class="container m-5">
@ -41,12 +67,32 @@
{#each members.memberships as member}
<div class="m-1">
{member.userName} - {member.userEmail}
{#if rolesIndex(member, "admin") !== -1}
{#if rolesIndex(member, "owner") !== -1}
<span class="border p-1">List Admin</span>
{/if}
{#if member.confirm == false}
<span class="border p-1">Pending</span>
{/if}
{#if userIsAdmin(members, loggedInUser["$id"]) && member.userId !== loggedInUser["$id"]}
<Link
class="text-blue-400"
on:click={() => removeFromList(member.$id)}
to="#">Remove from list</Link
>
{#if !userIsAdmin(members, member.userId)}
| <Link
class="text-blue-400"
on:click={() => makeAdmin(member.$id)}
to="#">Make user admin</Link
>
{:else}
| <Link
class="text-blue-400"
on:click={() => removeAdmin(member.$id)}
to="#">Remove as admin</Link
>
{/if}
{/if}
</div>
{/each}
<Link class="text-blue-400" to="#" on:click={inviteMember}