forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): fix updates from the UI (datahub-project#3280)
- Loading branch information
1 parent
3574294
commit b1e6c61
Showing
16 changed files
with
516 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/mutate/DescriptionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.linkedin.datahub.graphql.resolvers.mutate; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.authorization.AuthorizationUtils; | ||
import com.linkedin.datahub.graphql.authorization.ConjunctivePrivilegeGroup; | ||
import com.linkedin.datahub.graphql.authorization.DisjunctivePrivilegeGroup; | ||
import com.linkedin.datahub.graphql.generated.SubResourceType; | ||
import com.linkedin.metadata.authorization.PoliciesConfig; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import com.linkedin.schema.EditableSchemaFieldInfo; | ||
import com.linkedin.schema.EditableSchemaMetadata; | ||
import javax.annotation.Nonnull; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.mutate.MutationUtils.*; | ||
|
||
|
||
@Slf4j | ||
public class DescriptionUtils { | ||
private static final ConjunctivePrivilegeGroup ALL_PRIVILEGES_GROUP = new ConjunctivePrivilegeGroup(ImmutableList.of( | ||
PoliciesConfig.EDIT_ENTITY_PRIVILEGE.getType() | ||
)); | ||
|
||
private DescriptionUtils() { } | ||
|
||
public static final String EDITABLE_SCHEMA_METADATA = "editableSchemaMetadata"; | ||
|
||
public static void updateFieldDescription( | ||
String newDescription, | ||
Urn resourceUrn, | ||
String fieldPath, | ||
Urn actor, | ||
EntityService entityService | ||
) { | ||
EditableSchemaMetadata editableSchemaMetadata = | ||
(EditableSchemaMetadata) getAspectFromEntity( | ||
resourceUrn.toString(), EDITABLE_SCHEMA_METADATA, entityService, new EditableSchemaMetadata()); | ||
EditableSchemaFieldInfo editableFieldInfo = getFieldInfoFromSchema(editableSchemaMetadata, fieldPath); | ||
|
||
editableFieldInfo.setDescription(newDescription); | ||
|
||
persistAspect(resourceUrn, editableSchemaMetadata, actor, entityService); | ||
} | ||
|
||
public static Boolean validateFieldDescriptionInput( | ||
Urn resourceUrn, | ||
String subResource, | ||
SubResourceType subResourceType, | ||
EntityService entityService | ||
) { | ||
if (!entityService.exists(resourceUrn)) { | ||
throw new IllegalArgumentException(String.format("Failed to update %s. %s does not exist.", resourceUrn, resourceUrn)); | ||
} | ||
|
||
validateSubresourceExists(resourceUrn, subResource, subResourceType, entityService); | ||
|
||
return true; | ||
} | ||
|
||
public static boolean isAuthorizedToUpdateFieldDescription(@Nonnull QueryContext context, Urn targetUrn) { | ||
final DisjunctivePrivilegeGroup orPrivilegeGroups = new DisjunctivePrivilegeGroup(ImmutableList.of( | ||
ALL_PRIVILEGES_GROUP, | ||
new ConjunctivePrivilegeGroup(ImmutableList.of(PoliciesConfig.EDIT_DATASET_COL_DESCRIPTION_PRIVILEGE.getType())) | ||
)); | ||
|
||
return AuthorizationUtils.isAuthorized( | ||
context.getAuthorizer(), | ||
context.getActor(), | ||
targetUrn.getEntityType(), | ||
targetUrn.toString(), | ||
orPrivilegeGroups); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.