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
uname: string
room?: string
admin?: number
admin?: string[]
locked?: boolean
fname?: string
surname?: string

View File

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

View File

@@ -36,7 +36,7 @@ export class UserEditComponent {
room: new FormControl<string>(''),
uname: new FormControl<string>(''),
groups: new FormControl<Array<string>>([]),
flags: new FormControl<Array<number>>([]),
flags: new FormControl<Array<string>>([]),
})
id?: string
regDate?: DateTime
@@ -53,17 +53,6 @@ export class UserEditComponent {
this.id = data.id
this.acu.getUser(data.id!).subscribe(r => {
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.lockout = r.lockout
this.form.get('fname')?.setValue(r.fname)
@@ -71,7 +60,7 @@ export class UserEditComponent {
this.form.get('room')?.setValue(r.room)
this.form.get('uname')?.setValue(r.uname)
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,
groups: this.form.get('groups')?.value,
admin: (() => {
var value = this.form
.get('flags')
?.value.reduce((a: number, b: number) => a + b, 0)
var value = this.form.get('flags')?.value
if (this.ls.capCheck(32)) {
return value
} else {

View File

@@ -15,43 +15,43 @@ export class AdminViewComponent {
title: 'Wiadomości',
icon: 'newspaper',
href: 'news',
enabled: this.ls.permChecker(1) && this.ls.capCheck(1),
enabled: this.ls.permChecker("news") && this.ls.capCheck(1),
},
{
title: 'Jadłospis',
icon: 'restaurant_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ń',
icon: 'notifications',
href: 'notifications',
enabled: this.ls.permChecker(4) && this.ls.capCheck(4),
enabled: this.ls.permChecker("notif") && this.ls.capCheck(4),
},
{
title: 'Grupy',
icon: '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',
icon: 'manage_accounts',
href: 'accounts',
enabled: this.ls.permChecker(16),
enabled: this.ls.permChecker("accs"),
},
{
title: 'Klucze',
icon: 'key',
href: 'keys',
enabled: this.ls.permChecker(64) && this.ls.capCheck(32),
enabled: this.ls.permChecker("keys") && this.ls.capCheck(32),
},
{
title: 'Czystość',
icon: 'cleaning_services',
href: 'grades',
enabled: this.ls.permChecker(128) && this.ls.capCheck(16),
enabled: this.ls.permChecker("grades") && this.ls.capCheck(16),
},
{
title: 'Frekwencja',
@@ -63,7 +63,7 @@ export class AdminViewComponent {
title: 'Ustawienia',
icon: 'settings_applications',
href: 'settings',
enabled: this.ls.permChecker(32),
enabled: this.ls.permChecker("super"),
},
]
public get LINKS(): Link[] {

View File

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

View File

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

View File

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