import org.sonar.db.component.ResourceDto;
import org.sonar.db.permission.PermissionRepository;
import org.sonar.db.permission.template.PermissionTemplateDto;
-import org.sonar.server.component.ComponentFinder;
import org.sonar.server.permission.index.PermissionIndexer;
import org.sonar.server.user.UserSession;
import static java.util.Arrays.asList;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey;
+import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
@ServerSide
public class PermissionService {
private final PermissionRepository permissionRepository;
private final PermissionIndexer permissionIndexer;
private final UserSession userSession;
- private final ComponentFinder componentFinder;
- public PermissionService(DbClient dbClient, PermissionRepository permissionRepository, PermissionIndexer permissionIndexer, UserSession userSession,
- ComponentFinder componentFinder) {
+ public PermissionService(DbClient dbClient, PermissionRepository permissionRepository, PermissionIndexer permissionIndexer, UserSession userSession) {
this.dbClient = dbClient;
this.permissionRepository = permissionRepository;
this.permissionIndexer = permissionIndexer;
this.userSession = userSession;
- this.componentFinder = componentFinder;
}
public void applyDefaultPermissionTemplate(String componentKey) {
*/
@Deprecated
public void applyDefaultPermissionTemplate(DbSession session, String componentKey) {
- ComponentDto component = componentFinder.getByKey(session, componentKey);
+ ComponentDto component = checkFoundWithOptional(dbClient.componentDao().selectByKey(session, componentKey), "Component key '%s' not found", componentKey);
ResourceDto provisioned = dbClient.resourceDao().selectProvisionedProject(session, componentKey);
if (provisioned == null) {
checkProjectAdminUserByComponentKey(userSession, componentKey);
@Override
protected ApplyTemplateAction buildWsAction() {
PermissionRepository repository = new PermissionRepository(db.getDbClient(), new MapSettings());
- ComponentFinder componentFinder = new ComponentFinder(db.getDbClient());
- PermissionService permissionService = new PermissionService(db.getDbClient(), repository, permissionIndexer, userSession, componentFinder);
+ PermissionService permissionService = new PermissionService(db.getDbClient(), repository, permissionIndexer, userSession);
return new ApplyTemplateAction(db.getDbClient(), userSession, permissionService, newPermissionWsSupport());
}
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
-import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.i18n.I18nRule;
@Override
protected BulkApplyTemplateAction buildWsAction() {
PermissionRepository repository = new PermissionRepository(db.getDbClient(), new MapSettings());
- ComponentFinder componentFinder = new ComponentFinder(db.getDbClient());
- PermissionService permissionService = new PermissionService(db.getDbClient(), repository, issuePermissionIndexer, userSession, componentFinder);
+ PermissionService permissionService = new PermissionService(db.getDbClient(), repository, issuePermissionIndexer, userSession);
return new BulkApplyTemplateAction(db.getDbClient(), userSession, permissionService, newPermissionWsSupport(), new I18nRule(), newRootResourceTypes());
}