Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect admin user correctly in project permissions dialog #384

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ E.g., if it was used in a menu and the menu is red, the circle would be red.
### **WORK IN PROGRESS**
-->
## Changelog
### **WORK IN PROGRESS**
* (foxriver76) detect admin user correctly in project permissions dialog

### 2.9.33 (2024-02-21)
* (foxriver76) fixed issue that last image is never shown in image8 widget
* (foxriver76) added possibility to define background and title color for jqui dialog
Expand Down
19 changes: 11 additions & 8 deletions src/src/Toolbar/ProjectsManager/PermissionsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface RenderWidgetPermissionsOptions extends RenderViewPermissionsOptions {

export default class PermissionsDialog extends React.Component<PermissionsDialogProps, PermissionsDialogState> {
/** Admin user cannot be disabled */
private readonly ADMIN_USER = 'admin';
private adminUser = 'admin';

constructor(props: PermissionsDialogProps) {
super(props);
Expand All @@ -91,6 +91,9 @@ export default class PermissionsDialog extends React.Component<PermissionsDialog
const viewPermissions: Record<string, PermissionsMap> = {};
const widgetPermissions: Record<string, PermissionsMap> = {};

const adminObj = Object.values(userView).find(obj => obj._id === 'system.user.admin');
this.adminUser = adminObj?.common.name || this.adminUser;

for (const user of Object.keys(userView)) {
projectPermissions.set(user, visProject.___settings.permissions?.[user] ?? DEFAULT_PERMISSIONS);

Expand Down Expand Up @@ -131,7 +134,7 @@ export default class PermissionsDialog extends React.Component<PermissionsDialog
}

for (const [user, permissions] of this.state.projectPermissions) {
if (user === this.ADMIN_USER) {
if (user === this.adminUser) {
continue;
}

Expand Down Expand Up @@ -208,7 +211,7 @@ export default class PermissionsDialog extends React.Component<PermissionsDialog
}}
>
<Checkbox
disabled={user === this.ADMIN_USER || activeUser !== this.ADMIN_USER || !this.state.projectPermissions.get(user)?.read || !this.state.viewPermissions[view].get(user)?.read}
disabled={user === this.adminUser || activeUser !== this.adminUser || !this.state.projectPermissions.get(user)?.read || !this.state.viewPermissions[view].get(user)?.read}
checked={this.state.widgetPermissions[wid]?.get(user)?.read}
onClick={() => {
const newState = this.state;
Expand All @@ -223,7 +226,7 @@ export default class PermissionsDialog extends React.Component<PermissionsDialog
/>
{I18n.t('Read')}
<Checkbox
disabled={user === this.ADMIN_USER || activeUser !== this.ADMIN_USER || !this.state.projectPermissions.get(user)?.write || !this.state.viewPermissions[view].get(user)?.write}
disabled={user === this.adminUser || activeUser !== this.adminUser || !this.state.projectPermissions.get(user)?.write || !this.state.viewPermissions[view].get(user)?.write}
checked={this.state.widgetPermissions[wid]?.get(user)?.write}
onClick={() => {
const newState = this.state;
Expand Down Expand Up @@ -271,7 +274,7 @@ export default class PermissionsDialog extends React.Component<PermissionsDialog
}}
>
<Checkbox
disabled={user === this.ADMIN_USER || activeUser !== this.ADMIN_USER || !this.state.projectPermissions.get(user)?.read}
disabled={user === this.adminUser || activeUser !== this.adminUser || !this.state.projectPermissions.get(user)?.read}
checked={this.state.viewPermissions[view]?.get(user)?.read}
onClick={() => {
const newState = this.state;
Expand All @@ -286,7 +289,7 @@ export default class PermissionsDialog extends React.Component<PermissionsDialog
/>
{I18n.t('Read')}
<Checkbox
disabled={user === this.ADMIN_USER || activeUser !== this.ADMIN_USER || !this.state.projectPermissions.get(user)?.write}
disabled={user === this.adminUser || activeUser !== this.adminUser || !this.state.projectPermissions.get(user)?.write}
checked={this.state.viewPermissions[view]?.get(user)?.write}
onClick={() => {
const newState = this.state;
Expand Down Expand Up @@ -359,7 +362,7 @@ export default class PermissionsDialog extends React.Component<PermissionsDialog
>
<div>
<Checkbox
disabled={user === this.ADMIN_USER || activeUser !== this.ADMIN_USER}
disabled={user === this.adminUser || activeUser !== this.adminUser}
checked={this.state.projectPermissions.get(user)?.read}
onClick={() => {
const newState = this.state;
Expand All @@ -374,7 +377,7 @@ export default class PermissionsDialog extends React.Component<PermissionsDialog
/>
{I18n.t('Read')}
<Checkbox
disabled={user === this.ADMIN_USER || activeUser !== this.ADMIN_USER}
disabled={user === this.adminUser || activeUser !== this.adminUser}
checked={this.state.projectPermissions.get(user)?.write}
onClick={() => {
const newState = this.state;
Expand Down
Loading