Skip to content

Commit

Permalink
Merge branch 'issue-19066' into test-for-viewall
Browse files Browse the repository at this point in the history
  • Loading branch information
rushikesh1799 authored Jan 6, 2025
2 parents 85418d9 + e394e3b commit e7cc374
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -636,4 +656,11 @@ public static <T> T getDao() {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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> {
Expand Down Expand Up @@ -52,6 +53,25 @@ public String getCondition(String tableName) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public ResultList<T> listInternal(
Fields fields = getFields(fieldsParam);
OperationContext listOperationContext =
new OperationContext(entityType, getViewOperations(fields));

ResourceContext resourceContext = filter.getResourceContext(entityType);
return listInternal(
uriInfo,
securityContext,
Expand All @@ -154,7 +154,7 @@ public ResultList<T> listInternal(
before,
after,
listOperationContext,
getResourceContext());
resourceContext);
}

public ResultList<T> listInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,17 @@ protected boolean matchResource(String resource) {
}

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;
Expand Down

0 comments on commit e7cc374

Please sign in to comment.