Skip to content

Commit 36131d9

Browse files
committed
Collection upload/deprecate - fix permission checks
Issue: AAH-2439 Issue: AAH-2853
1 parent 0d292bf commit 36131d9

File tree

5 files changed

+69
-67
lines changed

5 files changed

+69
-67
lines changed

CHANGES/2439.bug

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Collection upload/deprecate - fix permission checks

CHANGES/2853.bug

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Collection upload/deprecate - fix permission checks

src/components/headers/collection-header.tsx

+29-31
Original file line numberDiff line numberDiff line change
@@ -238,36 +238,34 @@ export class CollectionHeader extends React.Component<IProps, IState> {
238238
return <Navigate to={redirect} />;
239239
}
240240

241-
const canSign = canSignNamespace(this.context, this.state.namespace);
242241
const { hasPermission } = this.context;
243242
const hasObjectPermission = (permission, namespace) =>
244243
namespace?.related_fields?.my_permissions?.includes?.(permission);
245244

246-
const canDeleteCommunityCollection =
247-
IS_COMMUNITY &&
248-
hasObjectPermission('galaxy.change_namespace', this.state.namespace);
245+
const canDeleteCollection =
246+
hasPermission('ansible.delete_collection') ||
247+
(IS_COMMUNITY &&
248+
hasObjectPermission('galaxy.change_namespace', this.state.namespace));
249+
const canSign = canSignNamespace(this.context, this.state.namespace);
250+
const canUpload = hasPermission('galaxy.upload_to_namespace');
251+
const canDeprecate = canUpload;
249252

250253
const dropdownItems = [
251254
DeleteCollectionUtils.deleteMenuOption({
252-
canDeleteCollection:
253-
hasPermission('ansible.delete_collection') ||
254-
canDeleteCommunityCollection,
255+
canDeleteCollection,
255256
noDependencies,
256257
onClick: () => this.openDeleteModalWithConfirm(null, true),
257258
deleteAll: true,
258259
display_repositories: display_repositories,
259260
}),
260261
DeleteCollectionUtils.deleteMenuOption({
261-
canDeleteCollection:
262-
hasPermission('ansible.delete_collection') ||
263-
canDeleteCommunityCollection,
262+
canDeleteCollection,
264263
noDependencies,
265264
onClick: () => this.openDeleteModalWithConfirm(null, false),
266265
deleteAll: false,
267266
display_repositories: display_repositories,
268267
}),
269-
(hasPermission('ansible.delete_collection') ||
270-
canDeleteCommunityCollection) && (
268+
canDeleteCollection && (
271269
<DropdownItem
272270
data-cy='delete-collection-version'
273271
key='delete-collection-version'
@@ -276,17 +274,15 @@ export class CollectionHeader extends React.Component<IProps, IState> {
276274
{t`Delete version ${version} from system`}
277275
</DropdownItem>
278276
),
279-
(hasPermission('ansible.delete_collection') ||
280-
canDeleteCommunityCollection) &&
281-
display_repositories && (
282-
<DropdownItem
283-
data-cy='remove-collection-version'
284-
key='remove-collection-version'
285-
onClick={() => this.openDeleteModalWithConfirm(version, false)}
286-
>
287-
{t`Delete version ${version} from repository`}
288-
</DropdownItem>
289-
),
277+
canDeleteCollection && display_repositories && (
278+
<DropdownItem
279+
data-cy='remove-collection-version'
280+
key='remove-collection-version'
281+
onClick={() => this.openDeleteModalWithConfirm(version, false)}
282+
>
283+
{t`Delete version ${version} from repository`}
284+
</DropdownItem>
285+
),
290286
canSign && !can_upload_signatures && (
291287
<DropdownItem
292288
key='sign-all'
@@ -314,21 +310,23 @@ export class CollectionHeader extends React.Component<IProps, IState> {
314310
{t`Sign version ${version}`}
315311
</DropdownItem>
316312
),
317-
hasPermission('galaxy.upload_to_namespace') && (
313+
canDeprecate && (
318314
<DropdownItem
319315
onClick={() => this.deprecate(collection)}
320316
key='deprecate'
321317
>
322318
{collection.is_deprecated ? t`Undeprecate` : t`Deprecate`}
323319
</DropdownItem>
324320
),
325-
<DropdownItem
326-
key='upload-collection-version'
327-
onClick={() => this.checkUploadPrivilleges(collection)}
328-
data-cy='upload-collection-version-dropdown'
329-
>
330-
{t`Upload new version`}
331-
</DropdownItem>,
321+
canUpload && (
322+
<DropdownItem
323+
key='upload-collection-version'
324+
onClick={() => this.checkUploadPrivilleges(collection)}
325+
data-cy='upload-collection-version-dropdown'
326+
>
327+
{t`Upload new version`}
328+
</DropdownItem>
329+
),
332330
display_repositories && (
333331
<DropdownItem
334332
key='copy-collection-version-to-repository-dropdown'

src/containers/namespace-detail/namespace-detail.tsx

+23-21
Original file line numberDiff line numberDiff line change
@@ -1014,16 +1014,20 @@ export class NamespaceDetail extends React.Component<RouteProps, IState> {
10141014
namespace?.related_fields?.my_permissions?.includes?.(permission);
10151015
const { showControls } = this.state;
10161016
const { display_repositories } = this.context.featureFlags;
1017-
const canDeleteCommunityCollection =
1018-
IS_COMMUNITY &&
1019-
hasObjectPermission('galaxy.change_namespace', this.state.namespace);
1017+
1018+
const canDeleteCollection =
1019+
hasPermission('ansible.delete_collection') ||
1020+
(IS_COMMUNITY &&
1021+
hasObjectPermission('galaxy.change_namespace', this.state.namespace));
1022+
const canUpload = hasPermission('galaxy.upload_to_namespace');
1023+
const canDeprecate = canUpload;
10201024

10211025
if (!showControls) {
10221026
return;
10231027
}
10241028

10251029
return {
1026-
uploadButton: (
1030+
uploadButton: canUpload && (
10271031
<Button
10281032
onClick={() =>
10291033
this.handleCollectionAction(
@@ -1040,9 +1044,7 @@ export class NamespaceDetail extends React.Component<RouteProps, IState> {
10401044
<StatefulDropdown
10411045
items={[
10421046
DeleteCollectionUtils.deleteMenuOption({
1043-
canDeleteCollection:
1044-
hasPermission('ansible.delete_collection') ||
1045-
canDeleteCommunityCollection,
1047+
canDeleteCollection,
10461048
noDependencies: null,
10471049
onClick: () =>
10481050
DeleteCollectionUtils.tryOpenDeleteModalWithConfirm({
@@ -1055,9 +1057,7 @@ export class NamespaceDetail extends React.Component<RouteProps, IState> {
10551057
display_repositories: display_repositories,
10561058
}),
10571059
DeleteCollectionUtils.deleteMenuOption({
1058-
canDeleteCollection:
1059-
hasPermission('ansible.delete_collection') ||
1060-
canDeleteCommunityCollection,
1060+
canDeleteCollection,
10611061
noDependencies: null,
10621062
onClick: () =>
10631063
DeleteCollectionUtils.tryOpenDeleteModalWithConfirm({
@@ -1069,17 +1069,19 @@ export class NamespaceDetail extends React.Component<RouteProps, IState> {
10691069
deleteAll: false,
10701070
display_repositories: display_repositories,
10711071
}),
1072-
<DropdownItem
1073-
onClick={() =>
1074-
this.handleCollectionAction(
1075-
collection.collection_version.pulp_href,
1076-
'deprecate',
1077-
)
1078-
}
1079-
key='deprecate'
1080-
>
1081-
{collection.is_deprecated ? t`Undeprecate` : t`Deprecate`}
1082-
</DropdownItem>,
1072+
canDeprecate && (
1073+
<DropdownItem
1074+
onClick={() =>
1075+
this.handleCollectionAction(
1076+
collection.collection_version.pulp_href,
1077+
'deprecate',
1078+
)
1079+
}
1080+
key='deprecate'
1081+
>
1082+
{collection.is_deprecated ? t`Undeprecate` : t`Deprecate`}
1083+
</DropdownItem>
1084+
),
10831085
].filter(Boolean)}
10841086
ariaLabel='collection-kebab'
10851087
/>

src/containers/search/search.tsx

+15-15
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,20 @@ class Search extends React.Component<RouteProps, IState> {
390390
const hasObjectPermission = (permission, namespace) =>
391391
namespace?.related_fields?.my_permissions?.includes?.(permission);
392392
const { display_repositories } = this.context.featureFlags;
393-
const canDeleteCommunityCollection =
394-
IS_COMMUNITY &&
395-
hasObjectPermission(
396-
'galaxy.change_namespace',
397-
collection.collection_version.namespace,
398-
);
393+
394+
const canDeleteCollection =
395+
hasPermission('ansible.delete_collection') ||
396+
(IS_COMMUNITY &&
397+
hasObjectPermission(
398+
'galaxy.change_namespace',
399+
collection.collection_version.namespace,
400+
));
401+
const canUpload = hasPermission('galaxy.upload_to_namespace');
402+
const canDeprecate = canUpload;
399403

400404
const menuItems = [
401405
DeleteCollectionUtils.deleteMenuOption({
402-
canDeleteCollection:
403-
hasPermission('ansible.delete_collection') ||
404-
canDeleteCommunityCollection,
406+
canDeleteCollection,
405407
noDependencies: null,
406408
onClick: () =>
407409
DeleteCollectionUtils.tryOpenDeleteModalWithConfirm({
@@ -414,9 +416,7 @@ class Search extends React.Component<RouteProps, IState> {
414416
display_repositories: display_repositories,
415417
}),
416418
DeleteCollectionUtils.deleteMenuOption({
417-
canDeleteCollection:
418-
hasPermission('ansible.delete_collection') ||
419-
canDeleteCommunityCollection,
419+
canDeleteCollection,
420420
noDependencies: null,
421421
onClick: () =>
422422
DeleteCollectionUtils.tryOpenDeleteModalWithConfirm({
@@ -428,15 +428,15 @@ class Search extends React.Component<RouteProps, IState> {
428428
deleteAll: false,
429429
display_repositories: display_repositories,
430430
}),
431-
hasPermission('galaxy.upload_to_namespace') && (
431+
canDeprecate && (
432432
<DropdownItem
433433
onClick={() => this.handleControlClick(collection)}
434434
key='deprecate'
435435
>
436436
{collection.is_deprecated ? t`Undeprecate` : t`Deprecate`}
437437
</DropdownItem>
438438
),
439-
!list && hasPermission('galaxy.upload_to_namespace') && (
439+
!list && canUpload && (
440440
<DropdownItem
441441
onClick={() => this.checkUploadPrivilleges(collection)}
442442
key='upload new version'
@@ -450,7 +450,7 @@ class Search extends React.Component<RouteProps, IState> {
450450

451451
if (list) {
452452
return {
453-
uploadButton: hasPermission('galaxy.upload_to_namespace') ? (
453+
uploadButton: canUpload ? (
454454
<Button
455455
onClick={() => this.checkUploadPrivilleges(collection)}
456456
variant='secondary'

0 commit comments

Comments
 (0)