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:
Sriharsha Chintalapani 2025-01-07 07:39:46 -08:00 committed by GitHub
parent 29b48bec51
commit 6142f24bca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 5 deletions

View File

@ -248,6 +248,8 @@ public final class Entity {
public static final String DOCUMENT = "document"; public static final String DOCUMENT = "document";
// ServiceType - Service Entity name map // ServiceType - Service Entity name map
static final Map<ServiceType, String> SERVICE_TYPE_ENTITY_MAP = new EnumMap<>(ServiceType.class); 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<>(); public static final List<String> PARENT_ENTITY_TYPES = new ArrayList<>();
static { static {
@ -260,6 +262,24 @@ public final class Entity {
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.STORAGE, STORAGE_SERVICE); SERVICE_TYPE_ENTITY_MAP.put(ServiceType.STORAGE, STORAGE_SERVICE);
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.SEARCH, SEARCH_SERVICE); SERVICE_TYPE_ENTITY_MAP.put(ServiceType.SEARCH, SEARCH_SERVICE);
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.API, API_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( PARENT_ENTITY_TYPES.addAll(
listOf( listOf(
DATABASE_SERVICE, DATABASE_SERVICE,
@ -636,4 +656,11 @@ public final class Entity {
public static <T> T getSearchRepo() { public static <T> T getSearchRepo() {
return (T) searchRepository; 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;
}
} }

View File

@ -11,6 +11,7 @@ import org.openmetadata.schema.type.Relationship;
import org.openmetadata.schema.utils.EntityInterfaceUtil; import org.openmetadata.schema.utils.EntityInterfaceUtil;
import org.openmetadata.service.Entity; import org.openmetadata.service.Entity;
import org.openmetadata.service.resources.databases.DatasourceConfig; import org.openmetadata.service.resources.databases.DatasourceConfig;
import org.openmetadata.service.security.policyevaluator.ResourceContext;
import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.FullyQualifiedName;
public class ListFilter extends Filter<ListFilter> { public class ListFilter extends Filter<ListFilter> {
@ -52,6 +53,25 @@ public class ListFilter extends Filter<ListFilter> {
return condition.isEmpty() ? "WHERE TRUE" : "WHERE " + condition; 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() { private String getAssignee() {
String assignee = queryParams.get("assignee"); String assignee = queryParams.get("assignee");
return assignee == null ? "" : String.format("assignee = '%s'", assignee); return assignee == null ? "" : String.format("assignee = '%s'", assignee);

View File

@ -144,7 +144,7 @@ public abstract class EntityResource<T extends EntityInterface, K extends Entity
Fields fields = getFields(fieldsParam); Fields fields = getFields(fieldsParam);
OperationContext listOperationContext = OperationContext listOperationContext =
new OperationContext(entityType, getViewOperations(fields)); new OperationContext(entityType, getViewOperations(fields));
ResourceContext resourceContext = filter.getResourceContext(entityType);
return listInternal( return listInternal(
uriInfo, uriInfo,
securityContext, securityContext,
@ -154,7 +154,7 @@ public abstract class EntityResource<T extends EntityInterface, K extends Entity
before, before,
after, after,
listOperationContext, listOperationContext,
getResourceContext()); resourceContext);
} }
public ResultList<T> listInternal( public ResultList<T> listInternal(

View File

@ -197,16 +197,17 @@ public class CompiledRule extends Rule {
} }
private boolean matchOperation(MetadataOperation operation) { private boolean matchOperation(MetadataOperation operation) {
if (getOperations().contains(MetadataOperation.ALL)) { List<MetadataOperation> operations = getOperations();
if (operations.contains(MetadataOperation.ALL)) {
LOG.debug("matched all operations"); LOG.debug("matched all operations");
return true; // Match all operations return true; // Match all operations
} }
if (getOperations().contains(MetadataOperation.EDIT_ALL) if (operations.contains(MetadataOperation.EDIT_ALL)
&& OperationContext.isEditOperation(operation)) { && OperationContext.isEditOperation(operation)) {
LOG.debug("matched editAll operations"); LOG.debug("matched editAll operations");
return true; return true;
} }
if (getOperations().contains(MetadataOperation.VIEW_ALL) if (operations.contains(MetadataOperation.VIEW_ALL)
&& OperationContext.isViewOperation(operation)) { && OperationContext.isViewOperation(operation)) {
LOG.debug("matched viewAll operations"); LOG.debug("matched viewAll operations");
return true; return true;