Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-9018 Create a "members" group when creating an organization
- Loading branch information
1 parent
1e7edfd
commit e8a1a4d
Showing
11 changed files
with
335 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
server/sonar-server/src/main/java/org/sonar/server/usergroups/DefaultGroupCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2017 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package org.sonar.server.usergroups; | ||
|
||
import org.sonar.db.DbSession; | ||
import org.sonar.db.user.GroupDto; | ||
|
||
public interface DefaultGroupCreator { | ||
|
||
/** | ||
* Create the default group on the given organization | ||
*/ | ||
GroupDto create(DbSession dbSession, String organizationUuid); | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
server/sonar-server/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2017 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package org.sonar.server.usergroups; | ||
|
||
import java.util.Optional; | ||
import org.sonar.db.DbClient; | ||
import org.sonar.db.DbSession; | ||
import org.sonar.db.user.GroupDto; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
public class DefaultGroupCreatorImpl implements DefaultGroupCreator { | ||
|
||
static final String DEFAULT_GROUP_NAME = "Members"; | ||
private final DbClient dbClient; | ||
|
||
public DefaultGroupCreatorImpl(DbClient dbClient) { | ||
this.dbClient = dbClient; | ||
} | ||
|
||
public GroupDto create(DbSession dbSession, String organizationUuid) { | ||
Optional<GroupDto> existingMembersGroup = dbClient.groupDao().selectByName(dbSession, organizationUuid, DEFAULT_GROUP_NAME); | ||
checkArgument(!existingMembersGroup.isPresent(), "The group '%s' already exist on organization '%s'", DEFAULT_GROUP_NAME, organizationUuid); | ||
|
||
GroupDto defaultGroup = new GroupDto() | ||
.setName(DEFAULT_GROUP_NAME) | ||
.setDescription("All members of the organization") | ||
.setOrganizationUuid(organizationUuid); | ||
dbClient.groupDao().insert(dbSession, defaultGroup); | ||
dbClient.organizationDao().setDefaultGroupId(dbSession, organizationUuid, defaultGroup); | ||
return defaultGroup; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
server/sonar-server/src/main/java/org/sonar/server/usergroups/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2017 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package org.sonar.server.usergroups; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
Oops, something went wrong.