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