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

feat(auth): add viewTests platform privilege #10413

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public CompletableFuture<AuthenticatedUser> get(DataFetchingEnvironment environm
platformPrivileges.setManageIngestion(canManageIngestion(context));
platformPrivileges.setManageSecrets(canManageSecrets(context));
platformPrivileges.setManageTokens(canManageTokens(context));
platformPrivileges.setViewTests(canViewTests(context));
platformPrivileges.setManageTests(canManageTests(context));
platformPrivileges.setManageGlossaries(canManageGlossaries(context));
platformPrivileges.setManageUserCredentials(canManageUserCredentials(context));
Expand Down Expand Up @@ -130,6 +131,12 @@ private boolean canGeneratePersonalAccessToken(final QueryContext context) {
PoliciesConfig.GENERATE_PERSONAL_ACCESS_TOKENS_PRIVILEGE);
}

/** Returns true if the authenticated user has privileges to view tests. */
private boolean canViewTests(final QueryContext context) {
return isAuthorized(
context.getAuthorizer(), context.getActorUrn(), PoliciesConfig.VIEW_TESTS_PRIVILEGE);
}

/** Returns true if the authenticated user has privileges to manage (add or remove) tests. */
private boolean canManageTests(final QueryContext context) {
return isAuthorized(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CompletableFuture<ListTestsResult> get(final DataFetchingEnvironment envi

return CompletableFuture.supplyAsync(
() -> {
if (canManageTests(context)) {
if (canManageTests(context) || canViewTests(context)) {
final ListTestsInput input =
bindArgument(environment.getArgument("input"), ListTestsInput.class);
final Integer start = input.getStart() == null ? DEFAULT_START : input.getStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

public class TestUtils {

/** Returns true if the authenticated user is able to view tests. */
public static boolean canViewTests(@Nonnull QueryContext context) {
return AuthUtil.isAuthorized(
context.getAuthorizer(), context.getActorUrn(), PoliciesConfig.VIEW_TESTS_PRIVILEGE);
}

/** Returns true if the authenticated user is able to manage tests. */
public static boolean canManageTests(@Nonnull QueryContext context) {
return AuthUtil.isAuthorized(
Expand Down
5 changes: 5 additions & 0 deletions datahub-graphql-core/src/main/resources/app.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ type PlatformPrivileges {
"""
manageTokens: Boolean!

"""
Whether the user is able to view Tests
"""
viewTests: Boolean!

"""
Whether the user is able to manage Tests
"""
Expand Down
2 changes: 2 additions & 0 deletions datahub-web-react/src/Mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3617,6 +3617,7 @@ export const mocks = [
createTags: true,
manageUserCredentials: true,
manageGlossaries: true,
viewTests: false,
manageTests: true,
manageTokens: true,
manageSecrets: true,
Expand Down Expand Up @@ -3892,6 +3893,7 @@ export const platformPrivileges: PlatformPrivileges = {
manageIngestion: true,
manageSecrets: true,
manageTokens: true,
viewTests: false,
manageTests: true,
manageGlossaries: true,
manageUserCredentials: true,
Expand Down
1 change: 1 addition & 0 deletions datahub-web-react/src/graphql/me.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ query getMe {
manageSecrets
manageTokens
manageDomains
viewTests
manageTests
manageGlossaries
manageUserCredentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public class PoliciesConfig {
"Manage Home Page Posts",
"Create and delete home page posts");

public static final Privilege VIEW_TESTS_PRIVILEGE =
Privilege.of("VIEW_TESTS", "View Tests", "View Asset Tests.");

public static final Privilege MANAGE_TESTS_PRIVILEGE =
Privilege.of("MANAGE_TESTS", "Manage Tests", "Create and remove Asset Tests.");

Expand Down Expand Up @@ -154,6 +157,7 @@ public class PoliciesConfig {
MANAGE_SECRETS_PRIVILEGE,
GENERATE_PERSONAL_ACCESS_TOKENS_PRIVILEGE,
MANAGE_ACCESS_TOKENS,
VIEW_TESTS_PRIVILEGE,
MANAGE_TESTS_PRIVILEGE,
MANAGE_GLOSSARIES_PRIVILEGE,
MANAGE_USER_CREDENTIALS_PRIVILEGE,
Expand Down