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

Organization Visibility Capability #12730

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
62cd1b1
Add initial implementation
chamilaadhi Aug 13, 2024
413a84a
Merge pull request #12512 from chamilaadhi/org_visibility
chamilaadhi Aug 13, 2024
6930c4e
Add api org visibility to registry property
chamilaadhi Aug 16, 2024
197b95c
Add application sharing with the organization
chamilaadhi Aug 17, 2024
9514f90
Remove invalid files
chamilaadhi Aug 17, 2024
bdbab23
Merge pull request #12517 from chamilaadhi/org_visibility
chamilaadhi Aug 17, 2024
74ce0a9
Add application visibility info to the payload
chamilaadhi Aug 21, 2024
44adec3
Allow api visibility to admin users
chamilaadhi Aug 21, 2024
20abc2d
Merge pull request #12519 from chamilaadhi/org_visibility
chamilaadhi Aug 21, 2024
9b4b931
Fix bug
chamilaadhi Aug 21, 2024
6a13494
Merge pull request #12521 from chamilaadhi/org_visibility
chamilaadhi Aug 21, 2024
cbbec05
Add subscription tiers visibility by org
chamilaadhi Aug 23, 2024
6f04ad5
Merge pull request #12523 from chamilaadhi/org_visibility
chamilaadhi Aug 23, 2024
75f595d
Fix issues
chamilaadhi Aug 28, 2024
3a95871
Merge pull request #12528 from chamilaadhi/test-org
chamilaadhi Aug 28, 2024
364cec9
Fix admin dev portal api loading issue
chamilaadhi Aug 29, 2024
ba78056
Add indexed document modification logic
chamilaadhi Aug 29, 2024
2aa39f2
Merge pull request #12529 from chamilaadhi/org_visibility
chamilaadhi Aug 29, 2024
78bb1e7
Fix bug
chamilaadhi Sep 5, 2024
788ee7e
Merge pull request #12542 from chamilaadhi/org_visibility
chamilaadhi Sep 6, 2024
c7f06ad
Merge remote-tracking branch 'upstream/org_visibility' into org_test
chamilaadhi Sep 6, 2024
fca7dd0
Merge pull request #12549 from chamilaadhi/org_test
chamilaadhi Sep 9, 2024
66ba661
Fix multiple status display issue
chamilaadhi Sep 12, 2024
1fa232f
Fix shared application view issue
chamilaadhi Sep 12, 2024
cd392b5
Merge pull request #12559 from chamilaadhi/org_visibility
chamilaadhi Sep 12, 2024
e28bc64
Introduce config to enable org related visibility
chamilaadhi Sep 18, 2024
e1f97f1
Add dev portal org visibility to seperate section
chamilaadhi Sep 18, 2024
034ca35
Fix bug
chamilaadhi Sep 18, 2024
134b2c0
Fix bug
chamilaadhi Sep 18, 2024
60441da
Merge pull request #12572 from chamilaadhi/org_visibility
chamilaadhi Sep 18, 2024
62c00fc
Add capability to append org id and org name to dev portal token urls
chamilaadhi Sep 24, 2024
a33a3dd
Backend for keymanager visibility
chamilaadhi Oct 2, 2024
1ea20af
Revert url template change
chamilaadhi Oct 2, 2024
8a875bc
Format
chamilaadhi Oct 2, 2024
1c4e79a
Merge pull request #12592 from chamilaadhi/org_visibility
chamilaadhi Oct 2, 2024
9477c98
Refactor subcription visibility db
chamilaadhi Oct 4, 2024
4b34048
Merge pull request #12634 from chamilaadhi/org_visibility
chamilaadhi Oct 4, 2024
48ec34a
Fix app keys loading issue for shared apps
chamilaadhi Oct 7, 2024
d892178
Merge pull request #12640 from chamilaadhi/org_visibility
chamilaadhi Oct 7, 2024
88b7607
Add capability to use multiple keymanagers with same issuer
chamilaadhi Oct 9, 2024
27b3d21
Merge pull request #12652 from chamilaadhi/org_visibility
chamilaadhi Oct 9, 2024
6a6d5ce
Add org with spaces in the name
chamilaadhi Oct 10, 2024
4ca72b4
Merge pull request #12653 from chamilaadhi/org_visibility
chamilaadhi Oct 10, 2024
9081ab9
Fix orgs with space
chamilaadhi Oct 11, 2024
867d569
Merge pull request #12655 from chamilaadhi/org_visibility
chamilaadhi Oct 11, 2024
763494a
Provide config to set claim to select the organization info
chamilaadhi Oct 15, 2024
10c523b
Merge pull request #12670 from chamilaadhi/org_visibility
chamilaadhi Oct 15, 2024
1c6916b
Fix api overview page visibility
chamilaadhi Oct 16, 2024
08f9959
Merge pull request #12675 from chamilaadhi/org_visibility
chamilaadhi Oct 16, 2024
9d8bb3d
Merge remote-tracking branch 'upstream/master' into org_visibility_ma…
chamilaadhi Nov 22, 2024
10b0c64
Merge pull request #12707 from chamilaadhi/org_visibility
chamilaadhi Nov 22, 2024
60c483e
Fix issues related to unit test failures -carbon.apimgt.persistence
RusJaI Nov 22, 2024
3eafcbc
Fix issues related to unit test failures - carbon.apimgt.impl
RusJaI Nov 24, 2024
12961fb
Fix issues related to unit test failures - carbon.apimgt.gateway
RusJaI Nov 25, 2024
41002da
Undo expanding waiting time
RusJaI Nov 25, 2024
442cc04
Update language level for apimgt.impl component. This is not affected…
RusJaI Nov 25, 2024
e0c2c6b
Fix unit test related issues
RusJaI Nov 26, 2024
0ccafa1
Merge pull request #12711 from RusJaI/org_visibility
chamilaadhi Nov 26, 2024
e907f6d
Fix unified API search for APIs across organizations
RusJaI Dec 2, 2024
946c893
Fix tag based search
RusJaI Dec 3, 2024
2565f11
Fix api state based search
RusJaI Dec 4, 2024
011aab7
Fix api category based search
RusJaI Dec 4, 2024
f6aae23
Fix the visibility of API in Store for admin in same domain
RusJaI Dec 9, 2024
134262e
Maintain existing behavior when org visibility is not enabled
RusJaI Dec 10, 2024
a237ec8
save visibility value as a property for api artifacts
RusJaI Dec 12, 2024
99ecfb4
Introduce constants for search attribute fields
RusJaI Dec 27, 2024
354b156
Refactor the function which adds org visibility value for API Artifacts
RusJaI Dec 27, 2024
ecd772f
Merge pull request #12717 from RusJaI/org_visibility
chamilaadhi Jan 2, 2025
cb2da14
Merge remote-tracking branch 'upstream/org_visibility' into master-ne…
chamilaadhi Jan 2, 2025
012f9f5
Fix NPE in product listing in dev portal
chamilaadhi Jan 7, 2025
3369374
Fix dev portal rest api search
chamilaadhi Jan 8, 2025
d558299
Merge branch 'org_visibility' into master-new-merge
chamilaadhi Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix unified API search for APIs across organizations
  • Loading branch information
RusJaI committed Dec 2, 2024
commit e907f6d1c247caeb69fd7f37fca128494e529397
Original file line number Diff line number Diff line change
Expand Up @@ -904,4 +904,15 @@ boolean isKeyManagerByNameAllowedForUser(String keyManagerName, String organizat
*/
Map<String, Object> searchPaginatedAPIs(String searchQuery, OrganizationInfo organizationInfo, int start, int end,
String sortBy, String sortOrder) throws APIManagementException;

/**
* @param searchQuery search query
* @param organizationInfo Information about the organization
* @param start
* @param end
* @return
* @throws APIManagementException
*/
Map<String, Object> searchPaginatedContent(String searchQuery, OrganizationInfo organizationInfo, int start, int end)
throws APIManagementException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4192,6 +4192,31 @@ public API getLightweightAPI(APIIdentifier identifier, String orgId) throws APIM
public Map<String, Object> searchPaginatedContent(String searchQuery, String organization, int start, int end)
throws APIManagementException {

String userame = (userNameWithoutChange != null) ? userNameWithoutChange : username;
Organization org = new Organization(organization);
Map<String, Object> properties = APIUtil.getUserProperties(userame);
String[] roles = APIUtil.getFilteredUserRoles(userame);
;
UserContext ctx = new UserContext(userame, org, properties, roles);
return searchPaginatedContent(org, searchQuery, start, end, ctx);
}

@Override
public Map<String, Object> searchPaginatedContent(String searchQuery, OrganizationInfo organizationInfo,
int start, int end) throws APIManagementException {

String userName = (userNameWithoutChange != null) ? userNameWithoutChange : username;
Organization org = new Organization(organizationInfo.getSuperOrganization());
Map<String, Object> properties = APIUtil.getUserProperties(userName);
String[] roles = APIUtil.getFilteredUserRoles(userName);

UserContext ctx = new UserContext(userName, new Organization(organizationInfo.getOrganizationSelector()),
properties, roles);
return searchPaginatedContent(org, searchQuery, start, end, ctx);
}

private Map<String, Object> searchPaginatedContent(Organization org, String searchQuery, int start, int end,
UserContext ctx) throws APIManagementException {
ArrayList<Object> compoundResult = new ArrayList<Object>();
Map<Documentation, API> docMap = new HashMap<Documentation, API>();
Map<String, Object> result = new HashMap<String, Object>();
Expand All @@ -4200,13 +4225,6 @@ public Map<String, Object> searchPaginatedContent(String searchQuery, String org
List<APIDefinitionContentSearchResult> defSearchList = new ArrayList<>();
int totalLength = 0;

String userame = (userNameWithoutChange != null) ? userNameWithoutChange : username;
Organization org = new Organization(organization);
Map<String, Object> properties = APIUtil.getUserProperties(userame);
String[] roles = APIUtil.getFilteredUserRoles(userame);
;
UserContext ctx = new UserContext(userame, org, properties, roles);

try {
DevPortalContentSearchResult sResults = apiPersistenceInstance.searchContentForDevPortal(org, searchQuery,
start, end, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class RegistrySearchUtil {
public static final String SOAP_DEFINITION_INDEXER = "org.wso2.carbon.apimgt.impl.indexing.indexer" +
".SOAPAPIDefinitionIndexer";
public static final String STORE_VIEW_ROLES = "store_view_roles";
public static final String VISIBLE_ORGANIZATIONS = "visible_organizations";
public static final String PUBLISHER_ROLES = "publisher_roles";
public static final String DOCUMENT_MEDIA_TYPE_KEY = "application/vnd.wso2-document\\+xml";
public static final String API_DEF_MEDIA_TYPE_KEY = "application/json";
Expand Down Expand Up @@ -241,12 +242,28 @@ private static Map<String, String> getSearchAttributes(String searchQuery) {
String apiState = "";
String publisherRoles = "";
Map<String, String> attributes = new HashMap<String, String>();
String devportalFilterQuery = "";
String devportalFilterQueryField = "";
for (String searchCriterea : searchQueries) {
String[] keyVal = searchCriterea.split("=");
if (STORE_VIEW_ROLES.equals(keyVal[0])) {
attributes.put("propertyName", keyVal[0]);
attributes.put("rightPropertyValue", keyVal[1]);
attributes.put("rightOp", "eq");
if (!StringUtils.isEmpty(keyVal[1])) {
if (StringUtils.isEmpty(devportalFilterQuery)) {
devportalFilterQueryField = STORE_VIEW_ROLES;
devportalFilterQuery = keyVal[1];
} else {
devportalFilterQuery += (" AND store_view_roles_ss:" + keyVal[1]);
}
}
} else if (VISIBLE_ORGANIZATIONS.equals(keyVal[0])) {
if (!StringUtils.isEmpty(keyVal[1])) {
if (StringUtils.isEmpty(devportalFilterQuery)) {
devportalFilterQueryField = VISIBLE_ORGANIZATIONS;
devportalFilterQuery = keyVal[1];
} else {
devportalFilterQuery += (" AND visible_organizations_ss:" + keyVal[1]);
}
}
} else if (PUBLISHER_ROLES.equals(keyVal[0])) {
publisherRoles = keyVal[1];
} else {
Expand All @@ -258,6 +275,11 @@ private static Map<String, String> getSearchAttributes(String searchQuery) {
attributes.put(keyVal[0], keyVal[1]);
}
}
if (!StringUtils.isEmpty(devportalFilterQueryField)) {
attributes.put("propertyName", devportalFilterQueryField);
attributes.put("rightPropertyValue", devportalFilterQuery);
attributes.put("rightOp", "eq");
}

//check whether the new document indexer is engaged
RegistryConfigLoader registryConfig = RegistryConfigLoader.getInstance();
Expand Down Expand Up @@ -431,6 +453,28 @@ private static String getDevPortalRolesWrappedQuery(String query, UserContext co
return criteria;
}

private static String getOrganizationVisibilityWrappedQuery(String query, UserContext context) {
if (PersistenceUtil.isAdminUser(context)) {
log.debug("Admin user. no modifications to the query");
return query;
}

String orgName = context.getOrganization().getName();
if (orgName != null && orgName.contains(" ")) {
orgName = orgName.replace(" ", "+");
}

String criteria = VISIBLE_ORGANIZATIONS + "=" + "(" + APIConstants.DEFAULT_VISIBLE_ORG + " OR " + orgName + ")";
if (query != null && !query.trim().isEmpty()) {
criteria = criteria + "&" + query;
}
if (log.isDebugEnabled()) {
log.debug("Organization visibility wrapped query : " + criteria);
}
return criteria;
}


private static String getUserRolesQuery(String[] userRoles, String skippedRoles) {

StringBuilder rolesQuery = new StringBuilder();
Expand Down Expand Up @@ -597,6 +641,7 @@ public static Map<String, String> getDevPortalSearchAttributes(String searchQuer
modifiedQuery = StringUtils.replaceIgnoreCase(modifiedQuery, searchString,
APIConstants.LCSTATE_SEARCH_TYPE_KEY);
}
modifiedQuery = RegistrySearchUtil.getOrganizationVisibilityWrappedQuery(modifiedQuery, ctx);
modifiedQuery = RegistrySearchUtil.getDevPortalRolesWrappedQuery(modifiedQuery, ctx);
modifiedQuery = RegistrySearchUtil.getDevPortalVisibilityWrappedQuery(modifiedQuery, isCrossTenant);
Map<String, String> attributes = RegistrySearchUtil.getSearchAttributes(modifiedQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.wso2.carbon.apimgt.api.model.APIDefinitionContentSearchResult;
import org.wso2.carbon.apimgt.api.model.APIProduct;
import org.wso2.carbon.apimgt.api.model.Documentation;
import org.wso2.carbon.apimgt.api.model.OrganizationInfo;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.rest.api.common.RestApiCommonUtil;
import org.wso2.carbon.apimgt.rest.api.store.v1.SearchApiService;
Expand Down Expand Up @@ -55,9 +56,12 @@ public Response searchGet(Integer limit, Integer offset, String xWSO2Tenant, Str
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
query = query == null ? "*" : query;
String organization = RestApiUtil.getOrganization(messageContext);

try {
String superOrganization = RestApiUtil.getValidatedOrganization(messageContext);
OrganizationInfo orgInfo = RestApiUtil.getOrganizationInfo(messageContext);
orgInfo.setSuperOrganization(superOrganization);

if (!query.contains(":")) {
query = (APIConstants.CONTENT_SEARCH_TYPE_PREFIX + ":" + query);
}
Expand All @@ -66,11 +70,11 @@ public Response searchGet(Integer limit, Integer offset, String xWSO2Tenant, Str
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
Map<String, Object> result = null;
// Extracting search queries for the recommendation system
apiConsumer.publishSearchQuery(query, username, organization);
apiConsumer.publishSearchQuery(query, username, superOrganization);
if (query.startsWith(APIConstants.CONTENT_SEARCH_TYPE_PREFIX)) {
result = apiConsumer.searchPaginatedContent(query, organization, offset, limit);
result = apiConsumer.searchPaginatedContent(query, orgInfo, offset, limit);
} else {
result = apiConsumer.searchPaginatedAPIs(query, organization, offset, limit, null, null);
result = apiConsumer.searchPaginatedAPIs(query, orgInfo, offset, limit, null, null);
}

ArrayList<Object> apis;
Expand Down