mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-31 12:39:01 +00:00
Issue-19066: ViewAll() not working with matchAnyTag() and isOwner() conditions (#19209)
* Issue-19066: ViewAll() not working with matchAnyTag() and isOwner() conditions * Issue-19066: ViewAll() not working with matchAnyTag() and isOwner() conditions * Fix tests * Minor: Fix checkstyle --------- Co-authored-by: Aniket Katkar <aniketkatkar97@gmail.com>
This commit is contained in:
parent
29b48bec51
commit
6142f24bca
@ -248,6 +248,8 @@ public final class Entity {
|
||||
public static final String DOCUMENT = "document";
|
||||
// ServiceType - Service Entity name map
|
||||
static final Map<ServiceType, String> SERVICE_TYPE_ENTITY_MAP = new EnumMap<>(ServiceType.class);
|
||||
// entity type to service entity name map
|
||||
static final Map<String, String> ENTITY_SERVICE_TYPE_MAP = new HashMap<>();
|
||||
public static final List<String> PARENT_ENTITY_TYPES = new ArrayList<>();
|
||||
|
||||
static {
|
||||
@ -260,6 +262,24 @@ public final class Entity {
|
||||
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.STORAGE, STORAGE_SERVICE);
|
||||
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.SEARCH, SEARCH_SERVICE);
|
||||
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.API, API_SERVICE);
|
||||
|
||||
ENTITY_SERVICE_TYPE_MAP.put(DATABASE, DATABASE_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(DATABASE_SCHEMA, DATABASE_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(TABLE, DATABASE_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(STORED_PROCEDURE, DATABASE_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(QUERY, DATABASE_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(DASHBOARD, DASHBOARD_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(DASHBOARD_DATA_MODEL, DASHBOARD_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(CHART, DASHBOARD_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(PIPELINE, PIPELINE_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(MLMODEL, MLMODEL_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(TOPIC, MESSAGING_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(API, API_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(API_COLLCECTION, API_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(API_ENDPOINT, API_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(CONTAINER, STORAGE_SERVICE);
|
||||
ENTITY_SERVICE_TYPE_MAP.put(SEARCH_INDEX, SEARCH_SERVICE);
|
||||
|
||||
PARENT_ENTITY_TYPES.addAll(
|
||||
listOf(
|
||||
DATABASE_SERVICE,
|
||||
@ -636,4 +656,11 @@ public final class Entity {
|
||||
public static <T> T getSearchRepo() {
|
||||
return (T) searchRepository;
|
||||
}
|
||||
|
||||
public static String getServiceType(String entityType) {
|
||||
if (ENTITY_SERVICE_TYPE_MAP.containsKey(entityType)) {
|
||||
return ENTITY_SERVICE_TYPE_MAP.get(entityType);
|
||||
}
|
||||
return entityType;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.openmetadata.schema.type.Relationship;
|
||||
import org.openmetadata.schema.utils.EntityInterfaceUtil;
|
||||
import org.openmetadata.service.Entity;
|
||||
import org.openmetadata.service.resources.databases.DatasourceConfig;
|
||||
import org.openmetadata.service.security.policyevaluator.ResourceContext;
|
||||
import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
public class ListFilter extends Filter<ListFilter> {
|
||||
@ -52,6 +53,25 @@ public class ListFilter extends Filter<ListFilter> {
|
||||
return condition.isEmpty() ? "WHERE TRUE" : "WHERE " + condition;
|
||||
}
|
||||
|
||||
public ResourceContext getResourceContext(String entityType) {
|
||||
if (queryParams.containsKey("service") && queryParams.get("service") != null) {
|
||||
return new ResourceContext<>(
|
||||
Entity.getServiceType(entityType), null, queryParams.get("service"));
|
||||
} else if (queryParams.containsKey(Entity.DATABASE)
|
||||
&& queryParams.get(Entity.DATABASE) != null) {
|
||||
return new ResourceContext<>(Entity.DATABASE, null, queryParams.get(Entity.DATABASE));
|
||||
} else if (queryParams.containsKey(Entity.DATABASE_SCHEMA)
|
||||
&& queryParams.get(Entity.DATABASE_SCHEMA) != null) {
|
||||
return new ResourceContext<>(
|
||||
Entity.DATABASE_SCHEMA, null, queryParams.get(Entity.DATABASE_SCHEMA));
|
||||
} else if (queryParams.containsKey(Entity.API_COLLCECTION)
|
||||
&& queryParams.get(Entity.API_COLLCECTION) != null) {
|
||||
return new ResourceContext<>(
|
||||
Entity.API_COLLCECTION, null, queryParams.get(Entity.API_COLLCECTION));
|
||||
}
|
||||
return new ResourceContext<>(entityType);
|
||||
}
|
||||
|
||||
private String getAssignee() {
|
||||
String assignee = queryParams.get("assignee");
|
||||
return assignee == null ? "" : String.format("assignee = '%s'", assignee);
|
||||
|
@ -144,7 +144,7 @@ public abstract class EntityResource<T extends EntityInterface, K extends Entity
|
||||
Fields fields = getFields(fieldsParam);
|
||||
OperationContext listOperationContext =
|
||||
new OperationContext(entityType, getViewOperations(fields));
|
||||
|
||||
ResourceContext resourceContext = filter.getResourceContext(entityType);
|
||||
return listInternal(
|
||||
uriInfo,
|
||||
securityContext,
|
||||
@ -154,7 +154,7 @@ public abstract class EntityResource<T extends EntityInterface, K extends Entity
|
||||
before,
|
||||
after,
|
||||
listOperationContext,
|
||||
getResourceContext());
|
||||
resourceContext);
|
||||
}
|
||||
|
||||
public ResultList<T> listInternal(
|
||||
|
@ -197,16 +197,17 @@ public class CompiledRule extends Rule {
|
||||
}
|
||||
|
||||
private boolean matchOperation(MetadataOperation operation) {
|
||||
if (getOperations().contains(MetadataOperation.ALL)) {
|
||||
List<MetadataOperation> operations = getOperations();
|
||||
if (operations.contains(MetadataOperation.ALL)) {
|
||||
LOG.debug("matched all operations");
|
||||
return true; // Match all operations
|
||||
}
|
||||
if (getOperations().contains(MetadataOperation.EDIT_ALL)
|
||||
if (operations.contains(MetadataOperation.EDIT_ALL)
|
||||
&& OperationContext.isEditOperation(operation)) {
|
||||
LOG.debug("matched editAll operations");
|
||||
return true;
|
||||
}
|
||||
if (getOperations().contains(MetadataOperation.VIEW_ALL)
|
||||
if (operations.contains(MetadataOperation.VIEW_ALL)
|
||||
&& OperationContext.isViewOperation(operation)) {
|
||||
LOG.debug("matched viewAll operations");
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user