Skip to content

Commit

Permalink
Add owner role support (#300)
Browse files Browse the repository at this point in the history
Update checks for admin to include owner role

Updated role list to include role for users

Updated activity with new event type handler
  • Loading branch information
mlsmaycon authored Dec 1, 2023
1 parent f4d6ce5 commit a208940
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const Navbar = () => {
return false;
}

if (user.role?.toLowerCase() === "admin") {
if (user.role?.toLowerCase() === "admin" || user.role?.toLowerCase() === "owner") {
return true;
}
return !adminOnlyTabs.find((t) => t === key);
Expand Down
33 changes: 23 additions & 10 deletions src/components/UserEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const UserEdit = (props: any) => {
const [formUser, setFormUser] = useState({} as FormUser);
const [form] = Form.useForm();
const [isAdmin, setIsAdmin] = useState(false);
const [isOwner, setIsOwner] = useState(false);

const [confirmModal, confirmModalContextHolder] = Modal.useModal();

Expand All @@ -94,15 +95,21 @@ const UserEdit = (props: any) => {
};

const createUserToSave = (values: any): UserToSave => {
const autoGroups =
groups
?.filter((g) => values.autoGroupsNames.includes(g.id))
.map((g) => g.id || "") || [];
let autoGroups:string[] = []
if (values.autoGroupsNames) {
autoGroups =
groups
?.filter((g) => values.autoGroupsNames.includes(g.id))
.map((g) => g.id || "") || [];
}
// find groups that do not yet exist (newly added by the user)
const allGroupsNames: string[] = groups?.map((g) => g.id || "");
const groupsToCreate = values.autoGroupsNames.filter(
(s: string) => !allGroupsNames.includes(s)
);
let groupsToCreate:string[] = []
if (values.autoGroupsNames) {
groupsToCreate = values.autoGroupsNames.filter(
(s: string) => !allGroupsNames.includes(s)
);
}
let userID = user ? user.id : "";
let isServiceUser = user ? user?.is_service_user : false;
return {
Expand All @@ -120,7 +127,8 @@ const UserEdit = (props: any) => {
if (users) {
let currentUser = users.find((user) => user?.is_current);
if (currentUser) {
setIsAdmin(currentUser.role === "admin");
setIsAdmin(currentUser.role === "admin" || currentUser.role === "owner");
setIsOwner(currentUser.role === "owner");
}
}
}, [users]);
Expand Down Expand Up @@ -403,14 +411,19 @@ const UserEdit = (props: any) => {
>
<Select
style={{ width: "100%" }}
disabled={user?.is_current}
disabled={user?.is_current || user?.role === "owner"}
>
<Option value="admin">
<Text type={"secondary"}>admin</Text>
</Option>
<Option value="user">
<Text type={"secondary"}>user</Text>
</Option>
{!user?.is_service_user && isOwner && (
<Option value="owner">
<Text type={"secondary"}>owner</Text>
</Option>
)}
</Select>
</Form.Item>
</Col>
Expand Down Expand Up @@ -473,7 +486,7 @@ const UserEdit = (props: any) => {
label="Block user"
style={{ marginRight: "50px", fontWeight: "500" }}
>
<Switch />
<Switch disabled={user?.role == "owner"} />
</Form.Item>
</Col>
)}
Expand Down
14 changes: 14 additions & 0 deletions src/views/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,20 @@ export const Activity = () => {
);
}
return "-";
case "transferred.owner.role":
if (event.meta.email || event.meta.username || event.target_id) {
return renderMultiRowSpan(
event.meta.username ? event.meta.username : event.target_id,
event.meta.email ? event.meta.email : "User"
);
}
if (event.meta.user_name) {
return renderMultiRowSpan(
event.meta.user_name,
event.meta.is_service_user ? "Service User" : "User"
);
}
return "-";
case "setupkey.group.add":
case "setupkey.group.delete":
return renderMultiRowSpan(event.meta.setupkey, "Setup Key");
Expand Down
2 changes: 1 addition & 1 deletion src/views/Peers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const Peers = () => {
if (users) {
let currentUser = users.find((user) => user.is_current);
if (currentUser) {
setIsAdmin(currentUser.role === "admin");
setIsAdmin(currentUser.role === "admin" || currentUser.role === "owner");
}
}
}, [users]);
Expand Down
20 changes: 14 additions & 6 deletions src/views/RegularUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const RegularUsers = () => {
if (users) {
let currentUser = users.find((user) => user.is_current);
if (currentUser) {
setIsAdmin(currentUser.role === "admin");
setIsAdmin(currentUser.role === "admin" || currentUser.role === "owner");
}
}
}, [users]);
Expand Down Expand Up @@ -758,16 +758,20 @@ export const RegularUsers = () => {
<Switch
size={"small"}
checked={e}
disabled={record.is_current}
disabled={record.is_current || record.role === "owner"}
onClick={(active: boolean) => {
handleBlockUser(active, record);
}}
/>
);

if (record.is_current) {
if (record.is_current || record.role === "owner") {
let title = "You can't block or unblock yourself"
if(record.role === "owner") {
title = "You can't block or unblock owners"
}
return (
<Tooltip title="You can't block or unblock yourself">
<Tooltip title={title}>
<Empty
image={""}
description={""}
Expand Down Expand Up @@ -803,9 +807,13 @@ export const RegularUsers = () => {
</Button>
);

if (record.is_current) {
if (record.is_current || record.role === "owner") {
let title = "You can't delete yourself"
if(record.role === "owner") {
title = "You can't delete owners"
}
return (
<Tooltip title="You can't delete yourself">
<Tooltip title={title}>
<Empty
image={""}
description={""}
Expand Down
2 changes: 1 addition & 1 deletion src/views/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const Users = () => {
if(users) {
let currentUser = users.find((user) => user.is_current)
if(currentUser) {
setIsAdmin(currentUser.role === 'admin');
setIsAdmin(currentUser.role === 'admin' || currentUser.role === 'owner');
}
}
}, [users])
Expand Down

0 comments on commit a208940

Please sign in to comment.