Skip to content

Commit

Permalink
Merge remote-tracking branch 'acryl/jj--support-batch-domains-backend…
Browse files Browse the repository at this point in the history
…' into jj--support-batch-domains-backend
  • Loading branch information
jjoyce0510 committed Aug 4, 2022
2 parents 6b3d445 + caf4fea commit 6d973fa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void validateInputResources(List<ResourceRefInput> resources, QueryConte

private void validateInputResource(ResourceRefInput resource, QueryContext context) {
final Urn resourceUrn = UrnUtils.getUrn(resource.getResourceUrn());
if (!LabelUtils.isAuthorizedToUpdateTerms(context, resourceUrn, resource.getSubResource())) {
if (!DomainUtils.isAuthorizedToUpdateDomainsForEntity(context, resourceUrn)) {
throw new AuthorizationException("Unauthorized to perform this action. Please contact your DataHub administrator.");
}
LabelUtils.validateResource(resourceUrn, resource.getSubResource(), resource.getSubResourceType(), _entityService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public static void validateLabel(Urn labelUrn, String labelEntityType, EntitySer
}
}

// TODO: Move this out into a separate utilities class.
public static void validateResource(Urn resourceUrn, String subResource, SubResourceType subResourceType, EntityService entityService) {
if (!entityService.exists(resourceUrn)) {
throw new IllegalArgumentException(String.format("Failed to update resource with urn %s. Entity does not exist.", resourceUrn));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ export default function DomainsDropdown({ urns, disabled = false, refetch }: Pro
const [isEditModalVisible, setIsEditModalVisible] = useState(false);
const [batchSetDomainMutation] = useBatchSetDomainMutation();

const batchUnsetDomains = async () => {
try {
await batchSetDomainMutation({
variables: {
input: {
resources: [...urns.map((urn) => ({ resourceUrn: urn }))],
},
const batchUnsetDomains = () => {
batchSetDomainMutation({
variables: {
input: {
resources: [...urns.map((urn) => ({ resourceUrn: urn }))],
},
},
})
.then(({ errors }) => {
if (!errors) {
message.success({ content: 'Removed Domain!', duration: 2 });
refetch?.();
}
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to remove assets from Domain: \n ${e.message || ''}`, duration: 3 });
});
message.success({ content: 'Removed Domain!', duration: 2 });
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to re,pve Domain: \n ${e.message || ''}`, duration: 3 });
}
}
refetch?.();
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,25 @@ export const SetDomainModal = ({ urns, onCloseModal, refetch }: Props) => {
if (!selectedDomain) {
return;
}
try {
await batchSetDomainMutation({
variables: {
input: {
resources: [...urns.map((urn) => ({ resourceUrn: urn }))],
domainUrn: selectedDomain.urn,
},
batchSetDomainMutation({
variables: {
input: {
resources: [...urns.map((urn) => ({ resourceUrn: urn }))],
},
},
})
.then(({ errors }) => {
if (!errors) {
message.success({ content: 'Updated Domain!', duration: 2 });
refetch?.();
onModalClose();
setSelectedDomain(undefined);
}
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add assets to Domain: \n ${e.message || ''}`, duration: 3 });
});
message.success({ content: 'Updated Domain!', duration: 2 });
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to set Domain: \n ${e.message || ''}`, duration: 3 });
}
}
setSelectedDomain(undefined);
refetch?.();
onModalClose();
};

const selectValue = (selectedDomain && [selectedDomain?.displayName]) || undefined;
Expand Down

0 comments on commit 6d973fa

Please sign in to comment.