try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION));
QProfileDto profile = wsSupport.getProfile(dbSession, organization, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE));
- wsSupport.checkCanEdit(dbSession, profile);
+ wsSupport.checkCanEdit(dbSession, organization, profile);
GroupDto user = wsSupport.getGroup(dbSession, organization, request.mandatoryParam(PARAM_GROUP));
addGroup(dbSession, profile, user);
}
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION));
QProfileDto profile = wsSupport.getProfile(dbSession, organization, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE));
- wsSupport.checkCanEdit(dbSession, profile);
+ wsSupport.checkCanEdit(dbSession, organization, profile);
UserDto user = wsSupport.getUser(dbSession, organization, request.mandatoryParam(PARAM_LOGIN));
addUser(dbSession, profile, user);
}
userSession.checkPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
}
- public void checkCanEdit(DbSession dbSession, QProfileDto profile) {
+ public void checkCanEdit(DbSession dbSession, OrganizationDto organization, QProfileDto profile) {
checkNotBuiltInt(profile);
- OrganizationDto organization = getOrganization(dbSession, profile);
userSession.checkLoggedIn();
if (userSession.hasPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization)) {
return;
}
UserDto user = dbClient.userDao().selectByLogin(dbSession, userSession.getLogin());
checkState(user != null, "User from session does not exist");
- if (dbClient.qProfileEditUsersDao().exists(dbSession, profile, user)) {
+ if (dbClient.qProfileEditUsersDao().exists(dbSession, profile, user)
+ || dbClient.qProfileEditGroupsDao().selectQProfileUuidsByOrganizationAndGroups(dbSession, organization, userSession.getGroups()).contains(profile.getKee())) {
return;
}
+
throw insufficientPrivilegesException();
}
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION));
QProfileDto profile = wsSupport.getProfile(dbSession, organization, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE));
- wsSupport.checkCanEdit(dbSession, profile);
+ wsSupport.checkCanEdit(dbSession, organization, profile);
GroupDto group = wsSupport.getGroup(dbSession, organization, request.mandatoryParam(PARAM_GROUP));
removeGroup(dbSession, profile, group);
}
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION));
QProfileDto profile = wsSupport.getProfile(dbSession, organization, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE));
- wsSupport.checkCanEdit(dbSession, profile);
+ wsSupport.checkCanEdit(dbSession, organization, profile);
UserDto user = wsSupport.getUser(dbSession, organization, request.mandatoryParam(PARAM_LOGIN));
removeUser(dbSession, profile, user);
}
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, wsRequest.getOrganization());
QProfileDto profile = wsSupport.getProfile(dbSession, organization, wsRequest.getQualityProfile(), wsRequest.getLanguage());
- wsSupport.checkCanEdit(dbSession, profile);
+ wsSupport.checkCanEdit(dbSession, organization, profile);
SearchGroupsQuery query = builder()
.setOrganization(organization)
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, wsRequest.getOrganization());
QProfileDto profile = wsSupport.getProfile(dbSession, organization, wsRequest.getQualityProfile(), wsRequest.getLanguage());
- wsSupport.checkCanEdit(dbSession, profile);
+ wsSupport.checkCanEdit(dbSession, organization, profile);
SearchUsersQuery query = builder()
.setOrganization(organization)
}
@Test
- public void qp_editors_can_add_group() {
+ public void can_add_group_with_user_edit_permission() {
OrganizationDto organization = db.organizations().insert();
QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(XOO));
GroupDto group = db.users().insertGroup(organization);
assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isTrue();
}
+ @Test
+ public void can_add_group_with_group_edit_permission() {
+ OrganizationDto organization = db.organizations().insert();
+ QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(XOO));
+ GroupDto group = db.users().insertGroup(organization);
+ UserDto userAllowedToEditProfile = db.users().insertUser();
+ db.qualityProfiles().addGroupPermission(profile, group);
+ userSession.logIn(userAllowedToEditProfile).setGroups(group);
+
+ ws.newRequest()
+ .setParam(PARAM_QUALITY_PROFILE, profile.getName())
+ .setParam(PARAM_LANGUAGE, XOO)
+ .setParam(PARAM_GROUP, group.getName())
+ .setParam(PARAM_ORGANIZATION, organization.getKey())
+ .execute();
+
+ assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isTrue();
+ }
+
@Test
public void uses_default_organization_when_no_organization() {
OrganizationDto organization = db.getDefaultOrganization();