mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-07 12:00:01 +03:00
Fixed issue where role/user permissions could not be changed
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
<h4 *ngIf="role" mat-dialog-title><ng-container i18n="Manage role dialog title">Manage role</ng-container> - {{role.name}}</h4>
|
||||
<h4 *ngIf="role" mat-dialog-title><ng-container i18n="Manage role dialog title">Manage role</ng-container> - {{role.key}}</h4>
|
||||
|
||||
<mat-dialog-content *ngIf="role">
|
||||
<mat-list>
|
||||
<mat-list-item role="listitem" *ngFor="let permission of available_permissions">
|
||||
<div matListItemTitle>{{permissionToLabel[permission] ? permissionToLabel[permission] : permission}}</div>
|
||||
<div matListItemLine>
|
||||
<mat-radio-group [disabled]="permission === 'settings' && role.key === 'admin'" (change)="changeRolePermissions($event, permission, permissions[permission])" [(ngModel)]="permissions[permission]" [attr.aria-label]="'Give role permission for ' + permission">
|
||||
<mat-radio-button value="yes"><ng-container i18n="Yes">Yes</ng-container></mat-radio-button>
|
||||
<mat-radio-button value="no"><ng-container i18n="No">No</ng-container></mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
</mat-list-item>
|
||||
</mat-list>
|
||||
<div *ngFor="let permission of available_permissions">
|
||||
<div matListItemTitle>{{permissionToLabel[permission] ? permissionToLabel[permission] : permission}}</div>
|
||||
<div matListItemLine>
|
||||
<mat-radio-group [disabled]="permission === 'settings' && role.key === 'admin'" (change)="changeRolePermissions($event, permission, permissions[permission])" [(ngModel)]="permissions[permission]" [attr.aria-label]="'Give role permission for ' + permission">
|
||||
<mat-radio-button value="yes"><ng-container i18n="Yes">Yes</ng-container></mat-radio-button>
|
||||
<mat-radio-button value="no"><ng-container i18n="No">No</ng-container></mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions>
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
.mat-mdc-radio-button {
|
||||
margin-right: 10px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ export class ManageRoleComponent implements OnInit {
|
||||
}
|
||||
|
||||
constructor(public postsService: PostsService, private dialogRef: MatDialogRef<ManageRoleComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any) {
|
||||
@Inject(MAT_DIALOG_DATA) public data: {role: string}) {
|
||||
if (this.data) {
|
||||
this.role = this.data.role;
|
||||
this.available_permissions = this.postsService.available_permissions;
|
||||
|
||||
@@ -12,18 +12,16 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<mat-list>
|
||||
<mat-list-item role="listitem" *ngFor="let permission of available_permissions">
|
||||
<div matListItemTitle>{{permissionToLabel[permission] ? permissionToLabel[permission] : permission}}</div>
|
||||
<div matListItemLine>
|
||||
<mat-radio-group [disabled]="permission === 'settings' && postsService.user.uid === user.uid" (change)="changeUserPermissions($event, permission)" [(ngModel)]="permissions[permission]" [attr.aria-label]="'Give user permission for ' + permission">
|
||||
<mat-radio-button value="default"><ng-container i18n="Use role default">Use role default</ng-container></mat-radio-button>
|
||||
<mat-radio-button value="yes"><ng-container i18n="Yes">Yes</ng-container></mat-radio-button>
|
||||
<mat-radio-button value="no"><ng-container i18n="No">No</ng-container></mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
</mat-list-item>
|
||||
</mat-list>
|
||||
<div *ngFor="let permission of available_permissions">
|
||||
<div matListItemTitle>{{permissionToLabel[permission] ? permissionToLabel[permission] : permission}}</div>
|
||||
<div matListItemLine>
|
||||
<mat-radio-group [disabled]="permission === 'settings' && postsService.user.uid === user.uid" (change)="changeUserPermissions($event, permission)" [(ngModel)]="permissions[permission]" [attr.aria-label]="'Give user permission for ' + permission">
|
||||
<mat-radio-button value="default"><ng-container i18n="Use role default">Use role default</ng-container></mat-radio-button>
|
||||
<mat-radio-button value="yes"><ng-container i18n="Yes">Yes</ng-container></mat-radio-button>
|
||||
<mat-radio-button value="no"><ng-container i18n="No">No</ng-container></mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</mat-dialog-content>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Component, OnInit, Inject } from '@angular/core';
|
||||
import { PostsService } from 'app/posts.services';
|
||||
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { User } from 'api-types';
|
||||
|
||||
@Component({
|
||||
selector: 'app-manage-user',
|
||||
@@ -26,7 +27,7 @@ export class ManageUserComponent implements OnInit {
|
||||
|
||||
settingNewPassword = false;
|
||||
|
||||
constructor(public postsService: PostsService, @Inject(MAT_DIALOG_DATA) public data: any) {
|
||||
constructor(public postsService: PostsService, @Inject(MAT_DIALOG_DATA) public data: {user: User}) {
|
||||
if (this.data) {
|
||||
this.user = this.data.user;
|
||||
this.available_permissions = this.postsService.available_permissions;
|
||||
@@ -54,14 +55,14 @@ export class ManageUserComponent implements OnInit {
|
||||
}
|
||||
|
||||
changeUserPermissions(change, permission) {
|
||||
this.postsService.setUserPermission(this.user.uid, permission, change.value).subscribe(res => {
|
||||
this.postsService.setUserPermission(this.user.uid, permission, change.value).subscribe(() => {
|
||||
// console.log(res);
|
||||
});
|
||||
}
|
||||
|
||||
setNewPassword() {
|
||||
this.settingNewPassword = true;
|
||||
this.postsService.changeUserPassword(this.user.uid, this.newPasswordInput).subscribe(res => {
|
||||
this.postsService.changeUserPassword(this.user.uid, this.newPasswordInput).subscribe(() => {
|
||||
this.newPasswordInput = '';
|
||||
this.settingNewPassword = false;
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import { MatDialog, MatDialogRef } from '@angular/material/dialog';
|
||||
import { AddUserDialogComponent } from 'app/dialogs/add-user-dialog/add-user-dialog.component';
|
||||
import { ManageUserComponent } from '../manage-user/manage-user.component';
|
||||
import { ManageRoleComponent } from '../manage-role/manage-role.component';
|
||||
import { User } from 'api-types';
|
||||
|
||||
@Component({
|
||||
selector: 'app-modify-users',
|
||||
@@ -31,7 +32,7 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
|
||||
// MatPaginator Output
|
||||
pageEvent: PageEvent;
|
||||
users: any;
|
||||
users: User[];
|
||||
editObject = null;
|
||||
constructedObject = {};
|
||||
roles = null;
|
||||
@@ -94,11 +95,9 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
finishEditing(user_uid) {
|
||||
let has_finished = false;
|
||||
finishEditing(user_uid: string) {
|
||||
if (this.constructedObject && this.constructedObject['name'] && this.constructedObject['role']) {
|
||||
if (!isEmptyOrSpaces(this.constructedObject['name']) && !isEmptyOrSpaces(this.constructedObject['role'])) {
|
||||
has_finished = true;
|
||||
const index_of_object = this.indexOfUser(user_uid);
|
||||
this.users[index_of_object] = this.constructedObject;
|
||||
this.constructedObject = {};
|
||||
@@ -109,7 +108,7 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
}
|
||||
|
||||
enableEditMode(user_uid) {
|
||||
enableEditMode(user_uid: string) {
|
||||
if (this.uidInUserList(user_uid) && this.indexOfUser(user_uid) > -1) {
|
||||
const users_index = this.indexOfUser(user_uid);
|
||||
this.editObject = this.users[users_index];
|
||||
@@ -124,7 +123,7 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
// checks if user is in users array by name
|
||||
uidInUserList(user_uid) {
|
||||
uidInUserList(user_uid: string) {
|
||||
for (let i = 0; i < this.users.length; i++) {
|
||||
if (this.users[i].uid === user_uid) {
|
||||
return true;
|
||||
@@ -134,7 +133,7 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
// gets index of user in users array by name
|
||||
indexOfUser(user_uid) {
|
||||
indexOfUser(user_uid: string) {
|
||||
for (let i = 0; i < this.users.length; i++) {
|
||||
if (this.users[i].uid === user_uid) {
|
||||
return i;
|
||||
@@ -144,12 +143,12 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
setUser(change_obj) {
|
||||
this.postsService.changeUser(change_obj).subscribe(res => {
|
||||
this.postsService.changeUser(change_obj).subscribe(() => {
|
||||
this.getArray();
|
||||
});
|
||||
}
|
||||
|
||||
manageUser(user_uid) {
|
||||
manageUser(user_uid: string) {
|
||||
const index_of_object = this.indexOfUser(user_uid);
|
||||
const user_obj = this.users[index_of_object];
|
||||
this.dialog.open(ManageUserComponent, {
|
||||
@@ -160,17 +159,17 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
removeUser(user_uid) {
|
||||
this.postsService.deleteUser(user_uid).subscribe(res => {
|
||||
removeUser(user_uid: string) {
|
||||
this.postsService.deleteUser(user_uid).subscribe(() => {
|
||||
this.getArray();
|
||||
}, err => {
|
||||
}, () => {
|
||||
this.getArray();
|
||||
});
|
||||
}
|
||||
|
||||
createAndSortData() {
|
||||
// Sorts the data by last finished
|
||||
this.users.sort((a, b) => b.name > a.name);
|
||||
this.users.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
const filteredData = [];
|
||||
for (let i = 0; i < this.users.length; i++) {
|
||||
@@ -188,7 +187,7 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(success => {
|
||||
dialogRef.afterClosed().subscribe(() => {
|
||||
this.getRoles();
|
||||
});
|
||||
}
|
||||
@@ -197,7 +196,7 @@ export class ModifyUsersComponent implements OnInit, AfterViewInit {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
||||
public openSnackBar(message: string, action: string = '') {
|
||||
public openSnackBar(message: string, action = '') {
|
||||
this.snackBar.open(message, action, {
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user