diff --git a/src/helpers/AdminRolesHelper.ts b/src/helpers/AdminRolesHelper.ts
index fa60d4e..3bfe914 100644
--- a/src/helpers/AdminRolesHelper.ts
+++ b/src/helpers/AdminRolesHelper.ts
@@ -23,4 +23,22 @@ export class AdminRolesHelper {
static async LoadRolesList() {
RolesList = await serverRequest("roles/list");
}
+
+ /**
+ * Toggle a role for an administrator
+ *
+ * @param adminID Target administrator ID
+ * @param role The role to toggle
+ */
+ static async ToggleAdminRole(
+ adminID: number,
+ role: AdminRole,
+ enable: boolean
+ ) {
+ await serverRequest("roles/toggle", {
+ adminID: adminID,
+ role: role.id,
+ enable: enable,
+ });
+ }
}
diff --git a/src/ui/accountSettings/RoleSettingsSection.tsx b/src/ui/accountSettings/RoleSettingsSection.tsx
index 566310a..3b03ec6 100644
--- a/src/ui/accountSettings/RoleSettingsSection.tsx
+++ b/src/ui/accountSettings/RoleSettingsSection.tsx
@@ -4,15 +4,74 @@
* @author Pierre Hubert
*/
+import { Checkbox, FormControlLabel, Tooltip } from "@material-ui/core";
import React from "react";
import { AdminAccount } from "../../helpers/AccountHelper";
+import {
+ AdminRole,
+ AdminRolesHelper,
+ RolesList,
+} from "../../helpers/AdminRolesHelper";
+import { matAlert, snackbar } from "../widgets/DialogsProvider";
import { SettingsSection } from "./SettingsSection";
export class RoleSettingsSection extends React.Component<{
admin: AdminAccount;
editable: boolean;
+ onChanged: () => void;
}> {
+ constructor(p: any) {
+ super(p);
+
+ this.toggleRole = this.toggleRole.bind(this);
+ }
+
+ async toggleRole(r: AdminRole, enable: boolean) {
+ try {
+ await AdminRolesHelper.ToggleAdminRole(
+ this.props.admin.id,
+ r,
+ enable
+ );
+ this.props.onChanged();
+ snackbar("Administrator roles were successfully updated!");
+ } catch (e) {
+ console.error(e);
+ matAlert("Failed to update admin roles!");
+ }
+ }
+
render() {
- return