Skip to content

Commit

Permalink
Add method for fetching server-only roles assigned to user (#423)
Browse files Browse the repository at this point in the history
* Add method for fetching server-only roles assigned to user

* Add test for the new method
  • Loading branch information
andrian-sevastyanov authored Jun 14, 2024
1 parent 2c16879 commit e7f9d26
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private List<RoleView> getScopedRoles(BlackDuckRequestFilter scope) throws Integ
return blackDuckApiClient.getAllResponses(requestMultiple);
}

private BlackDuckRequestFilter createScopeFilter(String scope) {
public static BlackDuckRequestFilter createScopeFilter(String scope) {
return BlackDuckRequestFilter.createFilterWithSingleValue("scope", scope);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery;
import com.synopsys.integration.blackduck.api.generated.response.AssignedProjectView;
import com.synopsys.integration.blackduck.api.manual.view.ProjectView;
import com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder;
import com.synopsys.integration.blackduck.api.generated.view.RoleAssignmentView;
import com.synopsys.integration.blackduck.api.generated.view.RoleView;
import com.synopsys.integration.blackduck.api.generated.view.UserGroupView;
import com.synopsys.integration.blackduck.api.generated.view.UserView;
import com.synopsys.integration.blackduck.api.manual.temporary.component.UserGroupRequest;
import com.synopsys.integration.blackduck.service.BlackDuckApiClient;
import com.synopsys.integration.blackduck.service.DataService;
import com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest;
import com.synopsys.integration.exception.IntegrationException;
import com.synopsys.integration.log.IntLogger;
import com.synopsys.integration.rest.HttpUrl;
Expand Down Expand Up @@ -116,6 +119,20 @@ public List<RoleAssignmentView> getAllRolesForUser(UserView userView) throws Int
return new ArrayList(roleSet);
}

public List<RoleAssignmentView> getServerRolesForUser(UserView userView) throws IntegrationException {
BlackDuckRequestBuilder blackDuckRequestBuilder = new BlackDuckRequestBuilder()
.commonGet()
.addBlackDuckFilter(RoleService.createScopeFilter(
RoleService.SERVER_SCOPE
));

BlackDuckMultipleRequest<RoleAssignmentView> requestMultiple = blackDuckRequestBuilder.buildBlackDuckRequest(
userView.metaRolesLink()
);

return blackDuckApiClient.getAllResponses(requestMultiple);
}

public Optional<UserGroupView> getGroupByName(String groupName) throws IntegrationException {
List<UserGroupView> allGroups = blackDuckApiClient.getAllResponses(apiDiscovery.metaUsergroupsLink());
for (UserGroupView group : allGroups) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public void getRolesForUserTestIT() throws IllegalArgumentException, Integration
assertTrue(rolesForUser.size() > 0);
}

@Test
public void getServerRolesForUserTestIT() throws IntegrationException {
UserGroupService service = blackDuckServicesFactory.createUserGroupService();
String username = UserServiceTestIT.INT_HTTP_CLIENT_TEST_HELPER.getTestUsername();

UserView userView = service.getUserByUsername(username).get();

assertNotNull(userView);

List<RoleAssignmentView> serverRolesForUser = service.getServerRolesForUser(userView);
assertTrue(serverRolesForUser.size() > 0);
}

@Test
public void testAddingGroupToProject() throws IntegrationException {
String userGroupName = "user-group-test" + System.currentTimeMillis();
Expand Down

0 comments on commit e7f9d26

Please sign in to comment.