Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Allow subusers and subusers to delete or manage themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhpy committed Jul 26, 2024
1 parent 8ae76c3 commit 123ce52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/Http/Requests/Api/Client/Servers/Subusers/SubuserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@ public function authorize(): bool
return false;
}

// Always authorize requests from a root admin.
if ($this->user()->root_admin) {
return true;
}

$user = $this->route()->parameter('user');
// Don't allow a user to edit themselves on the server.
if ($user instanceof User) {
if ($user->uuid === $this->user()->uuid) {
// Except if they want to delete themselves from the server.
if ($this->method() === Request::METHOD_DELETE) {
return true;
}

return false;
}
}
Expand Down
13 changes: 10 additions & 3 deletions resources/scripts/components/server/users/UserRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Props {

export default ({ subuser }: Props) => {
const uuid = useStoreState((state) => state.user!.data!.uuid);
const rootAdmin = useStoreState((state) => state.user!.data!.rootAdmin);
const [visible, setVisible] = useState(false);

return (
Expand Down Expand Up @@ -44,7 +45,7 @@ export default ({ subuser }: Props) => {
</p>
<p css={tw`text-2xs text-neutral-500 uppercase`}>Permissions</p>
</div>
{subuser.uuid !== uuid && (
{(subuser.uuid !== uuid || rootAdmin) && (
<>
<Can action={'user.update'}>
<button
Expand All @@ -56,11 +57,17 @@ export default ({ subuser }: Props) => {
<FontAwesomeIcon icon={faPencilAlt} />
</button>
</Can>
</>
)}
<>
{subuser.uuid === uuid ? (
<RemoveSubuserButton subuser={subuser} />
) : (
<Can action={'user.delete'}>
<RemoveSubuserButton subuser={subuser} />
</Can>
</>
)}
)}
</>
</GreyRowBox>
);
};

0 comments on commit 123ce52

Please sign in to comment.