You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplyPermissionsStep.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.computation.step;
  21. import org.sonar.api.resources.Qualifiers;
  22. import org.sonar.db.permission.PermissionFacade;
  23. import org.sonar.db.DbSession;
  24. import org.sonar.db.MyBatis;
  25. import org.sonar.server.computation.component.DbIdsRepository;
  26. import org.sonar.server.computation.component.TreeRootHolder;
  27. import org.sonar.server.db.DbClient;
  28. import org.sonar.server.issue.index.IssueAuthorizationIndexer;
  29. /**
  30. * Apply default permissions on new projects and index issues/authorization
  31. */
  32. public class ApplyPermissionsStep implements ComputationStep {
  33. private final DbClient dbClient;
  34. private final DbIdsRepository dbIdsRepository;
  35. private final IssueAuthorizationIndexer indexer;
  36. private final PermissionFacade permissionFacade;
  37. private final TreeRootHolder treeRootHolder;
  38. public ApplyPermissionsStep(DbClient dbClient, DbIdsRepository dbIdsRepository, IssueAuthorizationIndexer indexer,
  39. PermissionFacade permissionFacade, TreeRootHolder treeRootHolder) {
  40. this.dbClient = dbClient;
  41. this.dbIdsRepository = dbIdsRepository;
  42. this.indexer = indexer;
  43. this.permissionFacade = permissionFacade;
  44. this.treeRootHolder = treeRootHolder;
  45. }
  46. @Override
  47. public void execute() {
  48. DbSession session = dbClient.openSession(false);
  49. try {
  50. long projectId = dbIdsRepository.getComponentId(treeRootHolder.getRoot());
  51. if (permissionFacade.countComponentPermissions(session, projectId) == 0) {
  52. permissionFacade.grantDefaultRoles(session, projectId, Qualifiers.PROJECT);
  53. session.commit();
  54. }
  55. // As batch is still apply permission on project, indexing of issue authorization must always been done
  56. indexer.index();
  57. } finally {
  58. MyBatis.closeQuietly(session);
  59. }
  60. }
  61. @Override
  62. public String getDescription() {
  63. return "Apply project permissions";
  64. }
  65. }