fix: Remade perms

This commit is contained in:
2025-06-13 15:11:57 +02:00
parent 14f355df53
commit 5cd31a4981
7 changed files with 31 additions and 58 deletions

View File

@@ -4,7 +4,7 @@ export interface User {
_id: string _id: string
uname: string uname: string
room?: string room?: string
admin?: number admin?: string[]
locked?: boolean locked?: boolean
fname?: string fname?: string
surname?: string surname?: string

View File

@@ -43,28 +43,28 @@
} @else { } @else {
<button mat-stroked-button disabled>Auto-Blokada nieczynna</button> <button mat-stroked-button disabled>Auto-Blokada nieczynna</button>
} }
@if (ls.permChecker(32)) { @if (ls.permChecker("accs")) {
<mat-form-field color="accent"> <mat-form-field color="accent">
<mat-label>Uprawnienia</mat-label> <mat-label>Uprawnienia</mat-label>
<mat-select multiple formControlName="flags"> <mat-select multiple formControlName="flags">
@if (ls.capCheck(1)) { @if (ls.capCheck(1)) {
<mat-option [value]="1">Wiadomości</mat-option> <mat-option value="news">Wiadomości</mat-option>
} }
@if (ls.capCheck(2)) { @if (ls.capCheck(2)) {
<mat-option [value]="2">Jadłospis</mat-option> <mat-option value="menu">Jadłospis</mat-option>
} }
@if (ls.capCheck(4)) { @if (ls.capCheck(4)) {
<mat-option [value]="4">Powiadomienia</mat-option> <mat-option value="notif">Powiadomienia</mat-option>
} }
@if (ls.capCheck(8)) { @if (ls.capCheck(8)) {
<mat-option [value]="8">Grupy</mat-option> <mat-option value="groups">Grupy</mat-option>
} }
<mat-option [value]="16">Konta</mat-option> <mat-option value="accs">Konta</mat-option>
@if (ls.capCheck(32)) { @if (ls.capCheck(32)) {
<mat-option [value]="64">Klucze</mat-option> <mat-option value="keys">Klucze</mat-option>
} }
@if (ls.capCheck(16)) { @if (ls.capCheck(16)) {
<mat-option [value]="128">Czystość</mat-option> <mat-option value="grades">Czystość</mat-option>
} }
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>

View File

@@ -36,7 +36,7 @@ export class UserEditComponent {
room: new FormControl<string>(''), room: new FormControl<string>(''),
uname: new FormControl<string>(''), uname: new FormControl<string>(''),
groups: new FormControl<Array<string>>([]), groups: new FormControl<Array<string>>([]),
flags: new FormControl<Array<number>>([]), flags: new FormControl<Array<string>>([]),
}) })
id?: string id?: string
regDate?: DateTime regDate?: DateTime
@@ -53,17 +53,6 @@ export class UserEditComponent {
this.id = data.id this.id = data.id
this.acu.getUser(data.id!).subscribe(r => { this.acu.getUser(data.id!).subscribe(r => {
this.regDate = DateTime.fromISO(r.regDate) this.regDate = DateTime.fromISO(r.regDate)
var flags: Array<number> = []
if (r.admin) {
if ((r.admin & 1) == 1) flags.push(1)
if ((r.admin & 2) == 2) flags.push(2)
if ((r.admin & 4) == 4) flags.push(4)
if ((r.admin & 8) == 8) flags.push(8)
if ((r.admin & 16) == 16) flags.push(16)
if ((r.admin & 32) == 32) flags.push(32)
if ((r.admin & 64) == 64) flags.push(64)
if ((r.admin & 128) == 128) flags.push(128)
}
this.locked = r.locked ? true : false this.locked = r.locked ? true : false
this.lockout = r.lockout this.lockout = r.lockout
this.form.get('fname')?.setValue(r.fname) this.form.get('fname')?.setValue(r.fname)
@@ -71,7 +60,7 @@ export class UserEditComponent {
this.form.get('room')?.setValue(r.room) this.form.get('room')?.setValue(r.room)
this.form.get('uname')?.setValue(r.uname) this.form.get('uname')?.setValue(r.uname)
this.form.get('groups')?.setValue(r.groups) this.form.get('groups')?.setValue(r.groups)
this.form.get('flags')?.setValue(flags) this.form.get('flags')?.setValue(r.admin)
}) })
} }
} }
@@ -150,9 +139,7 @@ export class UserEditComponent {
uname: this.form.get('uname')?.value, uname: this.form.get('uname')?.value,
groups: this.form.get('groups')?.value, groups: this.form.get('groups')?.value,
admin: (() => { admin: (() => {
var value = this.form var value = this.form.get('flags')?.value
.get('flags')
?.value.reduce((a: number, b: number) => a + b, 0)
if (this.ls.capCheck(32)) { if (this.ls.capCheck(32)) {
return value return value
} else { } else {

View File

@@ -15,43 +15,43 @@ export class AdminViewComponent {
title: 'Wiadomości', title: 'Wiadomości',
icon: 'newspaper', icon: 'newspaper',
href: 'news', href: 'news',
enabled: this.ls.permChecker(1) && this.ls.capCheck(1), enabled: this.ls.permChecker("news") && this.ls.capCheck(1),
}, },
{ {
title: 'Jadłospis', title: 'Jadłospis',
icon: 'restaurant_menu', icon: 'restaurant_menu',
href: 'menu', href: 'menu',
enabled: this.ls.permChecker(2) && this.ls.capCheck(2), enabled: this.ls.permChecker("menu") && this.ls.capCheck(2),
}, },
{ {
title: 'Wysyłanie powiadomień', title: 'Wysyłanie powiadomień',
icon: 'notifications', icon: 'notifications',
href: 'notifications', href: 'notifications',
enabled: this.ls.permChecker(4) && this.ls.capCheck(4), enabled: this.ls.permChecker("notif") && this.ls.capCheck(4),
}, },
{ {
title: 'Grupy', title: 'Grupy',
icon: 'groups', icon: 'groups',
href: 'groups', href: 'groups',
enabled: this.ls.permChecker(8) && this.ls.capCheck(8), enabled: this.ls.permChecker("groups") && this.ls.capCheck(8),
}, },
{ {
title: 'Zarządzanie kontami', title: 'Zarządzanie kontami',
icon: 'manage_accounts', icon: 'manage_accounts',
href: 'accounts', href: 'accounts',
enabled: this.ls.permChecker(16), enabled: this.ls.permChecker("accs"),
}, },
{ {
title: 'Klucze', title: 'Klucze',
icon: 'key', icon: 'key',
href: 'keys', href: 'keys',
enabled: this.ls.permChecker(64) && this.ls.capCheck(32), enabled: this.ls.permChecker("keys") && this.ls.capCheck(32),
}, },
{ {
title: 'Czystość', title: 'Czystość',
icon: 'cleaning_services', icon: 'cleaning_services',
href: 'grades', href: 'grades',
enabled: this.ls.permChecker(128) && this.ls.capCheck(16), enabled: this.ls.permChecker("grades") && this.ls.capCheck(16),
}, },
{ {
title: 'Frekwencja', title: 'Frekwencja',
@@ -63,7 +63,7 @@ export class AdminViewComponent {
title: 'Ustawienia', title: 'Ustawienia',
icon: 'settings_applications', icon: 'settings_applications',
href: 'settings', href: 'settings',
enabled: this.ls.permChecker(32), enabled: this.ls.permChecker("super"),
}, },
] ]
public get LINKS(): Link[] { public get LINKS(): Link[] {

View File

@@ -45,7 +45,7 @@ export class StartComponent {
title: 'Administracja', title: 'Administracja',
href: 'grades', href: 'grades',
icon: 'admin_panel_settings', icon: 'admin_panel_settings',
enabled: this.ls.admin != 0, enabled: this.ls.isAdmin,
}, },
] ]
public get LINKS(): Link[] { public get LINKS(): Link[] {

View File

@@ -27,7 +27,7 @@ export class AuthClient {
public login(uname: string, pass: string) { public login(uname: string, pass: string) {
return this.http return this.http
.post<Status & { admin: number; redirect: string }>( .post<Status & { admin: string[]; redirect: string }>(
environment.apiEndpoint + '/auth/login', environment.apiEndpoint + '/auth/login',
{ {
username: uname, username: uname,
@@ -51,7 +51,7 @@ export class AuthClient {
public check() { public check() {
this.http this.http
.get<{ .get<{
admin?: number admin?: string[]
room?: string room?: string
features: number features: number
menu: { menu: {

View File

@@ -7,11 +7,8 @@ import { News } from '../types/news'
export class LocalStorageService { export class LocalStorageService {
constructor() {} constructor() {}
permChecker(neededPermNumber: number) { permChecker(perm: string) {
return ( return this.admin?.includes(perm) ?? false
(Number.parseInt(localStorage.getItem('admin')!) & neededPermNumber) ==
neededPermNumber
)
} }
logOut() { logOut() {
@@ -62,9 +59,9 @@ export class LocalStorageService {
} }
} }
set admin(newInt: number | undefined) { set admin(perms: string[] | undefined) {
if (newInt) { if (perms) {
localStorage.setItem('admin', newInt.toString()) localStorage.setItem('admin', JSON.stringify(perms))
} else { } else {
localStorage.removeItem('admin') localStorage.removeItem('admin')
} }
@@ -72,22 +69,11 @@ export class LocalStorageService {
get admin() { get admin() {
var lsa = localStorage.getItem('admin') var lsa = localStorage.getItem('admin')
return lsa ? Number.parseInt(lsa) : undefined return lsa ? JSON.parse(lsa) : undefined
} }
set amgreg(toggle: boolean) { get isAdmin(): boolean {
if (toggle) { return this.admin ? true : false
localStorage.setItem('amgrb', 'true')
} else {
localStorage.removeItem('amgrb')
}
}
get amgreg() {
if (localStorage.getItem('amgrb') == 'true') {
return true
}
return false
} }
set capFlag(n: number | null) { set capFlag(n: number | null) {