update role
This commit is contained in:
@@ -77,12 +77,29 @@ class AccountManager {
|
||||
return detected ?? 1;
|
||||
}
|
||||
|
||||
getCurrentUserRoleRaw() {
|
||||
return this.currentUser?.Role
|
||||
?? this.currentUser?.role
|
||||
?? this.currentUser?.RoleName
|
||||
?? this.currentUser?.user?.Role
|
||||
?? this.currentUser?.user?.role
|
||||
?? '';
|
||||
}
|
||||
|
||||
getCurrentUserRole() {
|
||||
return String(this.getCurrentUserRoleRaw() || '').trim().toLowerCase();
|
||||
}
|
||||
|
||||
isCurrentUserAdmin() {
|
||||
return this.getCurrentUserRole() === 'admin';
|
||||
}
|
||||
|
||||
async init() {
|
||||
await this.fetchApplications();
|
||||
await this.fetchAccounts();
|
||||
|
||||
// Check if user is admin and fetch users/roles
|
||||
if (this.currentUser?.Role === 'admin') {
|
||||
if (this.isCurrentUserAdmin()) {
|
||||
await this.fetchUsers();
|
||||
await this.fetchRoles();
|
||||
// Show Users menu
|
||||
@@ -121,7 +138,7 @@ class AccountManager {
|
||||
this.setupAccountPagerListeners();
|
||||
} else if (page === 'users') {
|
||||
// Check if user is admin
|
||||
if (this.currentUser?.Role !== 'admin') {
|
||||
if (!this.isCurrentUserAdmin()) {
|
||||
mainContent.innerHTML = this.renderDashboard();
|
||||
} else {
|
||||
mainContent.innerHTML = this.getUsersContent();
|
||||
@@ -306,7 +323,7 @@ class AccountManager {
|
||||
const roleEl = document.getElementById('accountRole');
|
||||
|
||||
if (usernameEl) usernameEl.textContent = this.currentUser?.username || this.currentUser?.Username || 'User';
|
||||
if (roleEl) roleEl.textContent = this.currentUser?.role || this.currentUser?.Role || 'Guest';
|
||||
if (roleEl) roleEl.textContent = this.getCurrentUserRoleRaw() || 'Guest';
|
||||
}
|
||||
|
||||
getFilteredAccounts() {
|
||||
@@ -1601,7 +1618,7 @@ class AccountManager {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json', 'x-user-role': this.currentUser?.Role },
|
||||
headers: { 'Content-Type': 'application/json', 'x-user-role': this.getCurrentUserRole() },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
@@ -1626,7 +1643,7 @@ class AccountManager {
|
||||
async viewUserDetails(userId) {
|
||||
try {
|
||||
const response = await fetch(`${this.apiBase}/users/${userId}`, {
|
||||
headers: { 'x-user-role': this.currentUser?.Role }
|
||||
headers: { 'x-user-role': this.getCurrentUserRole() }
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
@@ -1787,7 +1804,7 @@ class AccountManager {
|
||||
try {
|
||||
const response = await fetch(`${this.apiBase}/users/${userId}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'x-user-role': this.currentUser?.Role }
|
||||
headers: { 'x-user-role': this.getCurrentUserRole() }
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
Reference in New Issue
Block a user