Skip to content

Commit

Permalink
Set Tag Authorization error as 403 error code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamalaseshan Radha authored and Kamalaseshan Radha committed Aug 18, 2023
1 parent 0da4478 commit 5067773
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public enum DataHubGraphQLErrorCode {
BAD_REQUEST(400),
UNAUTHORIZED(403),
NOT_FOUND(404),
UNAUTHORIZED_TAG_ERROR(405),
SERVER_ERROR(500);

private final int _code;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.linkedin.common.urn.Urn;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.exception.TagAuthorizationException;
import com.linkedin.datahub.graphql.generated.ResourceRefInput;
import com.linkedin.datahub.graphql.generated.TagAssociationInput;
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils;
Expand Down Expand Up @@ -37,7 +36,7 @@ public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throw
}

if (!LabelUtils.isAuthorizedToAssociateTag(environment.getContext(), tagUrn)) {
throw new TagAuthorizationException("Only users granted permission to this tag can assign or remove it");
throw new AuthorizationException("Only users granted permission to this tag can assign or remove it");
}

return CompletableFuture.supplyAsync(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.linkedin.common.urn.UrnUtils;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.exception.TagAuthorizationException;
import com.linkedin.datahub.graphql.generated.AddTagsInput;
import com.linkedin.datahub.graphql.generated.ResourceRefInput;
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils;
Expand Down Expand Up @@ -46,7 +45,7 @@ public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throw

tagUrns.forEach((tagUrn) -> {
if (!LabelUtils.isAuthorizedToAssociateTag(environment.getContext(), tagUrn)) {
throw new TagAuthorizationException("Only users granted permission to this tag can assign or remove it");
throw new AuthorizationException("Only users granted permission to this tag can assign or remove it");
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.linkedin.common.urn.UrnUtils;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.exception.TagAuthorizationException;
import com.linkedin.datahub.graphql.generated.BatchAddTagsInput;
import com.linkedin.datahub.graphql.generated.ResourceRefInput;
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils;
Expand Down Expand Up @@ -123,7 +122,7 @@ private void validateTags(List<Urn> tagUrns, QueryContext context) {
LabelUtils.validateLabel(tagUrn, Constants.TAG_ENTITY_NAME, _entityService);

if (!LabelUtils.isAuthorizedToAssociateTag(context, tagUrn)) {
throw new TagAuthorizationException("Only users granted permission to this tag can assign or remove it");
throw new AuthorizationException("Only users granted permission to this tag can assign or remove it");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.linkedin.common.urn.UrnUtils;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.exception.TagAuthorizationException;
import com.linkedin.datahub.graphql.generated.BatchRemoveTagsInput;
import com.linkedin.datahub.graphql.generated.ResourceRefInput;
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils;
Expand Down Expand Up @@ -57,7 +56,7 @@ public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throw
private void validateTags(List<Urn> tagUrns, QueryContext context) {
for (Urn tagUrn : tagUrns) {
if (!LabelUtils.isAuthorizedToAssociateTag(context, tagUrn)) {
throw new TagAuthorizationException("Only users granted permission to this tag can assign or remove it");
throw new AuthorizationException("Only users granted permission to this tag can assign or remove it");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.linkedin.common.urn.Urn;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.exception.TagAuthorizationException;
import com.linkedin.datahub.graphql.generated.ResourceRefInput;
import com.linkedin.datahub.graphql.generated.TagAssociationInput;
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils;
Expand Down Expand Up @@ -35,7 +34,7 @@ public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throw
throw new AuthorizationException("Unauthorized to perform this action. Please contact your DataHub administrator.");
}
if (!LabelUtils.isAuthorizedToAssociateTag(environment.getContext(), tagUrn)) {
throw new TagAuthorizationException("Only users granted permission to this tag can assign or remove it");
throw new AuthorizationException("Only users granted permission to this tag can assign or remove it");
}

return CompletableFuture.supplyAsync(() -> {
Expand Down
13 changes: 6 additions & 7 deletions datahub-web-react/src/app/entity/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,18 @@ function getGraphqlErrorCode(e) {

export const handleBatchError = (urns, e, defaultMessage) => {
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
if (e.message === 'Only users granted permission to this tag can assign or remove it') {
return {
content: `${e.message}. The bulk edit being performed will not be saved.`,
duration: 3,
};
}
return {
content:
'Your bulk edit selection included entities that you are unauthorized to update. The bulk edit being performed will not be saved.',
duration: 3,
};
}
if (urns.length > 1 && getGraphqlErrorCode(e) === 405) {
return {
content:
'Only users granted permission to this tag can assign or remove it. The bulk edit being performed will not be saved. ',
duration: 3,
};
}
return defaultMessage;
};

Expand Down

0 comments on commit 5067773

Please sign in to comment.