member admin actions
This commit is contained in:
parent
cfff09bd91
commit
c148bc7586
2 changed files with 57 additions and 11 deletions
|
@ -23,7 +23,7 @@
|
||||||
owner_id: loggedInUser["$id"],
|
owner_id: loggedInUser["$id"],
|
||||||
})
|
})
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
teams.create(r["$id"], listname, ["admin"]).then((r) => {
|
teams.create(r["$id"], listname, ["owner"]).then((r) => {
|
||||||
let permissions = [
|
let permissions = [
|
||||||
Permission.read(Role.user(loggedInUser["$id"])),
|
Permission.read(Role.user(loggedInUser["$id"])),
|
||||||
Permission.read(Role.team(r["$id"])),
|
Permission.read(Role.team(r["$id"])),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { Link } from "svelte-navigator";
|
import { Link } from "svelte-navigator";
|
||||||
import Header from "../../lib/Header.svelte";
|
import Header from "../../lib/Header.svelte";
|
||||||
import { database, teams } from "../../lib/appwrite";
|
import { database, loggedInUser, teams } from "../../lib/appwrite";
|
||||||
|
|
||||||
export let id;
|
export let id;
|
||||||
|
|
||||||
|
@ -13,19 +13,45 @@
|
||||||
return index;
|
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() {
|
function inviteMember() {
|
||||||
let email = prompt("Enter member email address");
|
let email = prompt("Enter member email address");
|
||||||
if (email !== "") {
|
if (email !== "") {
|
||||||
teams.createMembership(
|
teams
|
||||||
id,
|
.createMembership(
|
||||||
[],
|
id,
|
||||||
email,
|
[],
|
||||||
undefined,
|
email,
|
||||||
undefined,
|
undefined,
|
||||||
"http://localhost:5173/accept_list_invitation",
|
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>
|
</script>
|
||||||
|
|
||||||
<main class="container m-5">
|
<main class="container m-5">
|
||||||
|
@ -41,12 +67,32 @@
|
||||||
{#each members.memberships as member}
|
{#each members.memberships as member}
|
||||||
<div class="m-1">
|
<div class="m-1">
|
||||||
{member.userName} - {member.userEmail}
|
{member.userName} - {member.userEmail}
|
||||||
{#if rolesIndex(member, "admin") !== -1}
|
{#if rolesIndex(member, "owner") !== -1}
|
||||||
<span class="border p-1">List Admin</span>
|
<span class="border p-1">List Admin</span>
|
||||||
{/if}
|
{/if}
|
||||||
{#if member.confirm == false}
|
{#if member.confirm == false}
|
||||||
<span class="border p-1">Pending</span>
|
<span class="border p-1">Pending</span>
|
||||||
{/if}
|
{/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>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
<Link class="text-blue-400" to="#" on:click={inviteMember}
|
<Link class="text-blue-400" to="#" on:click={inviteMember}
|
||||||
|
|
Loading…
Reference in a new issue