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

Add owner role support #300

Merged
merged 3 commits into from
Dec 1, 2023
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
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 "-";
Comment on lines +365 to +378
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we duplicating this code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now when I checked closer I saw for PATs we also duplicate the same code

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