hide "add channel" button if the user cant create channels + public user object now shows permissions

This commit is contained in:
hippoz 2022-08-04 04:51:09 +03:00
parent e7615879e4
commit e1fccd2a66
No known key found for this signature in database
GPG key ID: 7C52899193467641
2 changed files with 16 additions and 7 deletions

View file

@ -49,12 +49,14 @@
{/if} {/if}
</button> </button>
{/each} {/each}
{#if $userInfoStore && $userInfoStore.permissions.create_channel}
<button on:click="{ () => overlayStore.open('createChannel') }" class="sidebar-button"> <button on:click="{ () => overlayStore.open('createChannel') }" class="sidebar-button">
<div> <div>
<PlusIcon /> <PlusIcon />
</div> </div>
<span>Create Channel</span> <span>Create Channel</span>
</button> </button>
{/if}
<button on:click="{ () => overlayStore.open('settings') }" class="sidebar-button"> <button on:click="{ () => overlayStore.open('settings') }" class="sidebar-button">
<div> <div>
<SettingsIcon /> <SettingsIcon />

View file

@ -2,6 +2,7 @@ import { NextFunction, Request, Response } from "express";
import { JwtPayload, sign, verify } from "jsonwebtoken"; import { JwtPayload, sign, verify } from "jsonwebtoken";
import { query } from "./database"; import { query } from "./database";
import { errors } from "./errors"; import { errors } from "./errors";
import serverConfig from "./serverconfig";
const jwtSecret = process.env.JWT_SECRET || "[generic token]"; const jwtSecret = process.env.JWT_SECRET || "[generic token]";
@ -15,8 +16,14 @@ if (jwtSecret === "[generic token]") {
process.exit(1); process.exit(1);
} }
export function getUserPermissions(user: User) {
return {
create_channel: serverConfig.superuserRequirement.createChannel ? user.is_superuser : true
};
}
export function getPublicUserObject(user: User) { export function getPublicUserObject(user: User) {
const newUser = { ...user }; const newUser = { ...user, permissions: getUserPermissions(user) };
newUser.password = undefined; newUser.password = undefined;
delete newUser.password; delete newUser.password;