hide "add channel" button if the user cant create channels + public user object now shows permissions
This commit is contained in:
parent
e7615879e4
commit
e1fccd2a66
2 changed files with 16 additions and 7 deletions
|
@ -49,12 +49,14 @@
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
<button on:click="{ () => overlayStore.open('createChannel') }" class="sidebar-button">
|
{#if $userInfoStore && $userInfoStore.permissions.create_channel}
|
||||||
<div>
|
<button on:click="{ () => overlayStore.open('createChannel') }" class="sidebar-button">
|
||||||
<PlusIcon />
|
<div>
|
||||||
</div>
|
<PlusIcon />
|
||||||
<span>Create Channel</span>
|
</div>
|
||||||
</button>
|
<span>Create Channel</span>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
<button on:click="{ () => overlayStore.open('settings') }" class="sidebar-button">
|
<button on:click="{ () => overlayStore.open('settings') }" class="sidebar-button">
|
||||||
<div>
|
<div>
|
||||||
<SettingsIcon />
|
<SettingsIcon />
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue