mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Add role 'owner' to users (#185)
This commit is contained in:
committed by
GitHub
parent
e86748edca
commit
0e96ff7ad4
@@ -2,7 +2,7 @@ import * as React from "react";
|
||||
import Gravatar from 'react-gravatar';
|
||||
import I18n from 'i18n-js';
|
||||
|
||||
import IUser, { UserRoles, USER_ROLE_ADMIN, USER_ROLE_USER, USER_STATUS_ACTIVE, USER_STATUS_BLOCKED, USER_STATUS_DELETED } from "../../../interfaces/IUser";
|
||||
import IUser, { UserRoles, USER_ROLE_ADMIN, USER_ROLE_MODERATOR, USER_ROLE_OWNER, USER_ROLE_USER, USER_STATUS_ACTIVE, USER_STATUS_BLOCKED, USER_STATUS_DELETED } from "../../../interfaces/IUser";
|
||||
import Separator from "../../common/Separator";
|
||||
import UserForm from "./UserForm";
|
||||
import { MutedText } from "../../common/CustomTexts";
|
||||
@@ -79,15 +79,14 @@ class UserEditable extends React.Component<Props, State> {
|
||||
const { user, currentUserRole, currentUserEmail } = this.props;
|
||||
const { editMode } = this.state;
|
||||
|
||||
const editEnabled =
|
||||
user.status === USER_STATUS_ACTIVE &&
|
||||
currentUserRole === USER_ROLE_ADMIN &&
|
||||
const hasPrivilege = user.role !== USER_ROLE_OWNER &&
|
||||
(currentUserRole === USER_ROLE_OWNER ||
|
||||
(currentUserRole === USER_ROLE_ADMIN && (user.role === USER_ROLE_MODERATOR || user.role === USER_ROLE_USER)) ||
|
||||
(currentUserRole === USER_ROLE_MODERATOR && user.role === USER_ROLE_USER)) &&
|
||||
currentUserEmail !== user.email;
|
||||
|
||||
const blockEnabled =
|
||||
user.status !== USER_STATUS_DELETED &&
|
||||
(currentUserRole === USER_ROLE_ADMIN || user.role === USER_ROLE_USER) &&
|
||||
currentUserEmail !== user.email;
|
||||
const editEnabled = hasPrivilege && user.status === USER_STATUS_ACTIVE;
|
||||
const blockEnabled = hasPrivilege && user.status !== USER_STATUS_DELETED;
|
||||
|
||||
return (
|
||||
<li className="userEditable">
|
||||
|
||||
@@ -23,12 +23,15 @@ class UserForm extends React.Component<Props, State> {
|
||||
this._handleUpdateUserRole = this._handleUpdateUserRole.bind(this);
|
||||
}
|
||||
|
||||
_handleUpdateUserRole(selectedRole: UserRoles) {
|
||||
_handleUpdateUserRole(selectedRole: UserRoles, currentRole: UserRoles) {
|
||||
const { user, updateUserRole } = this.props;
|
||||
let confirmation = true;
|
||||
|
||||
if (selectedRole === 'admin') {
|
||||
confirmation = confirm(I18n.t('site_settings.users.role_to_admin_confirmation', { name: user.fullName }));
|
||||
if (selectedRole !== currentRole) {
|
||||
if (selectedRole === 'moderator')
|
||||
confirmation = confirm(I18n.t('site_settings.users.role_to_moderator_confirmation', { name: user.fullName }));
|
||||
else if (selectedRole === 'admin')
|
||||
confirmation = confirm(I18n.t('site_settings.users.role_to_admin_confirmation', { name: user.fullName }));
|
||||
}
|
||||
|
||||
if (confirmation) updateUserRole(selectedRole);
|
||||
@@ -68,7 +71,7 @@ class UserForm extends React.Component<Props, State> {
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<Button onClick={() => this._handleUpdateUserRole(selectedRole)} className="updateUserButton">
|
||||
<Button onClick={() => this._handleUpdateUserRole(selectedRole, user.role)} className="updateUserButton">
|
||||
{ I18n.t('common.buttons.update') }
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user