Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

EnableSupportAction.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program 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. * This program 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.organization.ws;
  21. import org.sonar.api.server.ws.Change;
  22. import org.sonar.api.server.ws.Request;
  23. import org.sonar.api.server.ws.Response;
  24. import org.sonar.api.server.ws.WebService;
  25. import org.sonar.db.permission.OrganizationPermission;
  26. import org.sonar.server.organization.DefaultOrganizationProvider;
  27. import org.sonar.server.organization.OrganisationSupport;
  28. import org.sonar.server.user.UserSession;
  29. import static java.util.Objects.requireNonNull;
  30. public class EnableSupportAction implements OrganizationsWsAction {
  31. private static final String ACTION = "enable_support";
  32. private final UserSession userSession;
  33. private final DefaultOrganizationProvider defaultOrganizationProvider;
  34. private final OrganisationSupport organisationSupport;
  35. public EnableSupportAction(UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider, OrganisationSupport organisationSupport) {
  36. this.userSession = userSession;
  37. this.defaultOrganizationProvider = defaultOrganizationProvider;
  38. this.organisationSupport = organisationSupport;
  39. }
  40. @Override
  41. public void define(WebService.NewController context) {
  42. context.createAction(ACTION)
  43. .setPost(true)
  44. .setDescription("Enable support of organizations.<br />" +
  45. "'Administer System' permission is required. The logged-in user will be flagged as root and will be able to manage organizations and other root users.")
  46. .setInternal(true)
  47. .setPost(true)
  48. .setSince("6.3")
  49. .setChangelog(new Change("6.4", "Create default 'Members' group"))
  50. .setHandler(this);
  51. }
  52. @Override
  53. public void handle(Request request, Response response) throws Exception {
  54. verifySystemAdministrator();
  55. organisationSupport.enable(requireNonNull(userSession.getLogin()));
  56. response.noContent();
  57. }
  58. private void verifySystemAdministrator() {
  59. userSession.checkLoggedIn().checkPermission(OrganizationPermission.ADMINISTER, defaultOrganizationProvider.get().getUuid());
  60. }
  61. }