Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,6 @@ public static boolean isAuthorizedToUpdateFieldDescription(
context, targetUrn.getEntityType(), targetUrn.toString(), orPrivilegeGroups);
}

public static boolean isAuthorizedToUpdateDomainDescription(
@Nonnull QueryContext context, Urn targetUrn) {
final DisjunctivePrivilegeGroup orPrivilegeGroups =
new DisjunctivePrivilegeGroup(
ImmutableList.of(
ALL_PRIVILEGES_GROUP,
new ConjunctivePrivilegeGroup(
ImmutableList.of(PoliciesConfig.EDIT_ENTITY_DOCS_PRIVILEGE.getType()))));

return AuthorizationUtils.isAuthorized(
context, targetUrn.getEntityType(), targetUrn.toString(), orPrivilegeGroups);
}

public static boolean isAuthorizedToUpdateContainerDescription(
@Nonnull QueryContext context, Urn targetUrn) {
final DisjunctivePrivilegeGroup orPrivilegeGroups =
Expand All @@ -373,7 +360,9 @@ public static boolean isAuthorizedToUpdateDescription(
ImmutableList.of(
ALL_PRIVILEGES_GROUP,
new ConjunctivePrivilegeGroup(
ImmutableList.of(PoliciesConfig.EDIT_ENTITY_DOCS_PRIVILEGE.getType()))));
ImmutableList.of(PoliciesConfig.EDIT_ENTITY_DOCS_PRIVILEGE.getType())),
new ConjunctivePrivilegeGroup(
ImmutableList.of(PoliciesConfig.MANAGE_ASSET_SUMMARY_PRIVILEGE.getType()))));

return AuthorizationUtils.isAuthorized(
context, targetUrn.getEntityType(), targetUrn.toString(), orPrivilegeGroups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private CompletableFuture<Boolean> updateDomainDescription(
Urn targetUrn, DescriptionUpdateInput input, QueryContext context) {
return GraphQLConcurrencyUtils.supplyAsync(
() -> {
if (!DescriptionUtils.isAuthorizedToUpdateDomainDescription(context, targetUrn)) {
if (!DescriptionUtils.isAuthorizedToUpdateDescription(context, targetUrn)) {
throw new AuthorizationException(
"Unauthorized to perform this action. Please contact your DataHub administrator.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vi.mock('@app/entityV2/summary/shared/useCanUpdateGlossaryEntity', () => ({
useCanUpdateGlossaryEntity: vi.fn(),
}));

describe('useDocumentationPermissions', () => {
describe('useDocumentationPermission', () => {
const setup = (entityDataProps, canUpdateGlossaryEntityMock) => {
(useEntityData as unknown as any).mockReturnValue({
entityData: entityDataProps,
Expand All @@ -27,23 +27,38 @@ describe('useDocumentationPermissions', () => {
vi.resetAllMocks();
});

it('should return true when canEditDescription is true and canUpdateGlossaryEntity is false', () => {
it('should return true when canEditDescription is true', () => {
const { result } = setup({ privileges: { canEditDescription: true } }, false);
expect(result.current).toBe(true);
});

it('should return true when canEditDescription is false and canUpdateGlossaryEntity is true', () => {
const { result } = setup({ privileges: { canEditDescription: false } }, true);
it('should return true when canManageAssetSummary is true', () => {
const { result } = setup({ privileges: { canManageAssetSummary: true } }, false);
expect(result.current).toBe(true);
});

it('should return true when both canEditDescription and canUpdateGlossaryEntity are true', () => {
it('should return true when canUpdateGlossaryEntity is true', () => {
const { result } = setup({ privileges: { canEditDescription: false, canManageAssetSummary: false } }, true);
expect(result.current).toBe(true);
});

it('should return true when all permissions are true', () => {
const { result } = setup({ privileges: { canEditDescription: true, canManageAssetSummary: true } }, true);
expect(result.current).toBe(true);
});

it('should return true when two permissions are true (canEditDescription, canUpdateGlossaryEntity)', () => {
const { result } = setup({ privileges: { canEditDescription: true } }, true);
expect(result.current).toBe(true);
});

it('should return false when both canEditDescription and canUpdateGlossaryEntity are false', () => {
const { result } = setup({ privileges: { canEditDescription: false } }, false);
it('should return true when two permissions are true (canManageAssetSummary, canUpdateGlossaryEntity)', () => {
const { result } = setup({ privileges: { canManageAssetSummary: true } }, true);
expect(result.current).toBe(true);
});

it('should return false when all permissions are false', () => {
const { result } = setup({ privileges: { canEditDescription: false, canManageAssetSummary: false } }, false);
expect(result.current).toBe(false);
});

Expand All @@ -57,12 +72,12 @@ describe('useDocumentationPermissions', () => {
expect(result.current).toBe(true);
});

it('should return false when entityData.privileges is missing and canUpdateGlossaryEntity is false', () => {
it('should return false when privileges is missing and canUpdateGlossaryEntity is false', () => {
const { result } = setup({}, false);
expect(result.current).toBe(false);
});

it('should return true when entityData.privileges is missing but canUpdateGlossaryEntity is true', () => {
it('should return true when privileges is missing but canUpdateGlossaryEntity is true', () => {
const { result } = setup({}, true);
expect(result.current).toBe(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export function useDocumentationPermission() {
// Edit description permission
const canEditDescription = !!entityData?.privileges?.canEditDescription;

const hasDocumentationPermissions = canEditDescription || canUpdateGlossaryEntity;
const canManageSummary = !!entityData?.privileges?.canManageAssetSummary;

const hasDocumentationPermissions = canEditDescription || canUpdateGlossaryEntity || canManageSummary;

return hasDocumentationPermissions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vi.mock('@app/entityV2/summary/shared/useCanUpdateGlossaryEntity', () => ({
useCanUpdateGlossaryEntity: vi.fn(),
}));

describe('useGetLinkPermissions', () => {
describe('useLinkPermission', () => {
const setup = (entityDataProps, canUpdateGlossaryEntityMock) => {
(useEntityData as unknown as any).mockReturnValue({
entityData: entityDataProps,
Expand All @@ -27,23 +27,43 @@ describe('useGetLinkPermissions', () => {
vi.resetAllMocks();
});

it('should return true when canEditLinks is true and canUpdateGlossaryEntity is false', () => {
it('should return true when canEditLinks is true', () => {
const { result } = setup({ privileges: { canEditLinks: true } }, false);
expect(result.current).toBe(true);
});

it('should return true when canEditLinks is false and canUpdateGlossaryEntity is true', () => {
it('should return true when canUpdateGlossaryEntity is true', () => {
const { result } = setup({ privileges: { canEditLinks: false } }, true);
expect(result.current).toBe(true);
});

it('should return true when canManageAssetSummary is true', () => {
const { result } = setup({ privileges: { canEditLinks: false, canManageAssetSummary: true } }, false);
expect(result.current).toBe(true);
});

it('should return true when both canEditLinks and canUpdateGlossaryEntity are true', () => {
const { result } = setup({ privileges: { canEditLinks: true } }, true);
expect(result.current).toBe(true);
});

it('should return false when both canEditLinks and canUpdateGlossaryEntity are false', () => {
const { result } = setup({ privileges: { canEditLinks: false } }, false);
it('should return true when canEditLinks and canManageAssetSummary are true', () => {
const { result } = setup({ privileges: { canEditLinks: true, canManageAssetSummary: true } }, false);
expect(result.current).toBe(true);
});

it('should return true when canUpdateGlossaryEntity and canManageAssetSummary are true', () => {
const { result } = setup({ privileges: { canEditLinks: false, canManageAssetSummary: true } }, true);
expect(result.current).toBe(true);
});

it('should return true when all permissions are true', () => {
const { result } = setup({ privileges: { canEditLinks: true, canManageAssetSummary: true } }, true);
expect(result.current).toBe(true);
});

it('should return false when all permissions are false', () => {
const { result } = setup({ privileges: { canEditLinks: false, canManageAssetSummary: false } }, false);
expect(result.current).toBe(false);
});

Expand All @@ -57,12 +77,12 @@ describe('useGetLinkPermissions', () => {
expect(result.current).toBe(true);
});

it('should return false when entityData.privileges is missing and canUpdateGlossaryEntity is false', () => {
it('should return false when privileges is missing and canUpdateGlossaryEntity is false', () => {
const { result } = setup({}, false);
expect(result.current).toBe(false);
});

it('should return true when entityData.privileges is missing but canUpdateGlossaryEntity is true', () => {
it('should return true when privileges is missing but canUpdateGlossaryEntity is true', () => {
const { result } = setup({}, true);
expect(result.current).toBe(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export function useLinkPermission() {

// Edit links permission
const canEditLinks = !!entityData?.privileges?.canEditLinks;
const canManageSummary = !!entityData?.privileges?.canManageAssetSummary;

const hasLinkPermissions = canEditLinks || canUpdateGlossaryEntity;
const hasLinkPermissions = canEditLinks || canUpdateGlossaryEntity || canManageSummary;

return hasLinkPermissions;
}
Loading