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

Enable 'set collections' button when user is set as admin #3755

Merged
merged 8 commits into from
Sep 26, 2023
47 changes: 44 additions & 3 deletions specifyweb/context/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,46 @@ class Sp6CollectionAccessPT(PermissionTarget):
read = PermissionTargetAction()
update = PermissionTargetAction()

@openapi(schema={
"get": {
"responses" : {
"200" : {
"description": "Gets the list of collections a user has permissions for in Specify 6",
"content" : {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "integer",
"description": "The Collection IDs for which to a user has Specify 6 permission's for"
}
}
}
}
}
}
},
"put": {
"requestBody": {
"required": True,
"description": "Sets the Specify 6 permissions of a user for a list of collections",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "integer",
"description": "The Collection IDs for which to set a user's permussions in Specify 6 for"
}
}
}
}
},
"responses": {
"200": {"description": "Specify 6 permissions for user set."}
}
}
})
@login_maybe_required
@require_http_methods(['GET', 'PUT'])
@never_cache
Expand All @@ -119,7 +159,8 @@ def user_collection_access_for_sp6(request, userid):
check_permission_targets(None, request.specify_user.id, [Sp6CollectionAccessPT.update])
collections = json.loads(request.body)
user = Specifyuser.objects.get(id=userid)
set_users_collections_for_sp6(cursor, user, collections)
if len(collections) > 0:
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
set_users_collections_for_sp6(cursor, user, collections)

collections = users_collections_for_sp6(cursor, userid)
return HttpResponse(json.dumps([row[0] for row in collections]),
Expand Down Expand Up @@ -318,7 +359,7 @@ def domain(request):
"description": "Flag to indicate that if the AppResource does not exist, return response with code 204 instead of 404"
}
],
"get" : {
"get": {
"responses": {
"404": {
"description": "'name' parameter was not provided, or App Resource was not found"
Expand Down Expand Up @@ -418,7 +459,7 @@ def schema_localization(request):
"description": "Flag to indicate that if the view does not exist, return response with code 204 instead of 404"
}
],
"get" : {
"get": {
"responses": {
"404": {
"description": "'name' parameter was not provided, or view was not found"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ function UserCollectionsUi({

export function UserCollections({
user,
isAdmin,
grantfitzsimmons marked this conversation as resolved.
Show resolved Hide resolved
}: {
readonly user: SpecifyResource<SpecifyUser>;
readonly isAdmin: boolean;
}): JSX.Element {
const [isOpen, handleOpen, handleClose] = useBooleanState();
return (
Expand All @@ -122,12 +120,10 @@ export function UserCollections({
className="w-fit"
disabled={
// Admin users have access to all collections
user === undefined || isAdmin || user.isNew()
user === undefined || user.isNew()
}
title={
isAdmin
? userText.notAvailableOnAdmins()
: user === undefined
user === undefined
? commonText.loading()
: user.isNew()
? userText.saveUserFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function LegacyPermissions({
/>
{hasPermission('/admin/user/sp6/collection_access', 'read') &&
hasTablePermission('Collection', 'read') ? (
<UserCollections isAdmin={isAdmin} user={userResource} />
<UserCollections user={userResource} />
) : undefined}
</div>
)}
Expand Down