Skip to content

Commit

Permalink
fix(ui): return proper permission group for user (#3858)
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Jun 2, 2020
1 parent 7794a6b commit 99932b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/bot/users.ts
Expand Up @@ -13,6 +13,7 @@ import permissions from './permissions';
import oauth from './oauth';
import api from './api';
import currency from './currency';
import { Permissions } from './database/entity/permissions';

class Users extends Core {
uiSortCache: string | null = null;
Expand Down Expand Up @@ -350,7 +351,9 @@ class Users extends Core {
const aggregatedBits = viewer.bits.map((o) => Number(o.amount)).reduce((a, b) => a + b, 0);

const permId = await permissions.getUserHighestPermission(userId);
const permissionGroup = permId || permission.VIEWERS;
const permissionGroup = (await getRepository(Permissions).findOneOrFail({
where: { id: permId || permission.VIEWERS },
}));
cb(null, {...viewer, aggregatedBits, aggregatedTips, permission: permissionGroup});
} else {
cb(null);
Expand Down
5 changes: 3 additions & 2 deletions src/panel/components/navbar/user.vue
Expand Up @@ -58,6 +58,7 @@ import { permission } from 'src/bot/helpers/permissions'
import { library } from '@fortawesome/fontawesome-svg-core';
import { faUserCircle } from '@fortawesome/free-solid-svg-icons'
import { UserInterface } from '../../../bot/database/entity/user';
import { PermissionsInterface } from '../../../bot/database/entity/permissions';
library.add(faUserCircle);
@Component({
Expand All @@ -73,7 +74,7 @@ export default class User extends Vue {
permission = permission;
isViewerLoaded: boolean = false;
viewer: (Required<UserInterface> & { aggregatedTips: number; aggregatedBits: number; permission: string }) | null = null;
viewer: (Required<UserInterface> & { aggregatedTips: number; aggregatedBits: number; permission: PermissionsInterface }) | null = null;
beforeDestroy() {
clearInterval(this.interval);
Expand Down Expand Up @@ -121,7 +122,7 @@ export default class User extends Vue {
if (typeof this.$loggedUser === 'undefined'|| this.$loggedUser === null) {
return;
}
this.socket.emit('viewers::findOne', this.$loggedUser.id, (err: string| number, viewer: Readonly<Required<UserInterface>> & { aggregatedTips: number; aggregatedBits: number; permission: string }) => {
this.socket.emit('viewers::findOne', this.$loggedUser.id, (err: string| number, viewer: Readonly<Required<UserInterface>> & { aggregatedTips: number; aggregatedBits: number; permission: PermissionsInterface }) => {
if (err) {
return console.error(err);
}
Expand Down

0 comments on commit 99932b6

Please sign in to comment.