@Test
public void return_project_settings() {
ComponentDto project = db.components().insertPrivateProject();
- db.properties().insertProperties(
+ db.properties().insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("1").setValue("val1"),
newComponentPropertyDto(project).setKey("2").setValue("val2"),
newComponentPropertyDto(project).setKey("3").setValue("val3"));
public void project_settings_override_global_settings() {
settings.setProperty("key", "value");
ComponentDto project = db.components().insertPrivateProject();
- db.properties().insertProperties(newComponentPropertyDto(project).setKey("key").setValue("value2"));
+ db.properties().insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("key").setValue("value2"));
Configuration projectConfig = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl());
}
private void insertProjectProperty(ComponentDto project, String propertyKey, String propertyValue) {
- db.properties().insertProperties(new PropertyDto().setKey(propertyKey).setValue(propertyValue).setComponentUuid(project.uuid()));
+ db.properties().insertProperties(null, project.name(),
+ new PropertyDto().setKey(propertyKey).setValue(propertyValue).setComponentUuid(project.uuid()));
}
}
package org.sonar.ce.db;
import java.util.Map;
+import javax.annotation.Nullable;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbSession;
}
@Override
- public void saveProperty(DbSession session, PropertyDto property) {
+ public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin,
+ @Nullable String projectName) {
// do nothing
}
}
@Override
- public void deleteProjectProperty(String key, String projectUuid) {
+ public void deleteProjectProperty(String key, String projectUuid, String projectName) {
// do nothing
}
@Override
- public void deleteProjectProperty(String key, String projectUuid, DbSession session) {
+ public void deleteProjectProperty(String key, String projectUuid, DbSession session, String projectName) {
// do nothing
}
private void insertProperty(String key, String value) {
PropertyDto dto = new PropertyDto().setKey(key).setValue(value);
- db.getDbClient().propertiesDao().saveProperty(db.getSession(), dto);
+ db.getDbClient().propertiesDao().saveProperty(db.getSession(), dto, null, null);
db.commit();
}
@Test
public void insertProperty() {
- underTest.saveProperty(dbSession, propertyDto);
+ underTest.saveProperty(dbSession, propertyDto, null, null);
assertNoInteraction();
}
@Test
public void deleteProjectProperty() {
- underTest.deleteProjectProperty(null, null);
+ underTest.deleteProjectProperty(null, null, null);
assertNoInteraction();
@Test
public void deleteProjectProperty1() {
- underTest.deleteProjectProperty(null, null, dbSession);
+ underTest.deleteProjectProperty(null, null, dbSession, null);
assertNoInteraction();
package org.sonar.db.alm.pat;
import java.util.Optional;
+import javax.annotation.Nullable;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PersonalAccessTokenNewValue;
import org.sonar.db.user.UserDto;
public class AlmPatDao implements Dao {
private final System2 system2;
private final UuidFactory uuidFactory;
+ private AuditPersister auditPersister;
public AlmPatDao(System2 system2, UuidFactory uuidFactory) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
}
+ public AlmPatDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
+ this.system2 = system2;
+ this.uuidFactory = uuidFactory;
+ this.auditPersister = auditPersister;
+ }
+
private static AlmPatMapper getMapper(DbSession dbSession) {
return dbSession.getMapper(AlmPatMapper.class);
}
return Optional.ofNullable(getMapper(dbSession).selectByUserAndAlmSetting(userUuid, almSettingDto.getUuid()));
}
- public void insert(DbSession dbSession, AlmPatDto almPatDto) {
+ public void insert(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
String uuid = uuidFactory.create();
long now = system2.now();
almPatDto.setUuid(uuid);
almPatDto.setCreatedAt(now);
almPatDto.setUpdatedAt(now);
getMapper(dbSession).insert(almPatDto);
+
+ if (auditPersister != null) {
+ auditPersister.addPersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
+ }
}
- public void update(DbSession dbSession, AlmPatDto almPatDto) {
+ public void update(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
long now = system2.now();
almPatDto.setUpdatedAt(now);
getMapper(dbSession).update(almPatDto);
+ if (auditPersister != null) {
+ auditPersister.updatePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
+ }
}
- public void delete(DbSession dbSession, AlmPatDto almPatDto) {
+ public void delete(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
getMapper(dbSession).deleteByUuid(almPatDto.getUuid());
+ if (auditPersister != null) {
+ auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
+ }
}
public void deleteByUser(DbSession dbSession, UserDto user) {
getMapper(dbSession).deleteByUser(user.getUuid());
+ if (auditPersister != null) {
+ auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(user));
+ }
}
public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
getMapper(dbSession).deleteByAlmSetting(almSetting.getUuid());
+ if (auditPersister != null) {
+ auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almSetting));
+ }
}
-
}
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
public class AlmSettingDao implements Dao {
private final System2 system2;
private final UuidFactory uuidFactory;
+ private AuditPersister auditPersister;
+
public AlmSettingDao(System2 system2, UuidFactory uuidFactory) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
}
+ public AlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
+ this(system2, uuidFactory);
+ this.auditPersister = auditPersister;
+ }
+
private static AlmSettingMapper getMapper(DbSession dbSession) {
return dbSession.getMapper(AlmSettingMapper.class);
}
almSettingDto.setCreatedAt(now);
almSettingDto.setUpdatedAt(now);
getMapper(dbSession).insert(almSettingDto);
+
+ if (auditPersister != null) {
+ auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(),
+ almSettingDto.getKey()));
+ }
}
public Optional<AlmSettingDto> selectByUuid(DbSession dbSession, String uuid) {
public void delete(DbSession dbSession, AlmSettingDto almSettingDto) {
getMapper(dbSession).deleteByKey(almSettingDto.getKey());
+
+ if (auditPersister != null) {
+ auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(),
+ almSettingDto.getKey()));
+ }
}
public void update(DbSession dbSession, AlmSettingDto almSettingDto) {
long now = system2.now();
almSettingDto.setUpdatedAt(now);
getMapper(dbSession).update(almSettingDto);
+
+ if (auditPersister != null) {
+ auditPersister.updateDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto));
+ }
}
}
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
import org.sonar.db.project.ProjectDto;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
private final System2 system2;
private final UuidFactory uuidFactory;
+ private AuditPersister auditPersister;
public ProjectAlmSettingDao(System2 system2, UuidFactory uuidFactory) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
}
- public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto) {
+ public ProjectAlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
+ this(system2, uuidFactory);
+ this.auditPersister = auditPersister;
+ }
+
+ public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto,
+ String key, String projectName) {
String uuid = uuidFactory.create();
long now = system2.now();
ProjectAlmSettingMapper mapper = getMapper(dbSession);
+ boolean isUpdate = true;
if (mapper.update(projectAlmSettingDto, now) == 0) {
mapper.insert(projectAlmSettingDto, uuid, now);
projectAlmSettingDto.setUuid(uuid);
projectAlmSettingDto.setCreatedAt(now);
+ isUpdate = false;
}
projectAlmSettingDto.setUpdatedAt(now);
+
+ if (auditPersister != null) {
+ if (isUpdate) {
+ auditPersister.updateDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key, projectName));
+ } else {
+ auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(projectAlmSettingDto.getAlmSettingUuid(),
+ projectAlmSettingDto.getProjectUuid(), key, projectName));
+ }
+ }
}
public void deleteByProject(DbSession dbSession, ProjectDto project) {
getMapper(dbSession).deleteByProjectUuid(project.getUuid());
+
+ if (auditPersister != null) {
+ auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(project));
+ }
}
public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
+ deleteByAlmSetting(dbSession, almSetting, false);
+ }
+
+ public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting, boolean track) {
getMapper(dbSession).deleteByAlmSettingUuid(almSetting.getUuid());
+
+ if (track && auditPersister != null) {
+ auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSetting.getUuid(),
+ almSetting.getKey()));
+ }
}
public int countByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
void deleteUserFromGroup(DbSession dbSession, NewValue newValue);
- void addUserProperty(DbSession dbSession, NewValue newValue);
+ void addProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
- void updateUserProperty(DbSession dbSession, NewValue newValue);
+ void updateProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
- void deleteUserProperty(DbSession dbSession, NewValue newValue);
+ void deleteProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
void addUserToken(DbSession dbSession, NewValue newValue);
void deleteUserToken(DbSession dbSession, NewValue newValue);
+ void addGroupPermission(DbSession dbSession, NewValue newValue);
+
+ void deleteGroupPermission(DbSession dbSession, NewValue newValue);
+
+ void addUserPermission(DbSession dbSession, NewValue newValue);
+
+ void deleteUserPermission(DbSession dbSession, NewValue newValue);
+
+ void addPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void updatePermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void deletePermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void addUserToPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void deleteUserFromPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void addGroupToPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void deleteGroupFromPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void addCharacteristicToPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void updateCharacteristicInPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+ void addPlugin(DbSession dbSession, NewValue newValue);
+
+ void updatePlugin(DbSession dbSession, NewValue newValue);
+
+ void generateSecretKey(DbSession dbSession);
+
+ void setLicense(DbSession dbSession, boolean isSet, NewValue newValue);
+
+ void addWebhook(DbSession dbSession, NewValue newValue);
+
+ void updateWebhook(DbSession dbSession, NewValue newValue);
+
+ void deleteWebhook(DbSession dbSession, NewValue newValue);
+
+ void addDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+
+ void updateDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+
+ void deleteDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+
+ void addPersonalAccessToken(DbSession dbSession, NewValue newValue);
+
+ void updatePersonalAccessToken(DbSession dbSession, NewValue newValue);
+
+ void deletePersonalAccessToken(DbSession dbSession, NewValue newValue);
+
boolean isTrackedProperty(String propertyKey);
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.ObjectUtils;
+import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.alm.setting.ProjectAlmSettingDto;
+import org.sonar.db.project.ProjectDto;
+
+public class DevOpsPlatformSettingNewValue implements NewValue {
+ @Nullable
+ private String devOpsPlatformSettingUuid;
+
+ @Nullable
+ private String key;
+
+ @Nullable
+ private String devOpsPlatformName;
+
+ @Nullable
+ private String url;
+
+ @Nullable
+ private String appId;
+
+ @Nullable
+ private String clientId;
+
+ @Nullable
+ private String projectUuid;
+
+ @Nullable
+ private String projectName;
+
+ @Nullable
+ private String almRepo;
+
+ @Nullable
+ private String almSlug;
+
+ @Nullable
+ private Boolean isSummaryCommentEnabled;
+
+ @Nullable
+ private Boolean isMonorepo;
+
+ public DevOpsPlatformSettingNewValue(String devOpsPlatformSettingUuid, String key) {
+ this.devOpsPlatformSettingUuid = devOpsPlatformSettingUuid;
+ this.key = key;
+ }
+
+ public DevOpsPlatformSettingNewValue(AlmSettingDto dto) {
+ this.devOpsPlatformSettingUuid = dto.getUuid();
+ this.key = dto.getKey();
+ this.devOpsPlatformName = dto.getAppId();
+ this.url = dto.getUrl();
+ this.appId = dto.getAppId();
+ this.clientId = dto.getClientId();
+ }
+
+ public DevOpsPlatformSettingNewValue(ProjectAlmSettingDto dto, String key, String projectName) {
+ this.devOpsPlatformSettingUuid = dto.getAlmSettingUuid();
+ this.key = key;
+ this.projectUuid = dto.getProjectUuid();
+ this.projectName = projectName;
+ this.almRepo = dto.getAlmRepo();
+ this.almSlug = dto.getAlmSlug();
+ this.isSummaryCommentEnabled = dto.getSummaryCommentEnabled();
+ this.isMonorepo = dto.getMonorepo();
+ }
+
+ public DevOpsPlatformSettingNewValue(String devOpsPlatformSettingUuid, String projectUuid, String key, String projectName) {
+ this.devOpsPlatformSettingUuid = devOpsPlatformSettingUuid;
+ this.key = key;
+ this.projectUuid = projectUuid;
+ this.projectName = projectName;
+ }
+
+ public DevOpsPlatformSettingNewValue(ProjectDto projectDto) {
+ this.projectUuid = projectDto.getUuid();
+ this.projectName = projectDto.getName();
+ }
+
+ @CheckForNull
+ public String getDevOpsPlatformSettingUuid() {
+ return this.devOpsPlatformSettingUuid;
+ }
+
+ @CheckForNull
+ public String getKey() {
+ return this.key;
+ }
+
+ @CheckForNull
+ public String getDevOpsPlatformName() {
+ return this.devOpsPlatformName;
+ }
+
+ @CheckForNull
+ public String getUrl() {
+ return this.url;
+ }
+
+ @CheckForNull
+ public String getAppId() {
+ return this.appId;
+ }
+
+ @CheckForNull
+ public String getClientId() {
+ return this.clientId;
+ }
+
+ @CheckForNull
+ public String getProjectUuid() {
+ return this.projectUuid;
+ }
+
+ @CheckForNull
+ public String getProjectName() {
+ return this.projectName;
+ }
+
+ @CheckForNull
+ public String getAlmRepo() {
+ return this.almRepo;
+ }
+
+ @CheckForNull
+ public String getAlmSlug() {
+ return this.almSlug;
+ }
+
+ @CheckForNull
+ public Boolean isSummaryCommentEnabled() {
+ return this.isSummaryCommentEnabled;
+ }
+
+ @CheckForNull
+ public Boolean isMonorepo() {
+ return this.isMonorepo;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ addField(sb, "\"devOpsPlatformSettingUuid\": ", this.devOpsPlatformSettingUuid, true);
+ addField(sb, "\"key\": ", this.key, true);
+ addField(sb, "\"devOpsPlatformName\": ", this.devOpsPlatformName, true);
+ addField(sb, "\"url\": ", this.url, true);
+ addField(sb, "\"appId\": ", this.appId, true);
+ addField(sb, "\"clientId\": ", this.clientId, true);
+ addField(sb, "\"projectUuid\": ", this.projectUuid, true);
+ addField(sb, "\"projectName\": ", this.projectName, true);
+ addField(sb, "\"almRepo\": ", this.almRepo, true);
+ addField(sb, "\"almSlug\": ", this.almSlug, true);
+ addField(sb, "\"isSummaryCommentEnabled\": ", ObjectUtils.toString(this.isSummaryCommentEnabled), false);
+ addField(sb, "\"isMonorepo\": ", ObjectUtils.toString(this.isMonorepo), false);
+ endString(sb);
+ return sb.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class LicenseNewValue implements NewValue {
+ @Nullable
+ private String edition;
+
+ public LicenseNewValue(@Nullable String edition) {
+ this.edition = edition;
+ }
+
+ @CheckForNull
+ public String getEdition() {
+ return this.edition;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ addField(sb, "\"edition\": ", this.edition, true);
+ endString(sb);
+ return sb.toString();
+ }
+}
addQuote(sb, isString);
sb.append(value);
addQuote(sb, isString);
- sb.append(",");
+ sb.append(", ");
}
}
+ default void endString(StringBuilder sb) {
+ int length = sb.length();
+ if(sb.length() > 1) {
+ sb.delete(length - 2, length - 1);
+ }
+ sb.append("}");
+ }
+
private static void addQuote(StringBuilder sb, boolean isString) {
if(isString) {
- sb.append("'");
+ sb.append("\"");
}
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.permission.GroupPermissionDto;
+import org.sonar.db.permission.UserPermissionDto;
+
+public class PermissionNewValue implements NewValue {
+ @Nullable
+ private String permissionUuid;
+
+ @Nullable
+ private String groupUuid;
+
+ @Nullable
+ private String userUuid;
+
+ @Nullable
+ private String projectUuid;
+
+ @Nullable
+ private String projectName;
+
+ @Nullable
+ private String role;
+
+ public PermissionNewValue(GroupPermissionDto groupPermissionDto, String projectName) {
+ this.permissionUuid = groupPermissionDto.getUuid();
+ this.groupUuid = groupPermissionDto.getGroupUuid();
+ this.projectUuid = groupPermissionDto.getComponentUuid();
+ this.role = groupPermissionDto.getRole();
+ this.projectName = projectName;
+ }
+
+ public PermissionNewValue(UserPermissionDto permissionDto, @Nullable String projectName) {
+ this.permissionUuid = permissionDto.getUuid();
+ this.userUuid = permissionDto.getUserUuid();
+ this.projectUuid = permissionDto.getComponentUuid();
+ this.role = permissionDto.getPermission();
+ this.projectName = projectName;
+ }
+
+ public PermissionNewValue(@Nullable String role, @Nullable String groupUuid, @Nullable String rootComponentUuid,
+ @Nullable String projectName, @Nullable String userUuid) {
+ this.role = role;
+ this.groupUuid = groupUuid;
+ this.projectUuid = rootComponentUuid;
+ this.projectName = projectName;
+ this.userUuid = userUuid;
+ }
+
+ @CheckForNull
+ public String getPermissionUuid() {
+ return this.permissionUuid;
+ }
+
+ @CheckForNull
+ public String getGroupUuid() {
+ return this.groupUuid;
+ }
+
+ @CheckForNull
+ public String getProjectUuid() {
+ return this.projectUuid;
+ }
+
+ @CheckForNull
+ public String getRole() {
+ return this.role;
+ }
+
+ @CheckForNull
+ public String getProjectName() {
+ return this.projectName;
+ }
+
+ @CheckForNull
+ public String getUserUuid() {
+ return this.userUuid;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ addField(sb, "\"permissionUuid\": ", this.permissionUuid, true);
+ addField(sb, "\"groupUuid\": ", this.groupUuid, true);
+ addField(sb, "\"projectUuid\": ", this.projectUuid, true);
+ addField(sb, "\"role\": ", this.role, true);
+ addField(sb, "\"projectName\": ", this.projectName, true);
+ addField(sb, "\"userUuid\": ", this.userUuid, true);
+ endString(sb);
+ return sb.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.ObjectUtils;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+
+public class PermissionTemplateNewValue implements NewValue {
+ private String templateUuid;
+ private String name;
+
+ @Nullable
+ private String keyPattern;
+
+ @Nullable
+ private String description;
+
+ @Nullable
+ private String role;
+
+ @Nullable
+ private String userUuid;
+
+ @Nullable
+ private String userLogin;
+
+ @Nullable
+ private String groupUuid;
+
+ @Nullable
+ private String groupName;
+
+ @Nullable
+ private Boolean withProjectCreator;
+
+ public PermissionTemplateNewValue(String templateUuid, String name) {
+ this.templateUuid = templateUuid;
+ this.name = name;
+ }
+
+ public PermissionTemplateNewValue(PermissionTemplateDto permissionTemplateDto) {
+ this.templateUuid = permissionTemplateDto.getUuid();
+ this.name = permissionTemplateDto.getName();
+ this.keyPattern = permissionTemplateDto.getKeyPattern();
+ this.description = permissionTemplateDto.getDescription();
+ }
+
+ public PermissionTemplateNewValue(@Nullable String templateUuid, @Nullable String name, @Nullable String role,
+ @Nullable String userUuid, @Nullable String userLogin, @Nullable String groupUuid, @Nullable String groupName) {
+ this.templateUuid = templateUuid;
+ this.name = name;
+ this.role = role;
+ this.userUuid = userUuid;
+ this.userLogin = userLogin;
+ this.groupUuid = groupUuid;
+ this.groupName = groupName;
+ }
+
+ public PermissionTemplateNewValue(String templateUuid, String role, String name, boolean withProjectCreator) {
+ this.templateUuid = templateUuid;
+ this.name = name;
+ this.role = role;
+ this.withProjectCreator = withProjectCreator;
+ }
+
+ public String getTemplateUuid() {
+ return this.templateUuid;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ @CheckForNull
+ public String getKeyPattern() {
+ return this.keyPattern;
+ }
+
+ @CheckForNull
+ public String getDescription() {
+ return this.description;
+ }
+
+ @CheckForNull
+ public String getRole() {
+ return this.role;
+ }
+
+ @CheckForNull
+ public String getUserUuid() {
+ return this.userUuid;
+ }
+
+ @CheckForNull
+ public String getUserLogin() {
+ return this.userLogin;
+ }
+
+ @CheckForNull
+ public String getGroupUuid() {
+ return this.groupUuid;
+ }
+
+ @CheckForNull
+ public String getGroupName() {
+ return this.groupName;
+ }
+
+ @CheckForNull
+ public Boolean isWithProjectCreator() {
+ return this.withProjectCreator;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ addField(sb, "\"templateUuid\": ", this.templateUuid, true);
+ addField(sb, "\"name\": ", this.name, true);
+ addField(sb, "\"keyPattern\": ", this.keyPattern, true);
+ addField(sb, "\"description\": ", this.description, true);
+ addField(sb, "\"role\": ", this.role, true);
+ addField(sb, "\"userUuid\": ", this.userUuid, true);
+ addField(sb, "\"userLogin\": ", this.userLogin, true);
+ addField(sb, "\"groupUuid\": ", this.groupUuid, true);
+ addField(sb, "\"groupName\": ", this.groupName, true);
+ addField(sb, "\"withProjectCreator\": ", ObjectUtils.toString(this.withProjectCreator), false);
+ endString(sb);
+ return sb.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.alm.pat.AlmPatDto;
+import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.user.UserDto;
+
+public class PersonalAccessTokenNewValue implements NewValue {
+ @Nullable
+ private String patUuid;
+
+ @Nullable
+ private String userUuid;
+
+ @Nullable
+ private String userLogin;
+
+ @Nullable
+ private String almSettingUuid;
+
+ @Nullable
+ private String almSettingKey;
+
+ public PersonalAccessTokenNewValue(AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
+ this.patUuid = almPatDto.getUuid();
+ this.userUuid = almPatDto.getUserUuid();
+ this.almSettingUuid = almPatDto.getAlmSettingUuid();
+ this.userLogin = userLogin;
+ this.almSettingKey = almSettingKey;
+ }
+
+ public PersonalAccessTokenNewValue(UserDto userDto) {
+ this.userUuid = userDto.getUuid();
+ this.userLogin = userDto.getLogin();
+ }
+
+ public PersonalAccessTokenNewValue(AlmSettingDto almSettingDto) {
+ this.almSettingUuid = almSettingDto.getUuid();
+ this.almSettingKey = almSettingDto.getKey();
+ }
+
+ @CheckForNull
+ public String getPatUuid() {
+ return this.patUuid;
+ }
+
+ @CheckForNull
+ public String getUserUuid() {
+ return this.userUuid;
+ }
+
+ @CheckForNull
+ public String getUserLogin() {
+ return this.userLogin;
+ }
+
+ @CheckForNull
+ public String getAlmSettingUuid() {
+ return this.almSettingUuid;
+ }
+
+ @CheckForNull
+ public String getAlmSettingKey() {
+ return this.almSettingKey;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ addField(sb, "\"patUuid\": ", this.patUuid, true);
+ addField(sb, "\"userUuid\": ", this.userUuid, true);
+ addField(sb, "\"userLogin\": ", this.userLogin, true);
+ addField(sb, "\"almSettingUuid\": ", this.almSettingUuid, true);
+ addField(sb, "\"almSettingKey\": ", this.almSettingKey, true);
+ endString(sb);
+ return sb.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import org.sonar.db.plugin.PluginDto;
+
+public class PluginNewValue implements NewValue {
+ private String pluginUuid;
+ private String kee;
+ private String basePluginKey;
+ private String type;
+
+ public PluginNewValue(PluginDto pluginDto) {
+ this.pluginUuid = pluginDto.getUuid();
+ this.kee = pluginDto.getKee();
+ this.basePluginKey = pluginDto.getBasePluginKey();
+ this.type = pluginDto.getType().name();
+ }
+
+ public String getPluginUuid() {
+ return this.pluginUuid;
+ }
+
+ public String getKee() {
+ return this.kee;
+ }
+
+ public String getBasePluginKey() {
+ return this.basePluginKey;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ addField(sb, "\"pluginUuid\": ", this.pluginUuid, true);
+ addField(sb, "\"kee\": ", this.kee, true);
+ addField(sb, "\"basePluginKey\": ", this.basePluginKey, true);
+ addField(sb, "\"type\": ", this.type, true);
+ endString(sb);
+ return sb.toString();
+ }
+}
*/
package org.sonar.db.audit.model;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.property.PropertyDto;
import org.sonar.db.user.UserPropertyDto;
public class PropertyNewValue implements NewValue {
+ @Nullable
private String propertyKey;
+
+ @Nullable
private String propertyValue;
+
+ @Nullable
private String userUuid;
+
+ @Nullable
private String userLogin;
+ @Nullable
+ private String projectUuid;
+
+ @Nullable
+ private String projectName;
+
public PropertyNewValue(UserPropertyDto userPropertyDto, String login) {
this.propertyKey = userPropertyDto.getKey();
this.userUuid = userPropertyDto.getUserUuid();
this.userLogin = login;
- if(!propertyKey.contains(".secured")) {
- this.propertyValue = userPropertyDto.getValue();
- }
+ setValue(propertyKey, userPropertyDto.getValue());
+ }
+
+ public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String projectName) {
+ this.propertyKey = propertyDto.getKey();
+ this.userUuid = propertyDto.getUserUuid();
+ this.userLogin = userLogin;
+ this.projectUuid = propertyDto.getComponentUuid();
+ this.projectName = projectName;
+
+ setValue(propertyKey, propertyDto.getValue());
+ }
+
+ public PropertyNewValue(String propertyKey) {
+ this.propertyKey = propertyKey;
+ }
+
+ public PropertyNewValue(String propertyKey, @Nullable String userUuid, String userLogin) {
+ this.propertyKey = propertyKey;
+ this.userUuid = userUuid;
+ this.userLogin = userLogin;
+ }
+
+ public PropertyNewValue(String propertyKey, String propertyValue) {
+ this.propertyKey = propertyKey;
+
+ setValue(propertyKey, propertyValue);
+ }
+
+ public PropertyNewValue(@Nullable String propertyKey, @Nullable String projectUuid,
+ @Nullable String projectName, @Nullable String userUuid) {
+ this.propertyKey = propertyKey;
+ this.projectUuid = projectUuid;
+ this.projectName = projectName;
+ this.userUuid = userUuid;
}
+ @CheckForNull
public String getPropertyKey() {
return this.propertyKey;
}
+ @CheckForNull
public String getPropertyValue() {
return this.propertyValue;
}
+ @CheckForNull
public String getUserUuid() {
return this.userUuid;
}
+ @CheckForNull
public String getUserLogin() {
return this.userLogin;
}
+ @CheckForNull
+ public String getProjectUuid() {
+ return this.projectUuid;
+ }
+
+ @CheckForNull
+ public String getProjectName() {
+ return this.projectName;
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder("{");
- addField(sb, "'propertyKey':", this.propertyKey, true);
- addField(sb, "'propertyValue':", this.propertyValue, true);
- addField(sb, "'userUuid':", this.userUuid, true);
- addField(sb, "'userLogin':", this.userLogin, true);
- sb.append("}");
+ addField(sb, "\"propertyKey\": ", this.propertyKey, true);
+ addField(sb, "\"propertyValue\": ", this.propertyValue, true);
+ addField(sb, "\"userUuid\": ", this.userUuid, true);
+ addField(sb, "\"userLogin\": ", this.userLogin, true);
+ addField(sb, "\"projectUuid\": ", this.projectUuid, true);
+ addField(sb, "\"projectName\": ", this.projectName, true);
+ endString(sb);
return sb.toString();
}
+ private void setValue(String propertyKey, String value) {
+ if (!propertyKey.contains(".secured")) {
+ this.propertyValue = value;
+ }
+ }
}
*/
package org.sonar.db.audit.model;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserGroupDto;
public class UserGroupNewValue implements NewValue {
+
+ @Nullable
private String groupUuid;
+
+ @Nullable
private String name;
+
+ @Nullable
private String description;
+
+ @Nullable
private String userUuid;
+
+ @Nullable
private String userLogin;
public UserGroupNewValue(String groupUuid, String name) {
this.userLogin = userLogin;
}
+ @CheckForNull
public String getGroupUuid() {
return this.groupUuid;
}
+ @CheckForNull
public String getName() {
return this.name;
}
+ @CheckForNull
public String getDescription() {
return this.description;
}
+ @CheckForNull
public String getUserUuid() {
return this.userUuid;
}
+ @CheckForNull
public String getUserLogin() {
return this.userLogin;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("{");
- addField(sb, "'groupUuid':", this.groupUuid, true);
- addField(sb, "'name':", this.name, true);
- addField(sb, "'description':", this.description, true);
- addField(sb, "'userUuid':", this.userUuid, true);
- addField(sb, "'userLogin':", this.userLogin, true);
- sb.append("}");
+ addField(sb, "\"groupUuid\": ", this.groupUuid, true);
+ addField(sb, "\"name\": ", this.name, true);
+ addField(sb, "\"description\": ", this.description, true);
+ addField(sb, "\"userUuid\": ", this.userUuid, true);
+ addField(sb, "\"userLogin\": ", this.userLogin, true);
+ endString(sb);
return sb.toString();
}
-
}
*/
package org.sonar.db.audit.model;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.apache.commons.lang.ObjectUtils;
import org.sonar.db.user.UserDto;
public class UserNewValue implements NewValue {
private String userUuid;
private String login;
+
+ @Nullable
private String name;
+
+ @Nullable
private String email;
+
+ @Nullable
private Boolean isActive;
+
+ @Nullable
private String scmAccounts;
+
+ @Nullable
private String externalId;
+
+ @Nullable
private String externalLogin;
+
+ @Nullable
private String externalIdentityProvider;
+
+ @Nullable
private Boolean local;
+
+ @Nullable
private Boolean onboarded;
+
+ @Nullable
private Boolean root;
+
+ @Nullable
private Long lastConnectionDate;
public UserNewValue(String userUuid, String userLogin) {
return this.login;
}
+ @CheckForNull
public String getName() {
return this.name;
}
+ @CheckForNull
public String getEmail() {
return this.email;
}
+ @CheckForNull
public boolean isActive() {
return this.isActive;
}
+ @CheckForNull
public String getScmAccounts() {
return this.scmAccounts;
}
+ @CheckForNull
public String getExternalId() {
return this.externalId;
}
+ @CheckForNull
public String getExternalLogin() {
return this.externalLogin;
}
+ @CheckForNull
public String getExternalIdentityProvider() {
return this.externalIdentityProvider;
}
+ @CheckForNull
public boolean isLocal() {
return this.local;
}
+ @CheckForNull
public boolean isOnboarded() {
return this.onboarded;
}
+ @CheckForNull
public boolean isRoot() {
return this.root;
}
+ @CheckForNull
public Long getLastConnectionDate() {
return this.lastConnectionDate;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("{");
- addField(sb, "'userUuid':", this.userUuid, true);
- addField(sb, "'login':", this.login, true);
- addField(sb, "'name':", this.name, true);
- addField(sb, "'email':", this.email, true);
- addField(sb, "'isActive':", ObjectUtils.toString(this.isActive), false);
- addField(sb, "'scmAccounts':", this.scmAccounts, true);
- addField(sb, "'externalId':", this.externalId, true);
- addField(sb, "'externalLogin':", this.externalLogin, true);
- addField(sb, "'externalIdentityProvider':", this.externalIdentityProvider, true);
- addField(sb, "'local':", ObjectUtils.toString(this.local), false);
- addField(sb, "'onboarded':", ObjectUtils.toString(this.onboarded), false);
- addField(sb, "'root':", ObjectUtils.toString(this.root), false);
- addField(sb, "'lastConnectionDate':", ObjectUtils.toString(this.lastConnectionDate), false);
- sb.append("}");
+ addField(sb, "\"userUuid\": ", this.userUuid, true);
+ addField(sb, "\"login\": ", this.login, true);
+ addField(sb, "\"name\": ", this.name, true);
+ addField(sb, "\"email\": ", this.email, true);
+ addField(sb, "\"isActive\": ", ObjectUtils.toString(this.isActive), false);
+ addField(sb, "\"scmAccounts\": ", this.scmAccounts, true);
+ addField(sb, "\"externalId\": ", this.externalId, true);
+ addField(sb, "\"externalLogin\": ", this.externalLogin, true);
+ addField(sb, "\"externalIdentityProvider\": ", this.externalIdentityProvider, true);
+ addField(sb, "\"local\": ", ObjectUtils.toString(this.local), false);
+ addField(sb, "\"onboarded\": ", ObjectUtils.toString(this.onboarded), false);
+ addField(sb, "\"root\": ", ObjectUtils.toString(this.root), false);
+ addField(sb, "\"lastConnectionDate\": ", ObjectUtils.toString(this.lastConnectionDate), false);
+ endString(sb);
return sb.toString();
}
-
}
*/
package org.sonar.db.audit.model;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.apache.commons.lang.ObjectUtils;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserTokenDto;
public class UserTokenNewValue implements NewValue {
+ @Nullable
private String tokenUuid;
+
private String userUuid;
+
+ @Nullable
private String userLogin;
+
+ @Nullable
private String tokenName;
+
+ @Nullable
private Long lastConnectionDate;
public UserTokenNewValue(UserTokenDto userTokenDto, @Nullable String userLogin) {
this.tokenName = tokenName;
}
+ @CheckForNull
public String getTokenUuid() {
return this.tokenUuid;
}
return this.userUuid;
}
+ @CheckForNull
public String getUserLogin() {
return this.userLogin;
}
+ @CheckForNull
public String getTokenName() {
return this.tokenName;
}
+ @CheckForNull
public Long getLastConnectionDate() {
return this.lastConnectionDate;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("{");
- addField(sb, "'tokenUuid':", this.tokenUuid, true);
- addField(sb, "'userUuid':", this.userUuid, true);
- addField(sb, "'userLogin':", this.userLogin, true);
- addField(sb, "'tokenName':", this.tokenName, true);
- addField(sb, "'lastConnectionDate':", ObjectUtils.toString(this.lastConnectionDate), false);
- sb.append("}");
+ addField(sb, "\"tokenUuid\": ", this.tokenUuid, true);
+ addField(sb, "\"userUuid\": ", this.userUuid, true);
+ addField(sb, "\"userLogin\": ", this.userLogin, true);
+ addField(sb, "\"tokenName\": ", this.tokenName, true);
+ addField(sb, "\"lastConnectionDate\": ", ObjectUtils.toString(this.lastConnectionDate), false);
+ endString(sb);
return sb.toString();
}
-
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.project.ProjectDto;
+import org.sonar.db.webhook.WebhookDto;
+
+public class WebhookNewValue implements NewValue {
+ @Nullable
+ private String webhookUuid;
+
+ @Nullable
+ private String name;
+
+ @Nullable
+ private String url;
+
+ @Nullable
+ private String projectUuid;
+
+ @Nullable
+ private String projectName;
+
+ public WebhookNewValue(WebhookDto dto, @Nullable String projectName) {
+ this.webhookUuid = dto.getUuid();
+ this.name = dto.getName();
+ this.url = dto.getUrl();
+ this.projectUuid = dto.getProjectUuid();
+ this.projectName = projectName;
+ }
+
+ public WebhookNewValue(String webhookUuid, String webhookName) {
+ this.webhookUuid = webhookUuid;
+ this.name = webhookName;
+ }
+
+ public WebhookNewValue(String webhookUuid, String webhookName, @Nullable String projectUuid, @Nullable String projectName) {
+ this(webhookUuid, webhookName);
+ this.projectUuid = projectUuid;
+ this.projectName = projectName;
+ }
+
+ public WebhookNewValue(ProjectDto projectDto) {
+ this.projectUuid = projectDto.getUuid();
+ this.projectName = projectDto.getName();
+ }
+
+ @CheckForNull
+ public String getWebhookUuid() {
+ return this.webhookUuid;
+ }
+
+ @CheckForNull
+ public String getName() {
+ return this.name;
+ }
+
+ @CheckForNull
+ public String getUrl() {
+ return this.url;
+ }
+
+ @CheckForNull
+ public String getProjectUuid() {
+ return this.projectUuid;
+ }
+
+ @CheckForNull
+ public String getProjectName() {
+ return this.projectName;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ addField(sb, "\"webhookUuid\": ", this.webhookUuid, true);
+ addField(sb, "\"name\": ", this.name, true);
+ addField(sb, "\"url\": ", this.url, true);
+ addField(sb, "\"projectUuid\": ", this.projectUuid, true);
+ addField(sb, "\"projectName\": ", this.projectName, true);
+ endString(sb);
+ return sb.toString();
+ }
+}
import org.sonar.api.security.DefaultGroups;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionNewValue;
+import org.sonar.db.component.ComponentDto;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput;
private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup";
+ private AuditPersister auditPersister;
+
+ public GroupPermissionDao() {
+ }
+
+ public GroupPermissionDao(AuditPersister auditPersister) {
+ this.auditPersister = auditPersister;
+ }
+
/**
* Returns the names of the groups that match the given query.
* The virtual group "Anyone" may be returned as the value {@link DefaultGroups#ANYONE}.
return mapper(session).selectGroupUuidsWithPermissionOnProjectBut(projectUuid, permission);
}
- public void insert(DbSession dbSession, GroupPermissionDto dto) {
+ public void insert(DbSession dbSession, GroupPermissionDto dto, @Nullable ComponentDto componentDto) {
mapper(dbSession).insert(dto);
+
+ if (auditPersister != null) {
+ String projectName = (componentDto != null) ? componentDto.name() : null;
+ auditPersister.addGroupPermission(dbSession, new PermissionNewValue(dto, projectName));
+ }
}
/**
* Delete all the permissions associated to a root component (project)
*/
- public void deleteByRootComponentUuid(DbSession dbSession, String rootComponentUuid) {
+ public void deleteByRootComponentUuid(DbSession dbSession, String rootComponentUuid, String projectName) {
mapper(dbSession).deleteByRootComponentUuid(rootComponentUuid);
+
+ if (auditPersister != null) {
+ auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(null, null, rootComponentUuid, projectName, null));
+ }
}
/**
* Delete all permissions of the specified group (group "AnyOne" if {@code groupUuid} is {@code null}) for the specified
* component.
*/
- public int deleteByRootComponentUuidAndGroupUuid(DbSession dbSession, String rootComponentUuid, @Nullable String groupUuid) {
- return mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(rootComponentUuid, groupUuid);
+ public int deleteByRootComponentUuidAndGroupUuid(DbSession dbSession, String rootComponentUuid, @Nullable String groupUuid, String projectName) {
+ int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(rootComponentUuid, groupUuid);
+
+ if (auditPersister != null) {
+ auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(null, groupUuid, rootComponentUuid, projectName, null));
+ }
+
+ return deletedRecords;
}
/**
* Delete the specified permission for the specified component for any group (including group AnyOne).
*/
- public int deleteByRootComponentUuidAndPermission(DbSession dbSession, String rootComponentUuid, String permission) {
- return mapper(dbSession).deleteByRootComponentUuidAndPermission(rootComponentUuid, permission);
+ public int deleteByRootComponentUuidAndPermission(DbSession dbSession, String rootComponentUuid, String permission, String projectName) {
+ int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndPermission(rootComponentUuid, permission);
+
+ if (auditPersister != null) {
+ auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(permission, null, rootComponentUuid, projectName, null));
+ }
+
+ return deletedRecords;
}
/**
* @param groupUuid if null, then anyone, else uuid of group
* @param rootComponentUuid if null, then global permission, otherwise the uuid of root component (project)
*/
- public void delete(DbSession dbSession, String permission, @Nullable String groupUuid, @Nullable String rootComponentUuid) {
+ public void delete(DbSession dbSession, String permission, @Nullable String groupUuid, @Nullable String rootComponentUuid, @Nullable ComponentDto componentDto) {
mapper(dbSession).delete(permission, groupUuid, rootComponentUuid);
+
+ if (auditPersister != null) {
+ String projectName = (componentDto != null) ? componentDto.name() : null;
+ auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(permission, groupUuid, rootComponentUuid, projectName, null));
+ }
}
private static GroupPermissionMapper mapper(DbSession session) {
import java.util.Collection;
import java.util.List;
import java.util.Set;
+import javax.annotation.Nullable;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionNewValue;
+import org.sonar.db.component.ComponentDto;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Collections.emptyList;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class UserPermissionDao implements Dao {
+ private AuditPersister auditPersister;
+
+ public UserPermissionDao() {
+ }
+
+ public UserPermissionDao(AuditPersister auditPersister) {
+ this.auditPersister = auditPersister;
+ }
/**
* List of user permissions ordered by alphabetical order of user names.
return mapper(session).selectUserUuidsWithPermissionOnProjectBut(projectUuid, permission);
}
- public void insert(DbSession dbSession, UserPermissionDto dto) {
+ public void insert(DbSession dbSession, UserPermissionDto dto, @Nullable ComponentDto componentDto) {
mapper(dbSession).insert(dto);
+
+ if (auditPersister != null) {
+ String projectName = (componentDto != null) ? componentDto.name() : null;
+ auditPersister.addUserPermission(dbSession, new PermissionNewValue(dto, projectName));
+ }
}
/**
*/
public void deleteGlobalPermission(DbSession dbSession, String userUuid, String permission) {
mapper(dbSession).deleteGlobalPermission(userUuid, permission);
+
+ if (auditPersister != null) {
+ auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, null,
+ null, userUuid));
+ }
}
/**
* Removes a single project permission from user
*/
- public void deleteProjectPermission(DbSession dbSession, String userUuid, String permission, String projectUuid) {
+ public void deleteProjectPermission(DbSession dbSession, String userUuid, String permission, String projectUuid, @Nullable String projectName) {
mapper(dbSession).deleteProjectPermission(userUuid, permission, projectUuid);
+
+ if (auditPersister != null) {
+ auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, projectUuid, projectName, userUuid));
+ }
}
/**
* Deletes all the permissions defined on a project
*/
- public void deleteProjectPermissions(DbSession dbSession, String projectUuid) {
+ public void deleteProjectPermissions(DbSession dbSession, String projectUuid, String projectName) {
mapper(dbSession).deleteProjectPermissions(projectUuid);
+
+ if (auditPersister != null) {
+ auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(null, null, projectUuid, projectName, null));
+ }
}
/**
* Deletes the specified permission on the specified project for any user.
*/
- public int deleteProjectPermissionOfAnyUser(DbSession dbSession, String projectUuid, String permission) {
- return mapper(dbSession).deleteProjectPermissionOfAnyUser(projectUuid, permission);
+ public int deleteProjectPermissionOfAnyUser(DbSession dbSession, String projectUuid, String permission, String projectName) {
+ int deletedRows = mapper(dbSession).deleteProjectPermissionOfAnyUser(projectUuid, permission);
+
+ if (auditPersister != null) {
+ auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, projectUuid, projectName, null));
+ }
+
+ return deletedRows;
}
public void deleteByUserUuid(DbSession dbSession, String userUuid) {
mapper(dbSession).deleteByUserUuid(userUuid);
+
+ if (auditPersister != null) {
+ auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(null, null, null, null, userUuid));
+ }
}
private static UserPermissionMapper mapper(DbSession dbSession) {
import java.util.Optional;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class PermissionTemplateCharacteristicDao implements Dao {
+ private AuditPersister auditPersister;
+
+ public PermissionTemplateCharacteristicDao() {
+ }
+
+ public PermissionTemplateCharacteristicDao(AuditPersister auditPersister) {
+ this.auditPersister = auditPersister;
+ }
public List<PermissionTemplateCharacteristicDto> selectByTemplateUuids(DbSession dbSession, List<String> templateUuids) {
return executeLargeInputs(templateUuids, partitionOfTemplateUuids -> mapper(dbSession).selectByTemplateUuids(partitionOfTemplateUuids));
return Optional.ofNullable(dto);
}
- public PermissionTemplateCharacteristicDto insert(DbSession dbSession, PermissionTemplateCharacteristicDto dto) {
+ public PermissionTemplateCharacteristicDto insert(DbSession dbSession, PermissionTemplateCharacteristicDto dto, String templateName) {
checkArgument(dto.getCreatedAt() != 0L && dto.getUpdatedAt() != 0L);
mapper(dbSession).insert(dto);
+
+ if (auditPersister != null) {
+ auditPersister.addCharacteristicToPermissionTemplate(dbSession, new PermissionTemplateNewValue(dto.getTemplateUuid(),
+ dto.getPermission(), templateName, dto.getWithProjectCreator()));
+ }
+
return dto;
}
- public PermissionTemplateCharacteristicDto update(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermissionDto) {
+ public PermissionTemplateCharacteristicDto update(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermissionDto,
+ String templateName) {
requireNonNull(templatePermissionDto.getUuid());
mapper(dbSession).update(templatePermissionDto);
+
+ if (auditPersister != null) {
+ auditPersister.updateCharacteristicInPermissionTemplate(dbSession, new PermissionTemplateNewValue(templatePermissionDto.getTemplateUuid(),
+ templatePermissionDto.getPermission(), templateName, templatePermissionDto.getWithProjectCreator()));
+ }
+
return templatePermissionDto;
}
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
import org.sonar.db.permission.CountPerProjectPermission;
import org.sonar.db.permission.PermissionQuery;
private final System2 system;
private final UuidFactory uuidFactory;
+ private AuditPersister auditPersister;
+
public PermissionTemplateDao(UuidFactory uuidFactory, System2 system) {
this.uuidFactory = uuidFactory;
this.system = system;
}
+ public PermissionTemplateDao(UuidFactory uuidFactory, System2 system, AuditPersister auditPersister) {
+ this(uuidFactory, system);
+ this.auditPersister = auditPersister;
+ }
+
/**
* @return a paginated list of user logins.
*/
dto.setUuid(uuidFactory.create());
}
mapper(session).insert(dto);
+
+ if (auditPersister != null) {
+ auditPersister.addPermissionTemplate(session, new PermissionTemplateNewValue(dto.getUuid(), dto.getName()));
+ }
+
return dto;
}
return mapper(dbSession).selectAllGroupPermissionTemplatesByGroupUuid(groupUuid);
}
- public void deleteByUuid(DbSession session, String templateUuid) {
+ public void deleteByUuid(DbSession session, String templateUuid, String templateName) {
PermissionTemplateMapper mapper = mapper(session);
mapper.deleteUserPermissionsByTemplateUuid(templateUuid);
mapper.deleteGroupPermissionsByTemplateUuid(templateUuid);
session.getMapper(PermissionTemplateCharacteristicMapper.class).deleteByTemplateUuid(templateUuid);
mapper.deleteByUuid(templateUuid);
+
+ if (auditPersister != null) {
+ auditPersister.deletePermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName));
+ }
}
public PermissionTemplateDto update(DbSession session, PermissionTemplateDto permissionTemplate) {
mapper(session).update(permissionTemplate);
+ if (auditPersister != null) {
+ auditPersister.updatePermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplate));
+ }
return permissionTemplate;
}
- public void insertUserPermission(DbSession session, String templateUuid, String userUuid, String permission) {
+ public void insertUserPermission(DbSession session, String templateUuid, String userUuid, String permission,
+ String templateName, String userLogin) {
PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
.setUuid(uuidFactory.create())
.setTemplateUuid(templateUuid)
.setUpdatedAt(now());
mapper(session).insertUserPermission(permissionTemplateUser);
+
+ if (auditPersister != null) {
+ auditPersister.addUserToPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
+ permission, userUuid, userLogin, null, null));
+ }
+
session.commit();
}
- public void deleteUserPermission(DbSession session, String templateUuid, String userUuid, String permission) {
+ public void deleteUserPermission(DbSession session, String templateUuid, String userUuid, String permission,
+ String templateName, String userLogin) {
PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
.setTemplateUuid(templateUuid)
.setPermission(permission)
.setUserUuid(userUuid);
mapper(session).deleteUserPermission(permissionTemplateUser);
+
+ if (auditPersister != null) {
+ auditPersister.deleteUserFromPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
+ permission, userUuid, userLogin, null, null));
+ }
+
session.commit();
}
- public void deleteUserPermissionsByUserUuid(DbSession dbSession, String userUuid) {
+ public void deleteUserPermissionsByUserUuid(DbSession dbSession, String userUuid, String userLogin) {
mapper(dbSession).deleteUserPermissionsByUserUuid(userUuid);
+
+ if (auditPersister != null) {
+ auditPersister.deleteUserFromPermissionTemplate(dbSession, new PermissionTemplateNewValue(null, null,
+ null, userUuid, userLogin, null, null));
+ }
}
- public void insertGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission) {
+ public void insertGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission,
+ String templateName, @Nullable String groupName) {
PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
.setUuid(uuidFactory.create())
.setTemplateUuid(templateUuid)
.setCreatedAt(now())
.setUpdatedAt(now());
mapper(session).insertGroupPermission(permissionTemplateGroup);
+
+ if (auditPersister != null) {
+ auditPersister.addGroupToPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
+ permission, null, null, groupUuid, groupName));
+ }
}
- public void insertGroupPermission(DbSession session, PermissionTemplateGroupDto permissionTemplateGroup) {
+ public void insertGroupPermission(DbSession session, PermissionTemplateGroupDto permissionTemplateGroup, String templateName) {
mapper(session).insertGroupPermission(permissionTemplateGroup);
+
+ if (auditPersister != null) {
+ auditPersister.addGroupToPermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplateGroup.getTemplateUuid(), templateName,
+ permissionTemplateGroup.getPermission(), null, null, permissionTemplateGroup.getGroupUuid(), permissionTemplateGroup.getGroupName()));
+ }
}
- public void deleteGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission) {
+ public void deleteGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission, String templateName,
+ @Nullable String groupName) {
PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
.setTemplateUuid(templateUuid)
.setPermission(permission)
.setGroupUuid(groupUuid);
mapper(session).deleteGroupPermission(permissionTemplateGroup);
+
+ if (auditPersister != null) {
+ auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplateGroup.getTemplateUuid(), templateName,
+ permissionTemplateGroup.getPermission(), null, null, permissionTemplateGroup.getGroupUuid(), groupName));
+ }
+
session.commit();
}
/**
* Remove a group from all templates (used when removing a group)
*/
- public void deleteByGroup(DbSession session, String groupUuid) {
+ public void deleteByGroup(DbSession session, String groupUuid, String groupName) {
session.getMapper(PermissionTemplateMapper.class).deleteByGroupUuid(groupUuid);
+
+ if (auditPersister != null) {
+ auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(null, null,
+ null, null, null, groupUuid, groupName));
+ }
}
private Date now() {
import java.util.Optional;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PluginNewValue;
public class PluginDao implements Dao {
+ private AuditPersister auditPersister;
+
+ public PluginDao() {
+ }
+
+ public PluginDao(AuditPersister auditPersister) {
+ this.auditPersister = auditPersister;
+ }
+
+
public List<PluginDto> selectAll(DbSession dbSession) {
return mapper(dbSession).selectAll();
}
public void insert(DbSession dbSession, PluginDto dto) {
mapper(dbSession).insert(dto);
+
+ if (auditPersister != null) {
+ auditPersister.addPlugin(dbSession, new PluginNewValue(dto));
+ }
}
public void update(DbSession dbSession, PluginDto dto) {
mapper(dbSession).update(dto);
+
+ if (auditPersister != null) {
+ auditPersister.updatePlugin(dbSession, new PluginNewValue(dto));
+ }
}
private static PluginMapper mapper(DbSession dbSession) {
import org.sonar.db.DbSession;
import org.sonar.db.EmailSubscriberDto;
import org.sonar.db.MyBatis;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PropertyNewValue;
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang.StringUtils.repeat;
private final MyBatis mybatis;
private final System2 system2;
- private UuidFactory uuidFactory;
+ private final UuidFactory uuidFactory;
+ private AuditPersister auditPersister;
public PropertiesDao(MyBatis mybatis, System2 system2, UuidFactory uuidFactory) {
this.mybatis = mybatis;
this.uuidFactory = uuidFactory;
}
+ public PropertiesDao(MyBatis mybatis, System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
+ this(mybatis, system2, uuidFactory);
+ this.auditPersister = auditPersister;
+ }
+
/**
* Returns the logins of users who have subscribed to the given notification dispatcher with the given notification channel.
* If a resource ID is passed, the search is made on users who have specifically subscribed for the given resource.
}
try (DbSession session = mybatis.openSession(false);
- Connection connection = session.getConnection();
- PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection);
- ResultSet rs = pstmt.executeQuery()) {
+ Connection connection = session.getConnection();
+ PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection);
+ ResultSet rs = pstmt.executeQuery()) {
return rs.next() && rs.getInt(1) > 0;
} catch (SQLException e) {
throw new IllegalStateException("Fail to execute SQL for hasProjectNotificationSubscribersForDispatchers", e);
*
* @throws IllegalArgumentException if {@link PropertyDto#getKey()} is {@code null} or empty
*/
- public void saveProperty(DbSession session, PropertyDto property) {
+ public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin, @Nullable String projectName) {
save(getMapper(session), property.getKey(), property.getUserUuid(), property.getComponentUuid(), property.getValue());
+
+ if (auditPersister != null && auditPersister.isTrackedProperty(property.getKey())) {
+ auditPersister.addProperty(session, new PropertyNewValue(property, userLogin, projectName), false);
+ }
}
private void save(PropertiesMapper mapper, String key, @Nullable String userUuid, @Nullable String componentUuid, @Nullable String value) {
public void saveProperty(PropertyDto property) {
try (DbSession session = mybatis.openSession(false)) {
- saveProperty(session, property);
+ saveProperty(session, property, null, null);
session.commit();
}
}
* Used by Governance.
*/
public int deleteByQuery(DbSession dbSession, PropertyQuery query) {
- return getMapper(dbSession).deleteByQuery(query);
+ int deletedRows = getMapper(dbSession).deleteByQuery(query);
+
+ if (auditPersister != null && query.key() != null && auditPersister.isTrackedProperty(query.key())) {
+ auditPersister.deleteProperty(dbSession, new PropertyNewValue(query.key(), query.componentUuid(),
+ null, query.userUuid()), false);
+ }
+
+ return deletedRows;
}
- public int delete(DbSession dbSession, PropertyDto dto) {
- return getMapper(dbSession).delete(dto.getKey(), dto.getUserUuid(), dto.getComponentUuid());
+ public int delete(DbSession dbSession, PropertyDto dto, @Nullable String userLogin, @Nullable String projectName) {
+ int deletedRows = getMapper(dbSession).delete(dto.getKey(), dto.getUserUuid(), dto.getComponentUuid());
+
+ if (auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) {
+ auditPersister.deleteProperty(dbSession, new PropertyNewValue(dto, userLogin, projectName), false);
+ }
+ return deletedRows;
}
- public void deleteProjectProperty(String key, String projectUuid) {
+ public void deleteProjectProperty(String key, String projectUuid, String projectName) {
try (DbSession session = mybatis.openSession(false)) {
- deleteProjectProperty(key, projectUuid, session);
+ deleteProjectProperty(key, projectUuid, session, projectName);
session.commit();
}
}
- public void deleteProjectProperty(String key, String projectUuid, DbSession session) {
+ public void deleteProjectProperty(String key, String projectUuid, DbSession session, String projectName) {
getMapper(session).deleteProjectProperty(key, projectUuid);
+
+ if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ auditPersister.deleteProperty(session, new PropertyNewValue(key, projectUuid, projectName, null), false);
+ }
}
public void deleteProjectProperties(String key, String value, DbSession session) {
getMapper(session).deleteProjectProperties(key, value);
+
+ if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ auditPersister.deleteProperty(session, new PropertyNewValue(key, value), false);
+ }
}
public void deleteProjectProperties(String key, String value) {
public void deleteGlobalProperty(String key, DbSession session) {
getMapper(session).deleteGlobalProperty(key);
+
+ if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ auditPersister.deleteProperty(session, new PropertyNewValue(key), false);
+ }
}
public void deleteGlobalProperty(String key) {
}
}
- public void deleteByUser(DbSession dbSession, String userUuid) {
+ public void deleteByUser(DbSession dbSession, String userUuid, String userLogin) {
List<String> uuids = getMapper(dbSession).selectUuidsByUser(userUuid);
+
+ persistDeletedProperties(dbSession, userUuid, userLogin, uuids);
+
executeLargeInputsWithoutOutput(uuids, subList -> getMapper(dbSession).deleteByUuids(subList));
}
public void deleteByMatchingLogin(DbSession dbSession, String login, List<String> propertyKeys) {
List<String> uuids = getMapper(dbSession).selectIdsByMatchingLogin(login, propertyKeys);
+
+ persistDeletedProperties(dbSession, null, login, uuids);
+
executeLargeInputsWithoutOutput(uuids, list -> getMapper(dbSession).deleteByUuids(list));
}
public void deleteByKeyAndValue(DbSession dbSession, String key, String value) {
getMapper(dbSession).deleteByKeyAndValue(key, value);
+
+ if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ auditPersister.deleteProperty(dbSession, new PropertyNewValue(key, value), false);
+ }
}
public void saveGlobalProperties(Map<String, String> properties) {
properties.forEach((key, value) -> {
mapper.deleteGlobalProperty(key);
save(mapper, key, null, null, value);
+
+ if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ auditPersister.addProperty(session, new PropertyNewValue(key, value), false);
+ }
});
session.commit();
}
return session.getMapper(PropertiesMapper.class);
}
+ private void persistDeletedProperties(DbSession dbSession, @Nullable String userUuid, String userLogin, List<String> uuids) {
+ if (auditPersister != null) {
+ List<PropertyDto> properties = executeLargeInputs(uuids, subList -> getMapper(dbSession).selectByUuids(subList));
+
+ properties
+ .stream()
+ .filter(p -> auditPersister.isTrackedProperty(p.getKey()))
+ .forEach(p -> auditPersister.deleteProperty(dbSession,
+ new PropertyNewValue(p.getKey(), userUuid, userLogin), false));
+ }
+ }
}
void deleteByKeyAndValue(@Param("key") String key, @Param("value") String value);
+ List<PropertyDto> selectByUuids(@Param("uuids") List<String> uuids);
+
int renamePropertyKey(@Param("oldKey") String oldKey, @Param("newKey") String newKey);
}
if (auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) {
if (isUpdate) {
- auditPersister.updateUserProperty(session, new PropertyNewValue(dto, login));
+ auditPersister.updateProperty(session, new PropertyNewValue(dto, login), true);
} else {
- auditPersister.addUserProperty(session, new PropertyNewValue(dto, login));
+ auditPersister.addProperty(session, new PropertyNewValue(dto, login), true);
}
}
if (auditPersister != null) {
userProperties.stream()
.filter(p -> auditPersister.isTrackedProperty(p.getKey()))
- .forEach(p -> auditPersister.deleteUserProperty(session, new PropertyNewValue(p, user.getLogin())));
+ .forEach(p -> auditPersister.deleteProperty(session, new PropertyNewValue(p, user.getLogin()), true));
}
}
import java.util.List;
import java.util.Optional;
+import javax.annotation.Nullable;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.WebhookNewValue;
import org.sonar.db.project.ProjectDto;
public class WebhookDao implements Dao {
private final System2 system2;
+ private AuditPersister auditPersister;
+
public WebhookDao(System2 system2) {
this.system2 = system2;
}
+ public WebhookDao(System2 system2, AuditPersister auditPersister) {
+ this.system2 = system2;
+ this.auditPersister = auditPersister;
+ }
+
public List<WebhookDto> selectGlobalWebhooks(DbSession dbSession) {
return mapper(dbSession).selectGlobalWebhooksOrderedByName();
}
return mapper(dbSession).selectForProjectUuidOrderedByName(projectDto.getUuid());
}
- public void insert(DbSession dbSession, WebhookDto dto) {
+ public void insert(DbSession dbSession, WebhookDto dto, @Nullable String projectName) {
mapper(dbSession).insert(dto.setCreatedAt(system2.now()).setUpdatedAt(system2.now()));
+
+ if (auditPersister != null) {
+ auditPersister.addWebhook(dbSession, new WebhookNewValue(dto.getUuid(), dto.getName(),
+ dto.getProjectUuid(), projectName));
+ }
}
- public void update(DbSession dbSession, WebhookDto dto) {
+ public void update(DbSession dbSession, WebhookDto dto, @Nullable String projectName) {
mapper(dbSession).update(dto.setUpdatedAt(system2.now()));
+
+ if (auditPersister != null) {
+ auditPersister.updateWebhook(dbSession, new WebhookNewValue(dto, projectName));
+ }
}
- public void delete(DbSession dbSession, String uuid) {
+ public void delete(DbSession dbSession, String uuid, String webhookName) {
mapper(dbSession).delete(uuid);
+
+ if (auditPersister != null) {
+ auditPersister.deleteWebhook(dbSession, new WebhookNewValue(uuid, webhookName));
+ }
}
public void deleteByProject(DbSession dbSession, ProjectDto projectDto) {
mapper(dbSession).deleteForProjectUuid(projectDto.getUuid());
+
+ if (auditPersister != null) {
+ auditPersister.deleteWebhook(dbSession, new WebhookNewValue(projectDto));
+ }
}
private static WebhookMapper mapper(DbSession dbSession) {
</foreach>
</delete>
+ <select id="selectByUuids" parameterType="map" resultType="ScrapProperty">
+ select
+ <include refid="columnsToScrapPropertyDto"/>
+ from
+ properties p
+ where
+ uuid in
+ <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
+ #{uuid}
+ </foreach>
+ </select>
+
<update id="renamePropertyKey" parameterType="map">
update properties set
prop_key=#{newKey}
"UUID" VARCHAR(40) NOT NULL,
"USER_UUID" VARCHAR(40) NOT NULL,
"USER_LOGIN" VARCHAR(255) NOT NULL,
- "CATEGORY" VARCHAR(20) NOT NULL,
+ "CATEGORY" VARCHAR(25) NOT NULL,
"OPERATION" VARCHAR(50) NOT NULL,
"NEW_VALUE" VARCHAR(4000),
"CREATED_AT" BIGINT NOT NULL
when(uuidFactory.create()).thenReturn(A_UUID);
AlmPatDto almPatDto = newAlmPatDto();
- underTest.insert(dbSession, almPatDto);
+ underTest.insert(dbSession, almPatDto, null, null);
assertThat(underTest.selectByUuid(dbSession, A_UUID).get())
.extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
String userUuid = randomAlphanumeric(40);
almPatDto.setUserUuid(userUuid);
- underTest.insert(dbSession, almPatDto);
+ underTest.insert(dbSession, almPatDto, null, null);
assertThat(underTest.selectByUserAndAlmSetting(dbSession, userUuid, almSetting).get())
.extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
public void update() {
when(uuidFactory.create()).thenReturn(A_UUID);
AlmPatDto almPatDto = newAlmPatDto();
- underTest.insert(dbSession, almPatDto);
+ underTest.insert(dbSession, almPatDto, null, null);
String updated_pat = "updated pat";
almPatDto.setPersonalAccessToken(updated_pat);
system2.setNow(NOW + 1);
- underTest.update(dbSession, almPatDto);
+ underTest.update(dbSession, almPatDto, null, null);
AlmPatDto result = underTest.selectByUuid(dbSession, A_UUID).get();
assertThat(result)
public void delete() {
when(uuidFactory.create()).thenReturn(A_UUID);
AlmPatDto almPat = newAlmPatDto();
- underTest.insert(dbSession, almPat);
+ underTest.insert(dbSession, almPat, null, null);
- underTest.delete(dbSession, almPat);
+ underTest.delete(dbSession, almPat, null, null);
assertThat(underTest.selectByUuid(dbSession, almPat.getUuid())).isNotPresent();
}
UserDto userDto = db.users().insertUser();
AlmPatDto almPat = newAlmPatDto();
almPat.setUserUuid(userDto.getUuid());
- underTest.insert(dbSession, almPat);
+ underTest.insert(dbSession, almPat, userDto.getLogin(), null);
underTest.deleteByUser(dbSession, userDto);
AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
AlmPatDto almPat = newAlmPatDto();
almPat.setAlmSettingUuid(almSettingDto.getUuid());
- underTest.insert(dbSession, almPat);
+ underTest.insert(dbSession, almPat, null, null);
underTest.deleteByAlmSetting(dbSession, almSettingDto);
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.alm.pat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PersonalAccessTokenNewValue;
+import org.sonar.db.user.UserDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto;
+
+public class AlmPatDaoWithPersisterTest {
+
+ private static final long NOW = 1000000L;
+ private static final String A_UUID = "SOME_UUID";
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+ private final ArgumentCaptor<PersonalAccessTokenNewValue> newValueCaptor = ArgumentCaptor.forClass(PersonalAccessTokenNewValue.class);
+ private TestSystem2 system2 = new TestSystem2().setNow(NOW);
+ @Rule
+ public DbTester db = DbTester.create(system2, auditPersister);
+
+ private DbSession dbSession = db.getSession();
+ private UuidFactory uuidFactory = mock(UuidFactory.class);
+
+ private AlmPatDao underTest = db.getDbClient().almPatDao();
+
+ @Test
+ public void insertAndUpdateArePersisted() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+
+ AlmPatDto almPatDto = newAlmPatDto();
+ underTest.insert(dbSession, almPatDto, "user-login", "alm-key");
+
+ verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+ PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getUserUuid,
+ PersonalAccessTokenNewValue::getAlmSettingUuid, PersonalAccessTokenNewValue::getUserLogin,
+ PersonalAccessTokenNewValue::getAlmSettingKey)
+ .containsExactly(almPatDto.getUuid(), almPatDto.getUserUuid(), almPatDto.getAlmSettingUuid(),
+ "user-login", "alm-key");
+ assertThat(newValue.toString()).contains("userLogin");
+
+ String updated_pat = "updated pat";
+ almPatDto.setPersonalAccessToken(updated_pat);
+ system2.setNow(NOW + 1);
+ underTest.update(dbSession, almPatDto, null, null);
+
+ verify(auditPersister).updatePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+ }
+
+ @Test
+ public void deleteIsPersisted() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+
+ AlmPatDto almPat = newAlmPatDto();
+ underTest.insert(dbSession, almPat, null, null);
+ verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+
+ underTest.delete(dbSession, almPat, null, null);
+
+ verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+ PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getUserUuid,
+ PersonalAccessTokenNewValue::getAlmSettingUuid, PersonalAccessTokenNewValue::getUserLogin,
+ PersonalAccessTokenNewValue::getAlmSettingKey)
+ .containsExactly(almPat.getUuid(), almPat.getUserUuid(), almPat.getAlmSettingUuid(),
+ null, null);
+ assertThat(newValue.toString()).doesNotContain("userLogin");
+ }
+
+ @Test
+ public void deleteByUserIsPersisted() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ UserDto userDto = db.users().insertUser();
+ AlmPatDto almPat = newAlmPatDto();
+ almPat.setUserUuid(userDto.getUuid());
+ underTest.insert(dbSession, almPat, userDto.getLogin(), null);
+ verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+
+ underTest.deleteByUser(dbSession, userDto);
+
+ verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+ PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getUserUuid,
+ PersonalAccessTokenNewValue::getUserLogin, PersonalAccessTokenNewValue::getAlmSettingKey)
+ .containsExactly(null, userDto.getUuid(), userDto.getLogin(), null);
+ assertThat(newValue.toString()).doesNotContain("patUuid");
+ }
+
+ @Test
+ public void deleteByAlmSettingIsPersisted() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
+ AlmPatDto almPat = newAlmPatDto();
+ almPat.setAlmSettingUuid(almSettingDto.getUuid());
+ underTest.insert(dbSession, almPat, null, almSettingDto.getKey());
+ verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+
+ underTest.deleteByAlmSetting(dbSession, almSettingDto);
+
+ verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+ PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getAlmSettingUuid,
+ PersonalAccessTokenNewValue::getAlmSettingKey)
+ .containsExactly(null, almPat.getAlmSettingUuid(), almSettingDto.getKey());
+ assertThat(newValue.toString()).doesNotContain("userUuid");
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.alm.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto;
+
+public class AlmSettingDaoWithPersisterTest {
+
+ private static final long NOW = 1000000L;
+ private static final String A_UUID = "SOME_UUID";
+
+ private final ArgumentCaptor<DevOpsPlatformSettingNewValue> newValueCaptor = ArgumentCaptor.forClass(DevOpsPlatformSettingNewValue.class);
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+ private final TestSystem2 system2 = new TestSystem2().setNow(NOW);
+ @Rule
+ public final DbTester db = DbTester.create(system2, auditPersister);
+
+ private final DbSession dbSession = db.getSession();
+ private final UuidFactory uuidFactory = mock(UuidFactory.class);
+
+ private final AlmSettingDao underTest = db.getDbClient().almSettingDao();
+
+ @Test
+ public void insertAndUpdateArePersisted() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ AlmSettingDto almSettingDto = newGithubAlmSettingDto();
+
+ underTest.insert(dbSession, almSettingDto);
+
+ verify(auditPersister).addDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+ DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
+ .containsExactly(almSettingDto.getUuid(), almSettingDto.getKey());
+ assertThat(newValue.toString()).doesNotContain("url");
+
+ almSettingDto.setPrivateKey("updated private key");
+ almSettingDto.setAppId("updated app id");
+ almSettingDto.setUrl("updated url");
+ almSettingDto.setPersonalAccessToken("updated pat");
+ almSettingDto.setKey("updated key");
+ system2.setNow(NOW + 1);
+
+ underTest.update(dbSession, almSettingDto);
+
+ verify(auditPersister).updateDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey,
+ DevOpsPlatformSettingNewValue::getAppId, DevOpsPlatformSettingNewValue::getDevOpsPlatformName,
+ DevOpsPlatformSettingNewValue::getUrl, DevOpsPlatformSettingNewValue::getClientId)
+ .containsExactly(almSettingDto.getUuid(), almSettingDto.getKey(), almSettingDto.getAppId(), almSettingDto.getAppId(),
+ almSettingDto.getUrl(), almSettingDto.getClientId());
+ }
+
+ @Test
+ public void deleteIsPersisted() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ AlmSettingDto almSettingDto = newGithubAlmSettingDto();
+ underTest.insert(dbSession, almSettingDto);
+
+ underTest.delete(dbSession, almSettingDto);
+
+ verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+ DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
+ .containsExactly(almSettingDto.getUuid(), almSettingDto.getKey());
+ assertThat(newValue.toString()).doesNotContain("url");
+ }
+}
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectDto anotherProject = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto githubProjectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSettingDto, project);
- underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto);
+ underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto, githubAlmSettingDto.getKey(), anotherProject.getName());
assertThat(underTest.selectByProject(dbSession, project).get())
.extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid,
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto bitbucketProjectAlmSettingDto = newBitbucketProjectAlmSettingDto(almSettingsDto, project);
bitbucketProjectAlmSettingDto.setAlmSlug("slug1");
- underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto);
+ underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto, almSettingsDto.getKey(), project.getName());
ProjectAlmSettingDto bitbucketProjectAlmSettingDto2 = newBitbucketProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto());
bitbucketProjectAlmSettingDto2.setAlmSlug("slug2");
when(uuidFactory.create()).thenReturn(A_UUID + 1);
- underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto2);
+ underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto2, almSettingsDto.getKey(), project.getName());
Set<String> slugs = new HashSet<>();
slugs.add("slug1");
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto githubProjectAlmSettingDto = newGithubProjectAlmSettingDto(almSettingsDto, project);
githubProjectAlmSettingDto.setAlmRepo("repo1");
- underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto);
+ underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto, almSettingsDto.getKey(), project.getName());
ProjectAlmSettingDto githubProjectAlmSettingDto2 = newGithubProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto());
githubProjectAlmSettingDto2.setAlmRepo("repo2");
when(uuidFactory.create()).thenReturn(A_UUID + 1);
- underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto2);
+ underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto2, almSettingsDto.getKey(), project.getName());
Set<String> repos = new HashSet<>();
repos.add("repo1");
system2.setNow(A_DATE_LATER);
ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project)
.setSummaryCommentEnabled(false);
- underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto);
+ underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto, githubAlmSetting.getKey(), project.getName());
assertThat(underTest.selectByProject(dbSession, project).get())
.extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.alm.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
+import org.sonar.db.project.ProjectDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubProjectAlmSettingDto;
+
+public class ProjectAlmSettingDaoWithPersisterTest {
+ private static final long A_DATE = 1_000_000_000_000L;
+ private static final long A_DATE_LATER = 1_700_000_000_000L;
+ private static final String A_UUID = "SOME_UUID";
+
+ private final ArgumentCaptor<DevOpsPlatformSettingNewValue> newValueCaptor = ArgumentCaptor.forClass(DevOpsPlatformSettingNewValue.class);
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+ private final TestSystem2 system2 = new TestSystem2().setNow(A_DATE);
+ @Rule
+ public final DbTester db = DbTester.create(system2, auditPersister);
+
+ private final DbSession dbSession = db.getSession();
+ private final UuidFactory uuidFactory = mock(UuidFactory.class);
+ private final ProjectAlmSettingDao underTest = db.getDbClient().projectAlmSettingDao();
+
+ @Test
+ public void insertAndUpdateExistingBindingArePersisted() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+ ProjectDto project = db.components().insertPrivateProjectDto();
+ ProjectAlmSettingDto projectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSetting, project)
+ .setSummaryCommentEnabled(false);
+ underTest.insertOrUpdate(dbSession, projectAlmSettingDto, githubAlmSetting.getKey(), project.getName());
+
+ verify(auditPersister).addDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+ DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey,
+ DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectName)
+ .containsExactly(githubAlmSetting.getUuid(), githubAlmSetting.getKey(), project.getUuid(), project.getName());
+ assertThat(newValue.toString()).doesNotContain("url");
+
+ AlmSettingDto anotherGithubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+ system2.setNow(A_DATE_LATER);
+ ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project)
+ .setSummaryCommentEnabled(false);
+ underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto, anotherGithubAlmSetting.getKey(), project.getName());
+
+ verify(auditPersister).updateDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey,
+ DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectName,
+ DevOpsPlatformSettingNewValue::getAlmRepo, DevOpsPlatformSettingNewValue::getAlmSlug,
+ DevOpsPlatformSettingNewValue::isSummaryCommentEnabled, DevOpsPlatformSettingNewValue::isMonorepo)
+ .containsExactly(anotherGithubAlmSetting.getUuid(), anotherGithubAlmSetting.getKey(), project.getUuid(), project.getName(),
+ newProjectAlmSettingDto.getAlmRepo(), newProjectAlmSettingDto.getAlmSlug(),
+ newProjectAlmSettingDto.getSummaryCommentEnabled(), newProjectAlmSettingDto.getMonorepo());
+ assertThat(newValue.toString()).doesNotContain("url");
+ }
+
+ @Test
+ public void deleteByProject() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+ ProjectDto project = db.components().insertPrivateProjectDto();
+ ProjectAlmSettingDto projectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSetting, project)
+ .setSummaryCommentEnabled(false);
+ underTest.insertOrUpdate(dbSession, projectAlmSettingDto, githubAlmSetting.getKey(), project.getName());
+ underTest.deleteByProject(dbSession, project);
+
+ verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+ DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectName)
+ .containsExactly(project.getUuid(), project.getName());
+ assertThat(newValue.toString()).doesNotContain("devOpsPlatformSettingUuid");
+ }
+
+ @Test
+ public void deleteByAlmSettingWhenNotTracked() {
+ AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+ underTest.deleteByAlmSetting(dbSession, githubAlmSetting);
+
+ verifyNoInteractions(auditPersister);
+ }
+
+ @Test
+ public void deleteByAlmSettingWhenTracked() {
+ AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+ underTest.deleteByAlmSetting(dbSession, githubAlmSetting, true);
+
+ verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+ DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
+ .containsExactly(githubAlmSetting.getUuid(), githubAlmSetting.getKey());
+ assertThat(newValue.toString()).doesNotContain("url");
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LicenseNewValueTest {
+
+ @Test
+ public void toStringIsEmptyForNullEdition(){
+ LicenseNewValue newValue = new LicenseNewValue(null);
+ assertThat(newValue.toString()).isEqualTo("{}");
+ }
+
+ @Test
+ public void toStringHasEdition(){
+ LicenseNewValue newValue = new LicenseNewValue("Developer");
+ assertThat(newValue.toString()).contains("edition");
+ }
+}
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
import org.sonar.db.user.GroupDto;
import static java.util.Arrays.asList;
db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
db.users().insertProjectPermissionOnGroup(group2, "perm3", project2);
- underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
+ underTest.deleteByRootComponentUuid(dbSession, project1.uuid(), project1.name());
dbSession.commit();
assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.uuid() + "'")).isZero();
db.users().insertProjectPermissionOnAnyone("perm4", project1);
db.users().insertProjectPermissionOnAnyone("perm5", project2);
- underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
+ underTest.deleteByRootComponentUuid(dbSession, project1.uuid(), project1.name());
dbSession.commit();
assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.uuid() + "'")).isZero();
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
- underTest.delete(dbSession, "perm2", group1.getUuid(), null);
+ underTest.delete(dbSession, "perm2", group1.getUuid(), null, project1);
dbSession.commit();
assertThatNoPermission("perm2");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
- underTest.delete(dbSession, "perm2", group1.getUuid(), null);
+ underTest.delete(dbSession, "perm2", group1.getUuid(), null, project1);
dbSession.commit();
assertThatNoPermission("perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
- underTest.delete(dbSession, "perm1", null, null);
+ underTest.delete(dbSession, "perm1", null, null, project1);
dbSession.commit();
assertThatNoPermission("perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
- underTest.delete(dbSession, "perm3", group1.getUuid(), project1.uuid());
+ underTest.delete(dbSession, "perm3", group1.getUuid(), project1.uuid(), project1);
dbSession.commit();
assertThatNoPermission("perm3");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
- underTest.delete(dbSession, "perm3", group1.getUuid(), project1.uuid());
+ underTest.delete(dbSession, "perm3", group1.getUuid(), project1.uuid(), project1);
dbSession.commit();
assertThatNoPermission("perm3");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
- underTest.delete(dbSession, "perm4", null, project1.uuid());
+ underTest.delete(dbSession, "perm4", null, project1.uuid(), project1);
dbSession.commit();
assertThatNoPermission("perm4");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, group.getUuid()))
.containsOnly("p4");
- int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null);
+ int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null, project.name());
assertThat(deletedCount).isEqualTo(1);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, group2.getUuid()))
.containsOnly("p7");
- int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group1.getUuid());
+ int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group1.getUuid(), project.name());
assertThat(deletedCount).isEqualTo(1);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, group2.getUuid()))
.containsOnly("p7");
- deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid());
+ deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid(), project.name());
assertThat(deletedCount).isEqualTo(2);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid()))
public void deleteByRootComponentUuidAndGroupUuid_has_no_effect_if_component_does_not_exist() {
GroupDto group = db.users().insertGroup();
- assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", null)).isZero();
- assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", group.getUuid())).isZero();
+ assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", null, "")).isZero();
+ assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", group.getUuid(), "")).isZero();
}
@Test
ComponentDto project = randomPublicOrPrivateProject();
GroupDto group = db.users().insertGroup();
- assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null)).isZero();
- assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group.getUuid())).isZero();
+ assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null, project.name())).isZero();
+ assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group.getUuid(), project.name())).isZero();
}
@Test
public void deleteByRootComponentUuidAndGroupUuid_has_no_effect_if_group_does_not_exist() {
ComponentDto project = randomPublicOrPrivateProject();
- assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), "5678")).isZero();
+ assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), "5678", project.name())).isZero();
}
@Test
db.users().insertPermissionOnAnyone("p2");
db.users().insertPermissionOnGroup(group1, "p3");
- int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null);
+ int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null, project.name());
assertThat(deletedCount).isZero();
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid()))
db.users().insertPermissionOnAnyone("p2");
db.users().insertPermissionOnGroup(group1, "p3");
- int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid());
+ int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid(), project.name());
assertThat(deletedCount).isZero();
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, group1.getUuid(), project.uuid()))
assertThat(getProjectPermissionsForAnyOne(project)).containsOnly("p1", "p2");
assertThat(getProjectPermissionsForGroup(project, group)).containsOnly("p1", "p2");
- int deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1");
+ int deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1", project.name());
assertThat(deletedRows).isEqualTo(2);
assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1", "p2");
assertThat(getProjectPermissionsForAnyOne(project)).containsOnly("p2");
assertThat(getProjectPermissionsForGroup(project, group)).containsOnly("p2");
- deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p2");
+ deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p2", project.name());
assertThat(deletedRows).isEqualTo(2);
assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1", "p2");
db.users().insertPermissionOnAnyone("p1");
db.users().insertPermissionOnGroup(group, "p1");
- assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1")).isZero();
+ assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1", project.name())).isZero();
assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1");
assertThat(getGlobalPermissionsForGroup(group)).containsOnly("p1");
db.users().insertProjectPermissionOnGroup(group, "p1", project);
db.users().insertProjectPermissionOnAnyone("p1", project);
- assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, "1324", "p1")).isZero();
+ assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, "1324", "p1", "")).isZero();
assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1");
assertThat(getGlobalPermissionsForGroup(group)).containsOnly("p1");
db.users().insertPermissionOnAnyone("p1");
db.users().insertPermissionOnGroup(group, "p1");
- assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1")).isZero();
+ assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1", project.name())).isZero();
}
private Collection<String> getGlobalPermissionsForAnyone() {
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.permission;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionNewValue;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.user.GroupDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.sonar.api.web.UserRole.ADMIN;
+
+public class GroupPermissionDaoWithPersisterTest {
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+
+ private final ArgumentCaptor<PermissionNewValue> newValueCaptor = ArgumentCaptor.forClass(PermissionNewValue.class);
+ private final DbSession dbSession = db.getSession();
+ private final GroupPermissionDao underTest = db.getDbClient().groupPermissionDao();
+
+ @Test
+ public void groupGlobalPermissionInsertAndDeleteArePersisted() {
+ GroupDto group = db.users().insertGroup();
+ GroupPermissionDto dto = new GroupPermissionDto()
+ .setUuid(Uuids.createFast())
+ .setGroupUuid(group.getUuid())
+ .setRole(ADMIN);
+ underTest.insert(dbSession, dto, null);
+
+ verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
+ PermissionNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(dto.getUuid(), group.getUuid(), null, dto.getRole(), null);
+ assertThat(newValue.toString()).doesNotContain("projectUuid");
+
+ underTest.delete(dbSession, ADMIN, group.getUuid(), null, null);
+
+ verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(null, group.getUuid(), null, ADMIN, null);
+ assertThat(newValue.toString()).doesNotContain("permissionUuid");
+ }
+
+ @Test
+ public void groupProjectPermissionDeleteByComponentIsPersisted() {
+ GroupDto group = db.users().insertGroup();
+ ComponentDto project = db.components().insertPrivateProject();
+ GroupPermissionDto dto = getGroupPermission(group, project);
+ underTest.insert(dbSession, dto, project);
+
+ verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
+ PermissionNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(dto.getUuid(), group.getUuid(), project.uuid(), dto.getRole(), project.name());
+ assertThat(newValue.toString()).contains("projectUuid");
+
+ underTest.deleteByRootComponentUuid(dbSession, project.uuid(), project.name());
+
+ verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(null, null, project.uuid(), null, project.name());
+ assertThat(newValue.toString()).doesNotContain("permissionUuid");
+ }
+
+ @Test
+ public void groupProjectPermissionDeleteByComponentAndGroupIsPersisted() {
+ GroupDto group = db.users().insertGroup();
+ ComponentDto project = db.components().insertPrivateProject();
+ GroupPermissionDto dto = getGroupPermission(group, project);
+ underTest.insert(dbSession, dto, project);
+
+ verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
+ PermissionNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(dto.getUuid(), group.getUuid(), project.uuid(), dto.getRole(), project.name());
+ assertThat(newValue.toString()).contains("projectUuid");
+
+ underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group.getUuid(), project.name());
+
+ verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(null, group.getUuid(), project.uuid(), null, project.name());
+ assertThat(newValue.toString()).doesNotContain("permissionUuid");
+ }
+
+ @Test
+ public void groupProjectPermissionDeleteByComponentAndPermissionIsPersisted() {
+ GroupDto group = db.users().insertGroup();
+ ComponentDto project = db.components().insertPrivateProject();
+ GroupPermissionDto dto = getGroupPermission(group, project);
+ underTest.insert(dbSession, dto, project);
+
+ verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
+ PermissionNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(dto.getUuid(), group.getUuid(), project.uuid(), dto.getRole(), project.name());
+ assertThat(newValue.toString()).contains("projectUuid");
+
+ underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), dto.getRole(), project.name());
+
+ verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(null, null, project.uuid(), ADMIN, project.name());
+ assertThat(newValue.toString()).doesNotContain("permissionUuid");
+ }
+
+ private GroupPermissionDto getGroupPermission(GroupDto group, ComponentDto project) {
+ return new GroupPermissionDto()
+ .setUuid(Uuids.createFast())
+ .setGroupUuid(group.getUuid())
+ .setRole(ADMIN)
+ .setComponentUuid(project.uuid());
+ }
+}
addProjectPermission("perm", user2, project1);
// no such provision -> ignore
- underTest.deleteProjectPermission(dbSession, user1.getUuid(), "anotherPerm", project1.uuid());
+ underTest.deleteProjectPermission(dbSession, user1.getUuid(), "anotherPerm", project1.uuid(), project1.name());
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4);
- underTest.deleteProjectPermission(dbSession, user1.getUuid(), "perm", project1.uuid());
+ underTest.deleteProjectPermission(dbSession, user1.getUuid(), "perm", project1.uuid(), project1.name());
assertThatProjectPermissionDoesNotExist(user1, "perm", project1);
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(3);
}
addProjectPermission("perm", user2, project1);
addProjectPermission("perm", user1, project2);
- underTest.deleteProjectPermissions(dbSession, project1.uuid());
+ underTest.deleteProjectPermissions(dbSession, project1.uuid(), project1.name());
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(2);
assertThatProjectHasNoPermissions(project1);
}
UserDto user = insertUser();
db.users().insertPermissionOnUser(user, SCAN);
- int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, "124", SCAN.getKey());
+ int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, "124", SCAN.getKey(), "");
assertThat(deletedCount).isZero();
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid())).containsOnly(SCAN.getKey());
db.users().insertPermissionOnUser(user, SCAN);
ComponentDto project = randomPublicOrPrivateProject();
- int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), SCAN.getKey());
+ int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), SCAN.getKey(), "");
assertThat(deletedCount).isZero();
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid())).containsOnly(SCAN.getKey());
ComponentDto project = randomPublicOrPrivateProject();
db.users().insertProjectPermissionOnUser(user, SCAN.getKey(), project);
- int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), "p1");
+ int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), "p1", project.name());
assertThat(deletedCount).isZero();
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid())).containsOnly(SCAN.getKey());
db.users().insertProjectPermissionOnUser(user2, SCAN.getKey(), project2);
db.users().insertProjectPermissionOnUser(user2, PROVISION_PROJECTS.getKey(), project2);
- int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project1.uuid(), SCAN.getKey());
+ int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project1.uuid(), SCAN.getKey(), project1.name());
assertThat(deletedCount).isEqualTo(2);
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid())).containsOnly(SCAN.getKey());
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project2.uuid())).containsOnly(SCAN.getKey());
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getUuid(), project2.uuid())).containsOnly(SCAN.getKey(), PROVISION_PROJECTS.getKey());
- deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project2.uuid(), SCAN.getKey());
+ deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project2.uuid(), SCAN.getKey(), project2.name());
assertThat(deletedCount).isEqualTo(2);
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid())).containsOnly(SCAN.getKey());
private UserPermissionDto addGlobalPermission(String permission, UserDto user) {
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), null);
- underTest.insert(dbSession, dto);
+ underTest.insert(dbSession, dto, null);
db.commit();
return dto;
}
private UserPermissionDto addProjectPermission(String permission, UserDto user, ComponentDto project) {
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), project.uuid());
- underTest.insert(dbSession, dto);
+ underTest.insert(dbSession, dto, project);
db.commit();
return dto;
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.permission;
+
+import java.util.function.Consumer;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionNewValue;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.user.UserDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
+import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
+
+public class UserPermissionDaoWithPersisterTest {
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+ @Rule
+ public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+
+ private final ArgumentCaptor<PermissionNewValue> newValueCaptor = ArgumentCaptor.forClass(PermissionNewValue.class);
+ private final DbSession dbSession = db.getSession();
+ private final UserPermissionDao underTest = db.getDbClient().userPermissionDao();
+
+ @Test
+ public void userGlobalPermissionInsertAndDeleteArePersisted() {
+ UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+ UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), null);
+ underTest.insert(dbSession, dto, null);
+
+ verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
+ PermissionNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(dto.getUuid(), user.getUuid(), null, dto.getPermission(), null);
+ assertThat(newValue.toString()).doesNotContain("projectUuid");
+
+ underTest.deleteGlobalPermission(dbSession, user.getUuid(), SYSTEM_ADMIN);
+
+ verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(null, user.getUuid(), null, dto.getPermission(), null);
+ assertThat(newValue.toString()).doesNotContain("permissionUuid");
+ }
+
+ @Test
+ public void userProjectPermissionInsertAndDeleteArePersisted() {
+ UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+ ComponentDto project = db.components().insertPrivateProject();
+ UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), project.uuid());
+ underTest.insert(dbSession, dto, project);
+
+ verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
+ PermissionNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(dto.getUuid(), user.getUuid(), project.uuid(), dto.getPermission(), project.name());
+ assertThat(newValue.toString()).contains("projectUuid");
+
+ underTest.deleteProjectPermission(dbSession, user.getUuid(), SYSTEM_ADMIN, project.projectUuid(), project.name());
+
+ verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(null, user.getUuid(), project.uuid(), dto.getPermission(), project.name());
+ assertThat(newValue.toString()).doesNotContain("permissionUuid");
+ }
+
+ @Test
+ public void deleteUserPermissionOfAnyUserIsPersisted() {
+ UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+ ComponentDto project = db.components().insertPrivateProject();
+ UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SCAN_EXECUTION, user.getUuid(), project.uuid());
+ underTest.insert(dbSession, dto, project);
+ underTest.deleteProjectPermissionOfAnyUser(dbSession, project.projectUuid(), SCAN_EXECUTION, project.name());
+
+ verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
+ PermissionNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(null, null, project.uuid(), SCAN_EXECUTION, project.name());
+ assertThat(newValue.toString()).doesNotContain("userUuid");
+ }
+
+ @Test
+ public void deleteUserPermissionByUserUuidIsPersisted() {
+ UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+ ComponentDto project = db.components().insertPrivateProject();
+ UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), project.uuid());
+ underTest.insert(dbSession, dto, project);
+ underTest.deleteByUserUuid(dbSession, user.getUuid());
+
+ verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
+ PermissionNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+ PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+ .containsExactly(null, user.getUuid(), null, null, null);
+ assertThat(newValue.toString()).contains("userUuid");
+ }
+
+ private UserDto insertUser(Consumer<UserDto> populateUserDto) {
+ UserDto user = db.users().insertUser(populateUserDto);
+ return user;
+ }
+}
GroupDto group3 = db.users().insertGroup("Group-3");
PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER, template.getName(), group1.getName());
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN, template.getName(), group1.getName());
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING, template.getName(), group2.getName());
PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
- permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);
+ permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER, anotherTemplate.getName(), null);
+ permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING, anotherTemplate.getName(), group1.getName());
assertThat(selectGroupNamesByQueryAndTemplate(builder(), template))
.containsOnly("Group-1", "Group-2", "Group-3", "Anyone");
GroupDto group = db.users().insertGroup("Group");
PermissionTemplateDto otherTemplate = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(otherTemplate.getUuid(), group.getUuid(), USER);
+ permissionTemplateDbTester.addGroupToTemplate(otherTemplate.getUuid(), group.getUuid(), USER, otherTemplate.getName(), group.getName());
assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("nyo"), template))
.containsExactly("Anyone");
GroupDto group3 = db.users().insertGroup("Group-3");
PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER, template.getName(), group1.getName());
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN, template.getName(), group1.getName());
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING, template.getName(), group2.getName());
PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
- permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);
+ permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER, anotherTemplate.getName(), null);
+ permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING, anotherTemplate.getName(), group1.getName());
assertThat(countGroupNamesByQueryAndTemplate(builder(), template))
.isEqualTo(4);
GroupDto group3 = db.users().insertGroup(newGroupDto().setName("Group-3"));
PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER, template.getName(), group1.getName());
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN, template.getName(), group1.getName());
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING, template.getName(), group2.getName());
PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
- permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);
+ permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER, anotherTemplate.getName(), null);
+ permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING, anotherTemplate.getName(), group1.getName());
assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getUuid(), asList("Group-1")))
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
GroupDto group3 = db.users().insertGroup(newGroupDto().setName("Group-3"));
PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
- permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER, template.getName(), group1.getName());
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN, template.getName(), group1.getName());
+ permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING, template.getName(), group2.getName());
PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
- permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
- permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);
+ permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER, anotherTemplate.getName(), null);
+ permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING, anotherTemplate.getName(), group1.getName());
assertThat(underTest.selectGroupPermissionsByTemplateUuid(session, template.getUuid()))
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
@Test
public void selectByTemplateId_filter_by_template_uuid() {
PermissionTemplateCharacteristicDto templatePermission1 = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid1")
- .setPermission(UserRole.ADMIN)
- .setTemplateUuid("1")
- .setWithProjectCreator(true)
- .setCreatedAt(1_000_000_000L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid1")
+ .setPermission(UserRole.ADMIN)
+ .setTemplateUuid("1")
+ .setWithProjectCreator(true)
+ .setCreatedAt(1_000_000_000L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
PermissionTemplateCharacteristicDto templatePermission2 = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid2")
- .setPermission(UserRole.USER)
- .setTemplateUuid("2")
- .setWithProjectCreator(false)
- .setCreatedAt(1_000_000_000L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid2")
+ .setPermission(UserRole.USER)
+ .setTemplateUuid("2")
+ .setWithProjectCreator(false)
+ .setCreatedAt(1_000_000_000L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
PermissionTemplateCharacteristicDto templatePermission3 = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid3")
- .setPermission(UserRole.USER)
- .setTemplateUuid("3")
- .setWithProjectCreator(false)
- .setCreatedAt(1_000_000_001L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid3")
+ .setPermission(UserRole.USER)
+ .setTemplateUuid("3")
+ .setWithProjectCreator(false)
+ .setCreatedAt(1_000_000_001L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
PermissionTemplateCharacteristicDto templatePermissionForAnotherTemplate = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid4")
- .setPermission(UserRole.ADMIN)
- .setTemplateUuid("42")
- .setWithProjectCreator(true)
- .setCreatedAt(1_000_000_000L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid4")
+ .setPermission(UserRole.ADMIN)
+ .setTemplateUuid("42")
+ .setWithProjectCreator(true)
+ .setCreatedAt(1_000_000_000L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
List<PermissionTemplateCharacteristicDto> result = underTest.selectByTemplateUuids(dbSession, newArrayList("1", "2", "3"));
assertThat(result)
@Test
public void selectByPermissionAndTemplateId() {
PermissionTemplateCharacteristicDto templatePermission1 = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid1")
- .setPermission(UserRole.ADMIN)
- .setTemplateUuid("1")
- .setWithProjectCreator(true)
- .setCreatedAt(1_000_000_000L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid1")
+ .setPermission(UserRole.ADMIN)
+ .setTemplateUuid("1")
+ .setWithProjectCreator(true)
+ .setCreatedAt(1_000_000_000L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid2")
- .setPermission(UserRole.USER)
- .setTemplateUuid("1")
- .setWithProjectCreator(false)
- .setCreatedAt(1_000_000_000L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid2")
+ .setPermission(UserRole.USER)
+ .setTemplateUuid("1")
+ .setWithProjectCreator(false)
+ .setCreatedAt(1_000_000_000L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid3")
- .setPermission(UserRole.ADMIN)
- .setTemplateUuid("42")
- .setWithProjectCreator(true)
- .setCreatedAt(1_000_000_000L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid3")
+ .setPermission(UserRole.ADMIN)
+ .setTemplateUuid("42")
+ .setWithProjectCreator(true)
+ .setCreatedAt(1_000_000_000L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
Optional<PermissionTemplateCharacteristicDto> result = underTest.selectByPermissionAndTemplateId(dbSession, UserRole.ADMIN, "1");
@Test
public void insert() {
PermissionTemplateCharacteristicDto expectedResult = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid")
- .setPermission(UserRole.USER)
- .setTemplateUuid("1")
- .setWithProjectCreator(true)
- .setCreatedAt(123_456_789L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid")
+ .setPermission(UserRole.USER)
+ .setTemplateUuid("1")
+ .setWithProjectCreator(true)
+ .setCreatedAt(123_456_789L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
PermissionTemplateCharacteristicDto result = dbSession.getMapper(PermissionTemplateCharacteristicMapper.class).selectByUuid(expectedResult.getUuid());
assertThat(result.getUuid()).isEqualTo("uuid");
@Test
public void update_only_change_with_project_creator_and_updated_at() {
PermissionTemplateCharacteristicDto insertedDto = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid")
- .setPermission(UserRole.USER)
- .setTemplateUuid("1")
- .setWithProjectCreator(true)
- .setCreatedAt(123_456_789L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid")
+ .setPermission(UserRole.USER)
+ .setTemplateUuid("1")
+ .setWithProjectCreator(true)
+ .setCreatedAt(123_456_789L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
underTest.update(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid")
- .setPermission("PERMISSION_ARE_NOT_UPDATABLE")
- .setTemplateUuid("42")
- .setCreatedAt(42L)
- .setWithProjectCreator(false)
- .setUpdatedAt(3_000_000_000L));
+ .setUuid("uuid")
+ .setPermission("PERMISSION_ARE_NOT_UPDATABLE")
+ .setTemplateUuid("42")
+ .setCreatedAt(42L)
+ .setWithProjectCreator(false)
+ .setUpdatedAt(3_000_000_000L),
+ "template");
PermissionTemplateCharacteristicDto result = underTest.selectByPermissionAndTemplateId(dbSession, insertedDto.getPermission(), insertedDto.getTemplateUuid()).get();
assertThat(result).extracting("uuid", "permission", "templateUuid", "createdAt")
.setTemplateUuid("1")
.setWithProjectCreator(true)
.setUpdatedAt(2_000_000_000L);
- assertThatThrownBy(() -> underTest.insert(dbSession, characteristicDto))
+ assertThatThrownBy(() -> underTest.insert(dbSession, characteristicDto, "template"))
.isInstanceOf(IllegalArgumentException.class);
}
.setTemplateUuid("1")
.setWithProjectCreator(true)
.setCreatedAt(2_000_000_000L);
- assertThatThrownBy(() -> underTest.insert(dbSession, characteristicDto))
+ assertThatThrownBy(() -> underTest.insert(dbSession, characteristicDto, "template"))
.isInstanceOf(IllegalArgumentException.class);
}
.setWithProjectCreator(true)
.setCreatedAt(123_456_789L)
.setUpdatedAt(2_000_000_000L);
- assertThatThrownBy(() -> underTest.update(dbSession, characteristicDto))
+ assertThatThrownBy(() -> underTest.update(dbSession, characteristicDto, "template"))
.isInstanceOf(NullPointerException.class);
}
@Test
public void delete_by_permission_template_uuid() {
underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid1")
- .setPermission(UserRole.USER)
- .setTemplateUuid("1")
- .setWithProjectCreator(true)
- .setCreatedAt(123_456_789L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid1")
+ .setPermission(UserRole.USER)
+ .setTemplateUuid("1")
+ .setWithProjectCreator(true)
+ .setCreatedAt(123_456_789L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid("uuid2")
- .setPermission(UserRole.USER)
- .setTemplateUuid("2")
- .setWithProjectCreator(true)
- .setCreatedAt(123_456_789L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid("uuid2")
+ .setPermission(UserRole.USER)
+ .setTemplateUuid("2")
+ .setWithProjectCreator(true)
+ .setCreatedAt(123_456_789L)
+ .setUpdatedAt(2_000_000_000L),
+ "template");
assertThat(underTest.selectByTemplateUuids(dbSession, singletonList("1"))).hasSize(1);
assertThat(underTest.selectByTemplateUuids(dbSession, asList("1", "2"))).hasSize(2);
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.permission.template;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.api.web.UserRole;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class PermissionTemplateCharacteristicDaoWithPersisterTest {
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+ @Rule
+ public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+ private final DbSession session = db.getSession();
+ private final PermissionTemplateCharacteristicDao underTest = db.getDbClient().permissionTemplateCharacteristicDao();
+ private final ArgumentCaptor<PermissionTemplateNewValue> newValueCaptor = ArgumentCaptor.forClass(PermissionTemplateNewValue.class);
+
+ @Test
+ public void insertPermissionTemplateCharacteristicIsPersisted() {
+ PermissionTemplateCharacteristicDto dto = getPermissionTemplateCharacteristic(UserRole.USER);
+ underTest.insert(session, dto, "template");
+
+ verify(auditPersister).addCharacteristicToPermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::isWithProjectCreator)
+ .containsExactly(dto.getTemplateUuid(), "template", dto.getPermission(), dto.getWithProjectCreator());
+ assertThat(newValue.toString()).contains("withProjectCreator");
+ }
+
+ @Test
+ public void updatePermissionTemplateCharacteristicIsPersisted() {
+ underTest.insert(session, getPermissionTemplateCharacteristic(UserRole.USER),
+ "template");
+ PermissionTemplateCharacteristicDto updated = getPermissionTemplateCharacteristic(UserRole.ADMIN);
+ underTest.update(session, updated, "template");
+
+ verify(auditPersister).updateCharacteristicInPermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::isWithProjectCreator)
+ .containsExactly(updated.getTemplateUuid(), "template", updated.getPermission(), updated.getWithProjectCreator());
+ assertThat(newValue.toString()).contains("withProjectCreator");
+ }
+
+ private PermissionTemplateCharacteristicDto getPermissionTemplateCharacteristic(String role) {
+ return new PermissionTemplateCharacteristicDto()
+ .setUuid("uuid")
+ .setPermission(role)
+ .setTemplateUuid("1")
+ .setWithProjectCreator(true)
+ .setCreatedAt(123_456_789L)
+ .setUpdatedAt(2_000_000_000L);
+ }
+}
templateDb.addGroupToTemplate(permissionTemplate1, group2, "user");
templateDb.addAnyoneToTemplate(permissionTemplate1, "admin");
templateDb.addAnyoneToTemplate(permissionTemplate2, "admin");
- templateDb.addProjectCreatorToTemplate(permissionTemplate1.getUuid(), "user");
- templateDb.addProjectCreatorToTemplate(permissionTemplate2.getUuid(), "user");
+ templateDb.addProjectCreatorToTemplate(permissionTemplate1.getUuid(), "user", permissionTemplate1.getName());
+ templateDb.addProjectCreatorToTemplate(permissionTemplate2.getUuid(), "user", permissionTemplate2.getName());
- underTest.deleteByUuid(dbSession, permissionTemplate1.getUuid());
+ underTest.deleteByUuid(dbSession, permissionTemplate1.getUuid(), permissionTemplate1.getName());
dbSession.commit();
assertThat(underTest.selectAll(db.getSession(), null))
PermissionTemplateDto permissionTemplate = templateDb.insertTemplate();
UserDto user = db.users().insertUser();
- underTest.insertUserPermission(dbSession, permissionTemplate.getUuid(), user.getUuid(), "user");
+ underTest.insertUserPermission(dbSession, permissionTemplate.getUuid(), user.getUuid(), "user", permissionTemplate.getName(), user.getLogin());
assertThat(db.getDbClient().permissionTemplateDao().selectUserPermissionsByTemplateId(db.getSession(), permissionTemplate.getUuid()))
.extracting(PermissionTemplateUserDto::getTemplateUuid, PermissionTemplateUserDto::getUserUuid, PermissionTemplateUserDto::getPermission,
templateDb.addUserToTemplate(permissionTemplate, user1, "admin");
templateDb.addUserToTemplate(permissionTemplate, user2, "user");
- underTest.deleteUserPermission(dbSession, permissionTemplate.getUuid(), user1.getUuid(), "user");
+ underTest.deleteUserPermission(dbSession, permissionTemplate.getUuid(), user1.getUuid(), "user", permissionTemplate.getName(), user1.getLogin());
assertThat(db.getDbClient().permissionTemplateDao().selectUserPermissionsByTemplateId(db.getSession(), permissionTemplate.getUuid()))
.extracting(PermissionTemplateUserDto::getUserUuid, PermissionTemplateUserDto::getPermission)
PermissionTemplateDto permissionTemplate = templateDb.insertTemplate();
GroupDto group = db.users().insertGroup();
- underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), group.getUuid(), "user");
+ underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), group.getUuid(), "user", permissionTemplate.getName(), group.getName());
dbSession.commit();
assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
templateDb.addGroupToTemplate(permissionTemplate, group1, "admin");
templateDb.addGroupToTemplate(permissionTemplate, group2, "user");
- underTest.deleteByGroup(db.getSession(), group1.getUuid());
+ underTest.deleteByGroup(db.getSession(), group1.getUuid(), group1.getName());
db.getSession().commit();
assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
public void add_group_permission_to_anyone() {
PermissionTemplateDto permissionTemplate = templateDb.insertTemplate();
- underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), null, "user");
+ underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), null, "user", permissionTemplate.getName(), null);
dbSession.commit();
assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
GroupDto group1 = db.users().insertGroup(newGroupDto());
GroupDto group2 = db.users().insertGroup(newGroupDto());
GroupDto group3 = db.users().insertGroup(newGroupDto());
- templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), CODEVIEWER);
- templateDb.addGroupToTemplate(template1.getUuid(), group2.getUuid(), CODEVIEWER);
- templateDb.addGroupToTemplate(template1.getUuid(), group3.getUuid(), CODEVIEWER);
- templateDb.addGroupToTemplate(template1.getUuid(), null, CODEVIEWER);
- templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), ADMIN);
- templateDb.addGroupToTemplate(template2.getUuid(), group1.getUuid(), ADMIN);
- templateDb.addGroupToTemplate(template4.getUuid(), group1.getUuid(), ISSUE_ADMIN);
+ templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), CODEVIEWER, template1.getName(), group1.getName());
+ templateDb.addGroupToTemplate(template1.getUuid(), group2.getUuid(), CODEVIEWER, template1.getName(), group2.getName());
+ templateDb.addGroupToTemplate(template1.getUuid(), group3.getUuid(), CODEVIEWER, template1.getName(), group3.getName());
+ templateDb.addGroupToTemplate(template1.getUuid(), null, CODEVIEWER, template1.getName(), null);
+ templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), ADMIN, template1.getName(), group1.getName());
+ templateDb.addGroupToTemplate(template2.getUuid(), group1.getUuid(), ADMIN, template2.getName(), group1.getName());
+ templateDb.addGroupToTemplate(template4.getUuid(), group1.getUuid(), ISSUE_ADMIN, template4.getName(), group1.getName());
final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
underTest.groupsCountByTemplateUuidAndPermission(dbSession, asList(template1.getUuid(), template2.getUuid(), template3.getUuid()),
UserDto user2 = db.users().insertUser();
UserDto user3 = db.users().insertUser();
- templateDb.addUserToTemplate(template1.getUuid(), user1.getUuid(), ADMIN);
- templateDb.addUserToTemplate(template1.getUuid(), user2.getUuid(), ADMIN);
- templateDb.addUserToTemplate(template1.getUuid(), user3.getUuid(), ADMIN);
- templateDb.addUserToTemplate(template1.getUuid(), user1.getUuid(), USER);
- templateDb.addUserToTemplate(template2.getUuid(), user1.getUuid(), USER);
- templateDb.addUserToTemplate(anotherTemplate.getUuid(), user1.getUuid(), ISSUE_ADMIN);
+ templateDb.addUserToTemplate(template1.getUuid(), user1.getUuid(), ADMIN, template1.getName(), user1.getLogin());
+ templateDb.addUserToTemplate(template1.getUuid(), user2.getUuid(), ADMIN, template1.getName(), user2.getLogin());
+ templateDb.addUserToTemplate(template1.getUuid(), user3.getUuid(), ADMIN, template1.getName(), user3.getLogin());
+ templateDb.addUserToTemplate(template1.getUuid(), user1.getUuid(), USER, template1.getName(), user1.getLogin());
+ templateDb.addUserToTemplate(template2.getUuid(), user1.getUuid(), USER, template2.getName(), user1.getLogin());
+ templateDb.addUserToTemplate(anotherTemplate.getUuid(), user1.getUuid(), ISSUE_ADMIN, anotherTemplate.getName(), user1.getLogin());
final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
underTest.usersCountByTemplateUuidAndPermission(dbSession, asList(template1.getUuid(), template2.getUuid(), template3.getUuid()),
GroupDto group = db.users().insertGroup(newGroupDto());
db.users().insertMember(group, user);
PermissionTemplateDto template = templateDb.insertTemplate();
- templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN_EXECUTION);
- templateDb.addProjectCreatorToTemplate(template.getUuid(), UserRole.ADMIN);
- templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER);
- templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.ADMIN);
- templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER);
- templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.ADMIN);
- templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN);
+ templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN_EXECUTION, template.getName());
+ templateDb.addProjectCreatorToTemplate(template.getUuid(), UserRole.ADMIN, template.getName());
+ templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER, template.getName(), user.getLogin());
+ templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.ADMIN, template.getName(), user.getLogin());
+ templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER, template.getName(), group.getName());
+ templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.ADMIN, template.getName(), group.getName());
+ templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN, template.getName(), null);
List<String> resultWithUser = underTest.selectPotentialPermissionsByUserUuidAndTemplateUuid(dbSession, user.getUuid(), template.getUuid());
List<String> resultWithoutUser = underTest.selectPotentialPermissionsByUserUuidAndTemplateUuid(dbSession, null, template.getUuid());
UserDto anotherUser = db.users().insertUser();
PermissionTemplateDto template = db.permissionTemplates().insertTemplate();
String permission = "PERMISSION";
- db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), permission);
- db.permissionTemplates().addUserToTemplate(template.getUuid(), anotherUser.getUuid(), permission);
+ db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), permission, template.getName(), user.getLogin());
+ db.permissionTemplates().addUserToTemplate(template.getUuid(), anotherUser.getUuid(), permission, template.getName(), anotherUser.getLogin());
- underTest.deleteUserPermissionsByUserUuid(dbSession, user.getUuid());
+ underTest.deleteUserPermissionsByUserUuid(dbSession, user.getUuid(), user.getLogin());
db.commit();
assertThat(db.select("select template_uuid as \"templateUuid\", user_uuid as \"userUuid\", permission_reference as \"permission\" from perm_templates_users"))
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.permission.template;
+
+import java.util.Date;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
+import org.sonar.db.user.GroupDto;
+import org.sonar.db.user.UserDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.sonar.api.web.UserRole.ADMIN;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.user.GroupTesting.newGroupDto;
+
+public class PermissionTemplateDaoWithPersisterTest {
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+ private static final Date PAST = new Date(100_000_000_000L);
+ private static final Date NOW = new Date(500_000_000_000L);
+
+ @Rule
+ public final DbTester db = DbTester.create(auditPersister);
+ private final DbSession session = db.getSession();
+
+ private final ArgumentCaptor<PermissionTemplateNewValue> newValueCaptor = ArgumentCaptor.forClass(PermissionTemplateNewValue.class);
+ private final PermissionTemplateDao underTest = db.getDbClient().permissionTemplateDao();
+
+ @Test
+ public void insertPermissionTemplateIsPersisted() {
+ PermissionTemplateDto dto = insertPermissionTemplate();
+
+ verify(auditPersister).addPermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName)
+ .containsExactly(dto.getUuid(), dto.getName());
+ assertThat(newValue.toString()).doesNotContain("keyPattern");
+ }
+
+ @Test
+ public void updatePermissionTemplateIsPersisted() {
+ PermissionTemplateDto dto = insertPermissionTemplate();
+ underTest.update(session, dto);
+
+ verify(auditPersister).updatePermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getDescription, PermissionTemplateNewValue::getKeyPattern)
+ .containsExactly(dto.getUuid(), dto.getName(), dto.getDescription(), dto.getKeyPattern());
+ assertThat(newValue.toString()).contains("keyPattern");
+ }
+
+ @Test
+ public void deletePermissionTemplateIsPersisted() {
+ PermissionTemplateDto dto = insertPermissionTemplate();
+ underTest.deleteByUuid(session, dto.getUuid(), dto.getName());
+
+ verify(auditPersister).deletePermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName)
+ .containsExactly(dto.getUuid(), dto.getName());
+ assertThat(newValue.toString()).doesNotContain("keyPattern");
+ }
+
+ @Test
+ public void insertAndDeleteUserPermissionToTemplateIsPersisted() {
+ PermissionTemplateDto dto = insertPermissionTemplate();
+ UserDto user = db.users().insertUser();
+ underTest.insertUserPermission(session, dto.getUuid(), user.getUuid(), ADMIN, dto.getName(), user.getLogin());
+
+ verify(auditPersister).addUserToPermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getUserUuid, PermissionTemplateNewValue::getUserLogin)
+ .containsExactly(dto.getUuid(), dto.getName(), ADMIN, user.getUuid(), user.getLogin());
+ assertThat(newValue.toString()).doesNotContain("groupUuid");
+
+ underTest.deleteUserPermission(session, dto.getUuid(), user.getUuid(), ADMIN, dto.getName(), user.getLogin());
+
+ verify(auditPersister).deleteUserFromPermissionTemplate(eq(session), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getUserUuid, PermissionTemplateNewValue::getUserLogin)
+ .containsExactly(dto.getUuid(), dto.getName(), ADMIN, user.getUuid(), user.getLogin());
+ assertThat(newValue.toString()).doesNotContain("groupUuid");
+ }
+
+ @Test
+ public void insertAndDeleteUserPermissionByUserUuidToTemplateIsPersisted() {
+ PermissionTemplateDto dto = insertPermissionTemplate();
+ UserDto user = db.users().insertUser();
+ underTest.insertUserPermission(session, dto.getUuid(), user.getUuid(), ADMIN, dto.getName(), user.getLogin());
+ underTest.deleteUserPermissionsByUserUuid(session, user.getUuid(), user.getLogin());
+
+ verify(auditPersister).deleteUserFromPermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getUserUuid, PermissionTemplateNewValue::getUserLogin)
+ .containsExactly(null, null, null, user.getUuid(), user.getLogin());
+ assertThat(newValue.toString()).doesNotContain("groupUuid");
+ }
+
+ @Test
+ public void insertAndDeleteGroupPermissionToTemplateIsPersisted() {
+ PermissionTemplateDto dto = insertPermissionTemplate();
+ GroupDto group = db.users().insertGroup(newGroupDto());
+ underTest.insertGroupPermission(session, dto.getUuid(), group.getUuid(), ADMIN, dto.getName(), group.getName());
+
+ verify(auditPersister).addGroupToPermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getGroupUuid, PermissionTemplateNewValue::getGroupName)
+ .containsExactly(dto.getUuid(), dto.getName(), ADMIN, group.getUuid(), group.getName());
+ assertThat(newValue.toString()).contains("groupUuid");
+
+ underTest.deleteGroupPermission(session, dto.getUuid(), group.getUuid(), ADMIN, dto.getName(), group.getName());
+
+ verify(auditPersister).deleteGroupFromPermissionTemplate(eq(session), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getGroupUuid, PermissionTemplateNewValue::getGroupName)
+ .containsExactly(dto.getUuid(), dto.getName(), ADMIN, group.getUuid(), group.getName());
+ assertThat(newValue.toString()).contains("groupUuid");
+ }
+
+ @Test
+ public void insertAndDeleteGroupPermissionByGroupUuidToTemplateIsPersisted() {
+ PermissionTemplateDto templateDto = insertPermissionTemplate();
+ PermissionTemplateGroupDto templateGroupDto = new PermissionTemplateGroupDto()
+ .setUuid(Uuids.createFast())
+ .setGroupName("group")
+ .setPermission(ADMIN)
+ .setTemplateUuid(templateDto.getUuid())
+ .setCreatedAt(new Date())
+ .setUpdatedAt(new Date());
+ underTest.insertGroupPermission(session, templateGroupDto, templateDto.getName());
+
+ verify(auditPersister).addGroupToPermissionTemplate(eq(session), newValueCaptor.capture());
+ PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getGroupUuid, PermissionTemplateNewValue::getGroupName)
+ .containsExactly(templateDto.getUuid(), templateDto.getName(), ADMIN, templateGroupDto.getGroupUuid(), templateGroupDto.getGroupName());
+ assertThat(newValue.toString()).doesNotContain("userUuid");
+
+ underTest.deleteByGroup(session, templateGroupDto.getGroupUuid(), templateGroupDto.getGroupName());
+
+ verify(auditPersister).deleteGroupFromPermissionTemplate(eq(session), newValueCaptor.capture());
+ newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+ PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getGroupUuid, PermissionTemplateNewValue::getGroupName)
+ .containsExactly(null, null, null, templateGroupDto.getGroupUuid(), templateGroupDto.getGroupName());
+ assertThat(newValue.toString()).doesNotContain("userUuid");
+ }
+
+ private PermissionTemplateDto insertPermissionTemplate() {
+ return underTest.insert(session, newPermissionTemplateDto()
+ .setUuid("ABCD")
+ .setName("my template")
+ .setDescription("my description")
+ .setKeyPattern("myregexp")
+ .setCreatedAt(PAST)
+ .setUpdatedAt(NOW));
+ }
+}
UserDto user1 = db.users().insertUser(u -> u.setName("A"));
UserDto user2 = db.users().insertUser(u -> u.setName("B"));
UserDto user3 = db.users().insertUser(u -> u.setName("C"));
- db.permissionTemplates().addUserToTemplate(template.getUuid(), user3.getUuid(), UserRole.USER);
+ db.permissionTemplates().addUserToTemplate(template.getUuid(), user3.getUuid(), UserRole.USER, template.getName(), user3.getLogin());
PermissionQuery query = PermissionQuery.builder().build();
assertThat(underTest.selectUserLoginsByQueryAndTemplate(db.getSession(), query, template.getUuid()))
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.plugin;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PluginNewValue;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.sonar.db.plugin.PluginDto.Type.EXTERNAL;
+
+public class PluginDaoWithPersisterTest {
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+ @Rule
+ public final ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+
+ private final ArgumentCaptor<PluginNewValue> newValueCaptor = ArgumentCaptor.forClass(PluginNewValue.class);
+ private final DbSession session = db.getSession();
+
+ private PluginDao underTest = db.getDbClient().pluginDao();
+
+ @Test
+ public void insert() {
+ PluginDto dto = getPluginDto();
+ underTest.insert(session, dto);
+
+ verify(auditPersister).addPlugin(eq(session), newValueCaptor.capture());
+ PluginNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PluginNewValue::getPluginUuid, PluginNewValue::getKee,
+ PluginNewValue::getBasePluginKey, PluginNewValue::getType)
+ .containsExactly(dto.getUuid(), dto.getKee(), dto.getBasePluginKey(), dto.getType().name());
+ assertThat(newValue.toString()).contains("pluginUuid");
+ }
+
+ @Test
+ public void update() {
+ PluginDto dto = getPluginDto();
+ underTest.update(session, dto);
+
+ verify(auditPersister).updatePlugin(eq(session), newValueCaptor.capture());
+ PluginNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PluginNewValue::getPluginUuid, PluginNewValue::getKee,
+ PluginNewValue::getBasePluginKey, PluginNewValue::getType)
+ .containsExactly(dto.getUuid(), dto.getKee(), dto.getBasePluginKey(), dto.getType().name());
+ assertThat(newValue.toString()).contains("pluginUuid");
+ }
+
+ private PluginDto getPluginDto() {
+ return new PluginDto()
+ .setUuid("plugin_uuid")
+ .setKee("plugin_kee")
+ .setBasePluginKey("plugin_base_key")
+ .setFileHash("plugin_file_hash")
+ .setType(EXTERNAL)
+ .setCreatedAt(1L)
+ .setUpdatedAt(2L);
+ }
+}
UserDto user1 = db.users().insertUser(u -> u.setLogin("user1"));
UserDto user2 = db.users().insertUser(u -> u.setLogin("user2"));
UserDto user3 = db.users().insertUser(u -> u.setLogin("user3"));
- insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getUuid());
- insertProperty("notification.NewViolations.Twitter", "true", null, user3.getUuid());
- insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getUuid());
- insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getUuid());
- insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getUuid());
+ insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getUuid(), user2.getLogin(), project1.name());
+ insertProperty("notification.NewViolations.Twitter", "true", null, user3.getUuid(), user3.getLogin(), null);
+ insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getUuid(), user1.getLogin(), project2.name());
+ insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getUuid(), user2.getLogin(), project1.name());
+ insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getUuid(), user3.getLogin(), project2.name());
db.users().insertProjectPermissionOnUser(user2, UserRole.USER, project1);
db.users().insertProjectPermissionOnUser(user3, UserRole.USER, project2);
db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project2);
@Test
public void hasNotificationSubscribers() {
- String userUuid1 = db.users().insertUser(u -> u.setLogin("user1")).getUuid();
- String userUuid2 = db.users().insertUser(u -> u.setLogin("user2")).getUuid();
+ UserDto user1 = db.users().insertUser(u -> u.setLogin("user1"));
+ UserDto user2 = db.users().insertUser(u -> u.setLogin("user2"));
String projectUuid = randomAlphabetic(8);
+ String projectName = randomAlphabetic(4);
db.components().insertPrivateProject(projectUuid);
// global subscription
- insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userUuid2);
+ insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null,
+ user2.getUuid(), user2.getLogin(), null);
// project subscription
- insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectUuid, userUuid1);
- insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", "uuid56", userUuid1);
- insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectUuid, userUuid1);
+ insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectUuid, user1.getUuid(),
+ user1.getLogin(), projectName);
+ insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", "uuid56", user1.getUuid(),
+ user1.getLogin(), projectName);
+ insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectUuid, user1.getUuid(),
+ user1.getLogin(), projectName);
// global subscription
- insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, userUuid2);
+ insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, user2.getUuid(),
+ user2.getLogin(), null);
// Nobody is subscribed
assertThat(underTest.hasProjectNotificationSubscribersForDispatchers(projectUuid, singletonList("NotSexyDispatcher")))
@Test
public void findEmailRecipientsForNotification_finds_only_globally_subscribed_users_if_projectKey_is_null() {
- String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
- String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid();
- String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
- String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid();
- String projectUuid = insertPrivateProject("PROJECT_A").uuid();
+ UserDto user1 = db.users().insertUser(withEmail("user1"));
+ UserDto user2 = db.users().insertUser(withEmail("user2"));
+ UserDto user3 = db.users().insertUser(withEmail("user3"));
+ UserDto user4 = db.users().insertUser(withEmail("user4"));
+ ComponentDto project = insertPrivateProject("PROJECT_A");
String dispatcherKey = randomAlphabetic(5);
String otherDispatcherKey = randomAlphabetic(6);
String channelKey = randomAlphabetic(7);
String otherChannelKey = randomAlphabetic(8);
// user1 subscribed only globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
// user2 subscribed on project and globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
// user3 subscribed on project only
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name());
// user4 did not subscribe
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name());
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null))
.containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user2", true, emailOf("user2")));
@Test
public void findEmailRecipientsForNotification_with_logins_finds_only_globally_subscribed_specified_users_if_projectKey_is_null() {
- String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
- String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid();
- String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
- String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid();
- String projectUuid = insertPrivateProject("PROJECT_A").uuid();
+ UserDto user1 = db.users().insertUser(withEmail("user1"));
+ UserDto user2 = db.users().insertUser(withEmail("user2"));
+ UserDto user3 = db.users().insertUser(withEmail("user3"));
+ UserDto user4 = db.users().insertUser(withEmail("user4"));
+ ComponentDto project = insertPrivateProject("PROJECT_A");
String dispatcherKey = randomAlphabetic(5);
String otherDispatcherKey = randomAlphabetic(6);
String channelKey = randomAlphabetic(7);
String otherChannelKey = randomAlphabetic(8);
// user1 subscribed only globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
// user2 subscribed on project and globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
// user3 subscribed on project only
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name());
// user4 did not subscribe
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name());
Set<String> allLogins = of("user1", "user2", "user3", "user4");
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, allLogins))
@Test
public void findEmailRecipientsForNotification_finds_global_and_project_subscribed_users_when_projectKey_is_non_null() {
- String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
- String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid();
- String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
- String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid();
+ UserDto user1 = db.users().insertUser(withEmail("user1"));
+ UserDto user2 = db.users().insertUser(withEmail("user2"));
+ UserDto user3 = db.users().insertUser(withEmail("user3"));
+ UserDto user4 = db.users().insertUser(withEmail("user4"));
String projectKey = randomAlphabetic(3);
String otherProjectKey = randomAlphabetic(4);
- String projectUuid = insertPrivateProject(projectKey).uuid();
+ ComponentDto project = insertPrivateProject(projectKey);
String dispatcherKey = randomAlphabetic(5);
String otherDispatcherKey = randomAlphabetic(6);
String channelKey = randomAlphabetic(7);
String otherChannelKey = randomAlphabetic(8);
// user1 subscribed only globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
// user2 subscribed on project and globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
// user3 subscribed on project only
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name());
// user4 did not subscribe
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name());
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey))
.containsOnly(
@Test
public void findEmailRecipientsForNotification_with_logins_finds_global_and_project_subscribed_specified_users_when_projectKey_is_non_null() {
- String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
- String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid();
- String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
- String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid();
+ UserDto user1 = db.users().insertUser(withEmail("user1"));
+ UserDto user2 = db.users().insertUser(withEmail("user2"));
+ UserDto user3 = db.users().insertUser(withEmail("user3"));
+ UserDto user4 = db.users().insertUser(withEmail("user4"));
String projectKey = randomAlphabetic(3);
String otherProjectKey = randomAlphabetic(4);
- String projectUuid = insertPrivateProject(projectKey).uuid();
+ ComponentDto project = insertPrivateProject(projectKey);
String dispatcherKey = randomAlphabetic(5);
String otherDispatcherKey = randomAlphabetic(6);
String channelKey = randomAlphabetic(7);
String otherChannelKey = randomAlphabetic(8);
// user1 subscribed only globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
// user2 subscribed on project and globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
// user3 subscribed on project only
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name());
// user4 did not subscribe
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name());
Set<String> allLogins = of("user1", "user2", "user3", "user4");
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins))
@Test
public void findEmailRecipientsForNotification_ignores_subscribed_users_without_email() {
- String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
- String userUuid2 = db.users().insertUser(noEmail("user2")).getUuid();
- String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
- String userUuid4 = db.users().insertUser(noEmail("user4")).getUuid();
+ UserDto user1 = db.users().insertUser(withEmail("user1"));
+ UserDto user2 = db.users().insertUser(noEmail("user2"));
+ UserDto user3 = db.users().insertUser(withEmail("user3"));
+ UserDto user4 = db.users().insertUser(noEmail("user4"));
String projectKey = randomAlphabetic(3);
- String projectUuid = insertPrivateProject(projectKey).uuid();
+ ComponentDto project = insertPrivateProject(projectKey);
String dispatcherKey = randomAlphabetic(4);
String channelKey = randomAlphabetic(5);
// user1 and user2 subscribed on project and globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid1);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user1.getUuid(), user1.getLogin(), project.name());
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
// user3 and user4 subscribed only globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid3);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user3.getUuid(), user3.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user4.getUuid(), user4.getLogin(), null);
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey))
.containsOnly(
@Test
public void findEmailRecipientsForNotification_with_logins_ignores_subscribed_users_without_email() {
- String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
- String userUuid2 = db.users().insertUser(noEmail("user2")).getUuid();
- String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
- String userUuid4 = db.users().insertUser(noEmail("user4")).getUuid();
+ UserDto user1 = db.users().insertUser(withEmail("user1"));
+ UserDto user2 = db.users().insertUser(noEmail("user2"));
+ UserDto user3 = db.users().insertUser(withEmail("user3"));
+ UserDto user4 = db.users().insertUser(noEmail("user4"));
Set<String> allLogins = of("user1", "user2", "user3");
String projectKey = randomAlphabetic(3);
- String projectUuid = insertPrivateProject(projectKey).uuid();
+ ComponentDto project = insertPrivateProject(projectKey);
String dispatcherKey = randomAlphabetic(4);
String channelKey = randomAlphabetic(5);
// user1 and user2 subscribed on project and globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid1);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user1.getUuid(), user1.getLogin(), project.name());
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
// user3 and user4 subscribed only globally
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid3);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user3.getUuid(), user3.getLogin(), null);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user4.getUuid(), user4.getLogin(), null);
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins))
.containsOnly(
@Test
public void selectGlobalProperties() {
// global
- insertProperty("global.one", "one", null, null);
- insertProperty("global.two", "two", null, null);
+ insertProperty("global.one", "one", null, null, null, null);
+ insertProperty("global.two", "two", null, null, null, null);
List<PropertyDto> properties = underTest.selectGlobalProperties();
assertThat(properties.size())
@Test
@UseDataProvider("allValuesForSelect")
public void selectGlobalProperties_supports_all_values(String dbValue, String expected) {
- insertProperty("global.one", dbValue, null, null);
+ insertProperty("global.one", dbValue, null, null, null, null);
List<PropertyDto> dtos = underTest.selectGlobalProperties();
assertThat(dtos)
@Test
public void selectGlobalProperty() {
// global
- insertProperty("global.one", "one", null, null);
- insertProperty("global.two", "two", null, null);
+ insertProperty("global.one", "one", null, null, null, null);
+ insertProperty("global.two", "two", null, null, null, null);
// project
- insertProperty("project.one", "one", "uuid10", null);
+ insertProperty("project.one", "one", "uuid10", null, null, "component");
// user
- insertProperty("user.one", "one", null, "100");
+ insertProperty("user.one", "one", null, "100", "login", null);
assertThat(underTest.selectGlobalProperty("global.one"))
.extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue)
@Test
@UseDataProvider("allValuesForSelect")
public void selectGlobalProperty_supports_all_values(String dbValue, String expected) {
- insertProperty("global.one", dbValue, null, null);
+ insertProperty("global.one", dbValue, null, null, null, null);
assertThat(underTest.selectGlobalProperty("global.one"))
.extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue)
ComponentDto projectDto = insertPrivateProject("A");
String projectUuid = projectDto.uuid();
// global
- insertProperty("global.one", "one", null, null);
- insertProperty("global.two", "two", null, null);
+ insertProperty("global.one", "one", null, null, null, null);
+ insertProperty("global.two", "two", null, null, null, null);
// project
- insertProperty("project.one", "Pone", projectUuid, null);
- insertProperty("project.two", "Ptwo", projectUuid, null);
+ insertProperty("project.one", "Pone", projectUuid, null, null, projectDto.name());
+ insertProperty("project.two", "Ptwo", projectUuid, null, null, projectDto.name());
List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey());
assertThat(dtos)
@UseDataProvider("allValuesForSelect")
public void selectProjectProperties_supports_all_values(String dbValue, String expected) {
ComponentDto projectDto = insertPrivateProject("A");
- insertProperty("project.one", dbValue, projectDto.uuid(), null);
+ insertProperty("project.one", dbValue, projectDto.uuid(), null, null, projectDto.name());
List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey());
assertThat(dtos).hasSize(1);
@DataProvider
public static Object[][] allValuesForSelect() {
- return new Object[][] {
+ return new Object[][]{
{null, ""},
{"", ""},
{"some value", "some value"},
@Test
public void selectProjectProperty() {
- insertProperty("project.one", "one", "uuid10", null);
+ insertProperty("project.one", "one", "uuid10", null, null, "component");
PropertyDto property = underTest.selectProjectProperty("uuid10", "project.one");
@Test
public void select_by_query() {
// global
- insertProperty("global.one", "one", null, null);
- insertProperty("global.two", "two", null, null);
+ insertProperty("global.one", "one", null, null, null, null);
+ insertProperty("global.two", "two", null, null, null, null);
// struts
- insertProperty("struts.one", "one", "uuid10", null);
+ insertProperty("struts.one", "one", "uuid10", null, null, "component");
// commons
- insertProperty("commonslang.one", "one", "uuid11", null);
+ insertProperty("commonslang.one", "one", "uuid11", null, null, "component");
// user
- insertProperty("user.one", "one", null, "100");
- insertProperty("user.two", "two", "uuid10", "100");
+ insertProperty("user.one", "one", null, "100", "login", null);
+ insertProperty("user.two", "two", "uuid10", "100", "login", "component");
// other
- insertProperty("other.one", "one", "uuid12", null);
+ insertProperty("other.one", "one", "uuid12", null, null, "component");
List<PropertyDto> results = underTest.selectByQuery(PropertyQuery.builder().setKey("user.two").setComponentUuid("uuid10")
.setUserUuid("100").build(), db.getSession());
@Test
public void select_global_properties_by_keys() {
insertPrivateProject("A");
- String userUuid = db.users().insertUser(u -> u.setLogin("B")).getUuid();
+ UserDto user = db.users().insertUser(u -> u.setLogin("B"));
String key = "key";
String anotherKey = "anotherKey";
- insertProperty(key, "value", null, null);
- insertProperty(key, "value", "uuid10", null);
- insertProperty(key, "value", null, userUuid);
- insertProperty(anotherKey, "value", null, null);
+ insertProperty(key, "value", null, null, null, null);
+ insertProperty(key, "value", "uuid10", null, null, "component");
+ insertProperty(key, "value", null, user.getUuid(), user.getLogin(), null);
+ insertProperty(anotherKey, "value", null, null, null, null);
- insertProperty("key1", "value", null, null);
- insertProperty("key2", "value", null, null);
- insertProperty("key3", "value", null, null);
+ insertProperty("key1", "value", null, null, null, null);
+ insertProperty("key2", "value", null, null, null, null);
+ insertProperty("key3", "value", null, null, null, null);
assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key)))
.extracting("key")
String key = "key";
String anotherKey = "anotherKey";
- insertProperties(
- newGlobalPropertyDto().setKey(key),
- newComponentPropertyDto(project).setKey(key),
- newComponentPropertyDto(project2).setKey(key),
- newComponentPropertyDto(project2).setKey(anotherKey),
- newUserPropertyDto(user).setKey(key));
+ insertProperties(null, null, newGlobalPropertyDto().setKey(key));
+ insertProperties(null, project.name(), newComponentPropertyDto(project).setKey(key));
+ insertProperties(null, project2.name(), newComponentPropertyDto(project2).setKey(key),
+ newComponentPropertyDto(project2).setKey(anotherKey));
+ insertProperties(user.getLogin(), null, newUserPropertyDto(user).setKey(key));
+
+ newUserPropertyDto(user).setKey(key);
assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet(project.uuid())))
.extracting("key", "componentUuid").containsOnly(tuple(key, project.uuid()));
assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet(project.uuid(), project2.uuid())))
.extracting("key", "componentUuid").containsOnly(
- tuple(key, project.uuid()),
- tuple(key, project2.uuid()),
- tuple(anotherKey, project2.uuid()));
+ tuple(key, project.uuid()),
+ tuple(key, project2.uuid()),
+ tuple(anotherKey, project2.uuid()));
assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet("uuid123456789"))).isEmpty();
}
String key = "key";
String anotherKey = "anotherKey";
- insertProperties(
- newGlobalPropertyDto().setKey(key),
- newComponentPropertyDto(project).setKey(key),
- newComponentPropertyDto(project2).setKey(key),
- newComponentPropertyDto(project2).setKey(anotherKey),
- newUserPropertyDto(user).setKey(key));
-
+ insertProperties(null, null, newGlobalPropertyDto().setKey(key));
+ insertProperties(null, project.name(), newComponentPropertyDto(project).setKey(key));
+ insertProperties(null, project2.name(), newComponentPropertyDto(project2).setKey(key),
+ newComponentPropertyDto(project2).setKey(anotherKey));
+ insertProperties(user.getLogin(), null, newUserPropertyDto(user).setKey(key));
+
assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key), newHashSet(project.uuid())))
.extracting("key", "componentUuid").containsOnly(tuple(key, project.uuid()));
assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key), newHashSet(project.uuid(), project2.uuid())))
.extracting("key", "componentUuid").containsOnly(
- tuple(key, project.uuid()),
- tuple(key, project2.uuid()));
+ tuple(key, project.uuid()),
+ tuple(key, project2.uuid()));
assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key, anotherKey), newHashSet(project.uuid(), project2.uuid())))
.extracting("key", "componentUuid").containsOnly(
- tuple(key, project.uuid()),
- tuple(key, project2.uuid()),
- tuple(anotherKey, project2.uuid()));
+ tuple(key, project.uuid()),
+ tuple(key, project2.uuid()),
+ tuple(anotherKey, project2.uuid()));
assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet("unknown"), newHashSet(project.uuid()))).isEmpty();
assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet("key"), newHashSet("uuid123456789"))).isEmpty();
public void select_by_key_and_matching_value() {
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
- db.properties().insertProperties(
- newComponentPropertyDto("key", "value", project1),
- newComponentPropertyDto("key", "value", project2),
- newGlobalPropertyDto("key", "value"),
- newComponentPropertyDto("another key", "value", project1));
+ db.properties().insertProperties(null, project1.name(), newComponentPropertyDto("key", "value", project1));
+ db.properties().insertProperties(null, project2.name(), newComponentPropertyDto("key", "value", project2));
+ db.properties().insertProperties(null, null, newGlobalPropertyDto("key", "value"));
+ db.properties().insertProperties(null, project1.name(), newComponentPropertyDto("another key", "value", project1));
assertThat(underTest.selectByKeyAndMatchingValue(db.getSession(), "key", "value"))
.extracting(PropertyDto::getValue, PropertyDto::getComponentUuid)
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project1));
ComponentDto project2 = db.components().insertPrivateProject();
- db.properties().insertProperties(
- newPropertyDto("key", "1", project1, user1),
- newPropertyDto("key", "2", project2, user1),
- newPropertyDto("key", "3", file1, user1),
- newPropertyDto("another key", "4", project1, user1),
- newPropertyDto("key", "5", project1, user2),
- newGlobalPropertyDto("key", "global"));
+ db.properties().insertProperties(user1.getLogin(), project1.name(), newPropertyDto("key", "1", project1, user1));
+ db.properties().insertProperties(user1.getLogin(), project2.name(), newPropertyDto("key", "2", project2, user1));
+ db.properties().insertProperties(user1.getLogin(), file1.name(), newPropertyDto("key", "3", file1, user1));
+ db.properties().insertProperties(user1.getLogin(), project1.name(), newPropertyDto("another key", "4", project1, user1));
+ db.properties().insertProperties(user2.getLogin(), project1.name(), newPropertyDto("key", "5", project1, user2));
+ db.properties().insertProperties(null, null, newGlobalPropertyDto("key", "global"));
assertThat(underTest.selectByKeyAndUserUuidAndComponentQualifier(db.getSession(), "key", user1.getUuid(), "TRK"))
.extracting(PropertyDto::getValue).containsExactlyInAnyOrder("1", "2");
@Test
@UseDataProvider("valueUpdatesDataProvider")
public void saveProperty_deletes_then_inserts_global_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) {
- String uuid = insertProperty("global", oldValue, null, null);
+ String uuid = insertProperty("global", oldValue, null, null, null, null);
underTest.saveProperty(new PropertyDto().setKey("global").setValue(newValue));
@UseDataProvider("valueUpdatesDataProvider")
public void saveProperty_deletes_then_inserts_component_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) {
String componentUuid = "uuid999";
- String uuid = insertProperty("global", oldValue, componentUuid, null);
+ String uuid = insertProperty("global", oldValue, componentUuid, null, null, "component");
underTest.saveProperty(new PropertyDto().setKey("global").setComponentUuid(componentUuid).setValue(newValue));
@UseDataProvider("valueUpdatesDataProvider")
public void saveProperty_deletes_then_inserts_user_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) {
String userUuid = "uuid-90";
- String uuid = insertProperty("global", oldValue, null, userUuid);
+ String uuid = insertProperty("global", oldValue, null, userUuid, "login", null);
underTest.saveProperty(new PropertyDto().setKey("global").setUserUuid(userUuid).setValue(newValue));
@DataProvider
public static Object[][] valueUpdatesDataProvider() {
- return new Object[][] {
+ return new Object[][]{
{null, null},
{null, ""},
{null, "some value"},
insertPrivateProject("A");
insertPrivateProject("B");
insertPrivateProject("C");
- String uuid1 = insertProperty("global.one", "one", null, null);
- String uuid2 = insertProperty("global.two", "two", null, null);
- String uuid3 = insertProperty("struts.one", "one", "project1", null);
- String uuid4 = insertProperty("commonslang.one", "one", "project2", null);
- String uuid5 = insertProperty("user.one", "one", null, "100");
- String uuid6 = insertProperty("user.two", "two", null, "100");
- String uuid7 = insertProperty("other.one", "one", "project3", null);
+ String uuid1 = insertProperty("global.one", "one", null, null, null, null);
+ String uuid2 = insertProperty("global.two", "two", null, null, null, null);
+ String uuid3 = insertProperty("struts.one", "one", "project1", null, null, "project1");
+ String uuid4 = insertProperty("commonslang.one", "one", "project2", null, null, "project2");
+ String uuid5 = insertProperty("user.one", "one", null, "100", "login", null);
+ String uuid6 = insertProperty("user.two", "two", null, "100", "login", null);
+ String uuid7 = insertProperty("other.one", "one", "project3", null, null, "project3");
- underTest.deleteProjectProperty("struts.one", "project1");
+ underTest.deleteProjectProperty("struts.one", "project1", "project1");
assertThatPropertiesRowByUuid(uuid1)
.hasKey("global.one")
@Test
public void delete_project_properties() {
- String uuid1 = insertProperty("sonar.profile.java", "Sonar Way", "uuid1", null);
- String uuid2 = insertProperty("sonar.profile.java", "Sonar Way", "uuid2", null);
+ String uuid1 = insertProperty("sonar.profile.java", "Sonar Way", "uuid1", null, null, "component");
+ String uuid2 = insertProperty("sonar.profile.java", "Sonar Way", "uuid2", null, null, "component");
- String uuid3 = insertProperty("sonar.profile.java", "Sonar Way", null, null);
+ String uuid3 = insertProperty("sonar.profile.java", "Sonar Way", null, null, null, "component");
- String uuid4 = insertProperty("sonar.profile.js", "Sonar Way", "uuid1", null);
- String uuid5 = insertProperty("sonar.profile.js", "Sonar Way", "uuid2", null);
- String uuid6 = insertProperty("sonar.profile.js", "Sonar Way", null, null);
+ String uuid4 = insertProperty("sonar.profile.js", "Sonar Way", "uuid1", null, null, "component");
+ String uuid5 = insertProperty("sonar.profile.js", "Sonar Way", "uuid2", null, null, "component");
+ String uuid6 = insertProperty("sonar.profile.js", "Sonar Way", null, null, null, "component");
underTest.deleteProjectProperties("sonar.profile.java", "Sonar Way");
@Test
public void deleteGlobalProperty() {
// global
- String uuid1 = insertProperty("global.key", "new_global", null, null);
- String uuid2 = insertProperty("to_be_deleted", "xxx", null, null);
+ String uuid1 = insertProperty("global.key", "new_global", null, null, null, null);
+ String uuid2 = insertProperty("to_be_deleted", "xxx", null, null, null, null);
// project - do not delete this project property that has the same key
- String uuid3 = insertProperty("to_be_deleted", "new_project", "to_be_deleted", null);
+ String uuid3 = insertProperty("to_be_deleted", "new_project", "to_be_deleted", null, null, "component");
// user
- String uuid4 = insertProperty("user.key", "new_user", null, "100");
+ String uuid4 = insertProperty("user.key", "new_user", null, "100", "login", null);
underTest.deleteGlobalProperty("to_be_deleted");
ComponentDto anotherProject = db.components().insertPrivateProject();
UserDto user = db.users().insertUser();
UserDto anotherUser = db.users().insertUser();
- insertProperty("KEY_11", "VALUE", project.uuid(), user.getUuid());
- insertProperty("KEY_12", "VALUE", project.uuid(), user.getUuid());
- insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getUuid());
- insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getUuid());
+ insertProperty("KEY_11", "VALUE", project.uuid(), user.getUuid(), user.getLogin(), project.name());
+ insertProperty("KEY_12", "VALUE", project.uuid(), user.getUuid(), user.getLogin(), project.name());
+ insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getUuid(), anotherUser.getLogin(), project.name());
+ insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getUuid(), user.getLogin(), anotherProject.name());
- underTest.deleteByUser(session, user.getUuid());
+ underTest.deleteByUser(session, user.getUuid(), user.getLogin());
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).build(), session))
.hasSize(1)
ComponentDto anotherProject = db.components().insertPrivateProject();
UserDto user = db.users().insertUser();
UserDto anotherUser = db.users().insertUser();
- insertProperty("KEY_11", user.getLogin(), project.uuid(), null);
- insertProperty("KEY_12", user.getLogin(), project.uuid(), null);
- insertProperty("KEY_11", anotherUser.getLogin(), project.uuid(), null);
- insertProperty("KEY_11", user.getLogin(), anotherProject.uuid(), null);
+ insertProperty("KEY_11", user.getLogin(), project.uuid(), null, null, project.name());
+ insertProperty("KEY_12", user.getLogin(), project.uuid(), null, null, project.name());
+ insertProperty("KEY_11", anotherUser.getLogin(), project.uuid(), null, null, project.name());
+ insertProperty("KEY_11", user.getLogin(), anotherProject.uuid(), null, null, anotherProject.name());
underTest.deleteByMatchingLogin(session, user.getLogin(), newArrayList("KEY_11", "KEY_12"));
public void delete_by_key_and_value() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto anotherProject = db.components().insertPrivateProject();
- insertProperty("KEY", "VALUE", null, null);
- insertProperty("KEY", "VALUE", project.uuid(), null);
- insertProperty("KEY", "VALUE", null, "100");
- insertProperty("KEY", "VALUE", project.uuid(), "100");
- insertProperty("KEY", "VALUE", anotherProject.uuid(), null);
+ insertProperty("KEY", "VALUE", null, null, null, null);
+ insertProperty("KEY", "VALUE", project.uuid(), null, null, project.name());
+ insertProperty("KEY", "VALUE", null, "100", "login", null);
+ insertProperty("KEY", "VALUE", project.uuid(), "100", "login", project.name());
+ insertProperty("KEY", "VALUE", anotherProject.uuid(), null, null, anotherProject.name());
// Should not be removed
- insertProperty("KEY", "ANOTHER_VALUE", null, null);
- insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), "100");
+ insertProperty("KEY", "ANOTHER_VALUE", null, null, null, null);
+ insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), "100", "login", project.name());
underTest.deleteByKeyAndValue(session, "KEY", "VALUE");
db.commit();
@Test
public void saveGlobalProperties_delete_and_insert_new_value_when_property_exists_in_db() {
- String uuid = insertProperty("to_be_updated", "old_value", null, null);
+ String uuid = insertProperty("to_be_updated", "old_value", null, null, null, null);
underTest.saveGlobalProperties(ImmutableMap.of("to_be_updated", "new value"));
@Test
public void renamePropertyKey_updates_global_component_and_user_properties() {
- String uuid1 = insertProperty("foo", "bar", null, null);
- String uuid2 = insertProperty("old_name", "doc1", null, null);
- String uuid3 = insertProperty("old_name", "doc2", "15", null);
- String uuid4 = insertProperty("old_name", "doc3", "16", null);
- String uuid5 = insertProperty("old_name", "doc4", null, "100");
- String uuid6 = insertProperty("old_name", "doc5", null, "101");
+ String uuid1 = insertProperty("foo", "bar", null, null, null, null);
+ String uuid2 = insertProperty("old_name", "doc1", null, null, null, null);
+ String uuid3 = insertProperty("old_name", "doc2", "15", null, null, "component");
+ String uuid4 = insertProperty("old_name", "doc3", "16", null, null, "component");
+ String uuid5 = insertProperty("old_name", "doc4", null, "100", "login", null);
+ String uuid6 = insertProperty("old_name", "doc5", null, "101", "login", null);
underTest.renamePropertyKey("old_name", "new_name");
@Test
public void rename_to_same_key_has_no_effect() {
- String uuid = insertProperty("foo", "bar", null, null);
+ String uuid = insertProperty("foo", "bar", null, null, null, null);
assertThatPropertiesRowByUuid(uuid)
.hasCreatedAt(INITIAL_DATE);
return null;
}
- private void insertProperties(PropertyDto... properties) {
+ private void insertProperties(@Nullable String userLogin, @Nullable String projectName, PropertyDto... properties) {
for (PropertyDto propertyDto : properties) {
- underTest.saveProperty(session, propertyDto);
+ underTest.saveProperty(session, propertyDto, userLogin, projectName);
}
session.commit();
}
- private String insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable String userUuid) {
+ private String insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable String userUuid,
+ @Nullable String userLogin, @Nullable String projectName) {
PropertyDto dto = new PropertyDto().setKey(key)
.setComponentUuid(componentUuid)
.setUserUuid(userUuid)
.setValue(value);
- db.properties().insertProperty(dto);
+ db.properties().insertProperty(dto, projectName, userLogin);
return (String) db.selectFirst(session, "select uuid as \"uuid\" from properties" +
" where prop_key='" + key + "'" +
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.property;
+
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PropertyNewValue;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.user.UserDto;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+@RunWith(DataProviderRunner.class)
+public class PropertiesDaoWithPersisterTest {
+ private static final String KEY = "key";
+ private static final String ANOTHER_KEY = "another_key";
+ private static final String PROJECT_NAME = "project_name";
+ private static final String PROJECT_UUID = "project_uuid";
+ private static final String SECURED_KEY = "key.secured";
+ private static final String USER_LOGIN = "user_login";
+ private static final String USER_UUID = "user_uuid";
+ private static final String VALUE = "value";
+
+ private static final long INITIAL_DATE = 1_444_000L;
+
+ private final AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(INITIAL_DATE, 1);
+
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+ private final ArgumentCaptor<PropertyNewValue> newValueCaptor = ArgumentCaptor.forClass(PropertyNewValue.class);
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public DbTester db = DbTester.create(system2, auditPersister);
+
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession session = db.getSession();
+ private final PropertiesDao underTest = dbClient.propertiesDao();
+
+ @Test
+ public void saveGlobalTrackedPropertyIsPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+ underTest.saveProperty(new PropertyDto().setKey(KEY).setValue(VALUE));
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
+
+ PropertyNewValue newValue = newValueCaptor.getValue();
+
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin)
+ .containsExactly(KEY, VALUE, null, null);
+ assertThat(newValue.toString()).doesNotContain("projectUuid");
+ }
+
+ @Test
+ public void saveGlobalNotTrackedPropertyIsNotPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+ underTest.saveProperty(new PropertyDto().setKey(KEY).setValue(VALUE));
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ @Test
+ public void saveGlobalTrackedAndSecuredPropertyIsPersisted() {
+ when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true);
+
+ underTest.saveProperty(new PropertyDto().setKey(SECURED_KEY).setValue(VALUE));
+
+ verify(auditPersister).isTrackedProperty(SECURED_KEY);
+ verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin)
+ .containsExactly(SECURED_KEY, null, null, null);
+ assertThat(newValue.toString()).doesNotContain("projectUuid");
+ }
+
+ @Test
+ public void saveProjectTrackedPropertyIsPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+ PropertyDto propertyDto = getPropertyDto(KEY);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(),
+ USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME);
+ assertThat(newValue.toString()).contains("projectUuid");
+ }
+
+ @Test
+ public void saveProjectTrackedAndSecuredPropertyIsPersisted() {
+ when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true);
+
+ PropertyDto propertyDto = getPropertyDto(SECURED_KEY);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+ verify(auditPersister).isTrackedProperty(SECURED_KEY);
+ verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(propertyDto.getKey(), null, propertyDto.getUserUuid(),
+ USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME);
+ assertThat(newValue.toString()).contains("projectUuid");
+ }
+
+ @Test
+ public void deleteTrackedPropertyByQueryIsPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+ PropertyQuery query = getPropertyQuery(KEY);
+ underTest.deleteByQuery(session, query);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(query.key(), null, query.userUuid(),
+ null, query.componentUuid(), null);
+ assertThat(newValue.toString()).doesNotContain("userLogin");
+ }
+
+ @Test
+ public void deleteNotTrackedPropertyByQueryIsNotPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+ PropertyQuery query = getPropertyQuery(KEY);
+ underTest.deleteByQuery(session, query);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ @Test
+ public void deleteTrackedPropertyIsPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+ PropertyDto propertyDto = getPropertyDto(KEY);
+ underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(),
+ USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME);
+ assertThat(newValue.toString()).contains("userLogin");
+ }
+
+ @Test
+ public void deleteNotTrackedPropertyIsNotPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+ PropertyDto propertyDto = getPropertyDto(KEY);
+ underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ @Test
+ public void deleteTrackedProjectPropertyIsPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+ underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_NAME);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(KEY, null, null,
+ null, PROJECT_UUID, PROJECT_NAME);
+ assertThat(newValue.toString()).doesNotContain("userLogin");
+ }
+
+ @Test
+ public void deleteNotTrackedProjectPropertyIsNotPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+ PropertyDto propertyDto = getPropertyDto(KEY);
+ underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ @Test
+ public void deleteTrackedProjectPropertiesIsPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+ underTest.deleteProjectProperties(KEY, VALUE);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(KEY, VALUE, null,
+ null, null, null);
+ assertThat(newValue.toString()).doesNotContain("projectUuid");
+ }
+
+ @Test
+ public void deleteNotTrackedProjectPropertiesIsNotPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+ underTest.deleteProjectProperties(KEY, VALUE);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ @Test
+ public void deleteTrackedGlobalPropertyIsPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+ underTest.deleteGlobalProperty(KEY, session);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(KEY, null, null,
+ null, null, null);
+ assertThat(newValue.toString()).doesNotContain("projectUuid");
+ }
+
+ @Test
+ public void deleteNotTrackedGlobalPropertyIsNotPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+ underTest.deleteGlobalProperty(KEY, session);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ @Test
+ public void deletePropertyByUserIsPersisted() {
+ UserDto user = setUserProperties(VALUE);
+ underTest.deleteByUser(session, user.getUuid(), user.getLogin());
+
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(ANOTHER_KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(SECURED_KEY);
+ verify(auditPersister, times(2)).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+ List<PropertyNewValue> newValues = newValueCaptor.getAllValues();
+ assertThat(newValues.get(0))
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(KEY, null, user.getUuid(),
+ user.getLogin(), null, null);
+ assertThat(newValues.get(0).toString()).contains("userUuid");
+ assertThat(newValues.get(1))
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(SECURED_KEY, null, user.getUuid(),
+ user.getLogin(), null, null);
+ assertThat(newValues.get(1).toString()).doesNotContain("value");
+ }
+
+ @Test
+ public void deletePropertyByUserLoginIsPersisted() {
+ UserDto user = setUserProperties(null);
+ underTest.deleteByMatchingLogin(session, user.getLogin(), newArrayList(KEY, ANOTHER_KEY, SECURED_KEY));
+
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(ANOTHER_KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(SECURED_KEY);
+ verify(auditPersister, times(2)).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+ List<PropertyNewValue> newValues = newValueCaptor.getAllValues();
+ assertThat(newValues.get(0))
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(KEY, null, null,
+ user.getLogin(), null, null);
+ assertThat(newValues.get(0).toString()).contains("userLogin");
+ assertThat(newValues.get(1))
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(SECURED_KEY, null, null,
+ user.getLogin(), null, null);
+ assertThat(newValues.get(1).toString()).doesNotContain("value");
+ }
+
+ @Test
+ public void deleteTrackedPropertyByKeyAndValueIsPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+ underTest.deleteByKeyAndValue(session, KEY, VALUE);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+ PropertyNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+ PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+ PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+ .containsExactly(KEY, VALUE, null,
+ null, null, null);
+ assertThat(newValue.toString()).doesNotContain("projectUuid");
+ }
+
+ @Test
+ public void deleteNotTrackedPropertyByKeyAndValueIsNotPersisted() {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+ underTest.deleteByKeyAndValue(session, KEY, VALUE);
+
+ verify(auditPersister).isTrackedProperty(KEY);
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ private PropertyDto getPropertyDto(String key) {
+ return new PropertyDto()
+ .setKey(key)
+ .setValue(VALUE)
+ .setUserUuid(USER_UUID)
+ .setComponentUuid(PROJECT_UUID);
+ }
+
+ private PropertyQuery getPropertyQuery(String key) {
+ return PropertyQuery.builder()
+ .setKey(key)
+ .setComponentUuid(PROJECT_UUID)
+ .setUserUuid(USER_UUID)
+ .build();
+ }
+
+ private UserDto setUserProperties(@Nullable String value) {
+ when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+ when(auditPersister.isTrackedProperty(ANOTHER_KEY)).thenReturn(false);
+ when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true);
+
+ ComponentDto project = db.components().insertPrivateProject();
+ UserDto user = db.users().insertUser();
+
+ if (value == null) {
+ value = user.getLogin();
+ }
+
+ PropertyDto dto1 = new PropertyDto().setKey(KEY)
+ .setComponentUuid(project.uuid())
+ .setUserUuid(user.getUuid())
+ .setValue(value);
+ PropertyDto dto2 = new PropertyDto().setKey(ANOTHER_KEY)
+ .setComponentUuid(project.uuid())
+ .setUserUuid(user.getUuid())
+ .setValue(value);
+ PropertyDto dto3 = new PropertyDto().setKey(SECURED_KEY)
+ .setComponentUuid(project.uuid())
+ .setUserUuid(user.getUuid())
+ .setValue(value);
+ db.properties().insertProperty(dto1, project.name(), user.getLogin());
+ db.properties().insertProperty(dto2, project.name(), user.getLogin());
+ db.properties().insertProperty(dto3, project.name(), user.getLogin());
+ List<PropertyDto> list = db.getDbClient().propertiesDao().selectByKeyAndMatchingValue(session, KEY, VALUE);
+ list = db.getDbClient().propertiesDao().selectByKeyAndMatchingValue(session, ANOTHER_KEY, VALUE);
+ list = db.getDbClient().propertiesDao().selectByKeyAndMatchingValue(session, SECURED_KEY, VALUE);
+ return user;
+ }
+}
@Test
public void selectPurgeableAnalyses() {
- SnapshotDto[] analyses = new SnapshotDto[] {
+ SnapshotDto[] analyses = new SnapshotDto[]{
newSnapshot()
.setUuid("u1")
.setComponentUuid(PROJECT_UUID)
private void insertPropertyFor(ComponentDto... components) {
Stream.of(components).forEach(componentDto -> db.properties().insertProperty(new PropertyDto()
- .setKey(randomAlphabetic(3))
- .setValue(randomAlphabetic(3))
- .setComponentUuid(componentDto.uuid())));
+ .setKey(randomAlphabetic(3))
+ .setValue(randomAlphabetic(3))
+ .setComponentUuid(componentDto.uuid()),
+ componentDto.name(), null));
}
private Stream<String> getComponentUuidsOfMeasures() {
}
@Test
- public void insert_and_update() {
+ public void insertAndUpdateGroupIsPersisted() {
dbClient.groupDao().insert(db.getSession(), aGroup);
verify(auditPersister).addUserGroup(eq(db.getSession()), newValueCaptor.capture());
assertThat(newValue)
.extracting(UserGroupNewValue::getGroupUuid, UserGroupNewValue::getName)
.containsExactly(aGroup.getUuid(), aGroup.getName());
- assertThat(newValue.toString()).doesNotContain("'description':");
+ assertThat(newValue.toString()).doesNotContain("description");
GroupDto dto = new GroupDto()
.setUuid(aGroup.getUuid())
assertThat(newValue)
.extracting(UserGroupNewValue::getGroupUuid, UserGroupNewValue::getName, UserGroupNewValue::getDescription)
.containsExactly(dto.getUuid(), dto.getName(), dto.getDescription());
- assertThat(newValue.toString()).contains("'description':");
+ assertThat(newValue.toString()).contains("description");
}
@Test
- public void deleteByUuid() {
+ public void deleteGroupIsPersisted() {
dbClient.groupDao().insert(db.getSession(), aGroup);
verify(auditPersister).addUserGroup(eq(db.getSession()), any());
private final UserDao underTest = db.getDbClient().userDao();
@Test
- public void insert_user_with_default_values() {
+ public void insertUserIsPersisted() {
UserDto userDto = new UserDto()
.setLogin("john")
.setName("John")
assertThat(newValue)
.extracting(UserNewValue::getUserUuid, UserNewValue::getLogin)
.containsExactly(user.getUuid(), user.getLogin());
- assertThat(newValue.toString()).doesNotContain("'name':");
+ assertThat(newValue.toString()).doesNotContain("name");
}
@Test
- public void update_user() {
+ public void updateUserIsPersisted() {
UserDto user = db.users().insertUser(u -> u
.setLogin("john")
.setName("John")
.containsExactly(updatedUser.getUuid(), updatedUser.getLogin(), updatedUser.getName(), updatedUser.getEmail(), updatedUser.isActive(),
updatedUser.getScmAccounts(), updatedUser.getExternalId(), updatedUser.getExternalLogin(), updatedUser.getExternalIdentityProvider(),
updatedUser.isLocal(), updatedUser.isOnboarded(), updatedUser.isRoot(), updatedUser.getLastConnectionDate());
- assertThat(newValue.toString()).contains("'name':");
+ assertThat(newValue.toString()).contains("name");
}
@Test
- public void update_user_without_track() {
+ public void updateUserWithoutTrackIsNotPersisted() {
UserDto user = db.users().insertUser(u -> u
.setLogin("john")
.setName("John")
}
@Test
- public void deactivate_user() {
+ public void deactivateUserIsPersisted() {
UserDto user = insertActiveUser();
insertUserGroup(user);
underTest.update(db.getSession(), user.setLastConnectionDate(10_000_000_000L));
private final UserGroupDao underTest = dbClient.userGroupDao();
@Test
- public void insert() {
+ public void insertUserGroupIsPersisted() {
UserDto user = db.users().insertUser();
verify(auditPersister).addUser(eq(db.getSession()), any());
}
@Test
- public void delete_members_by_group_uuid() {
+ public void deleteUserGroupByGroupIsPersisted() {
UserDto user1 = db.users().insertUser();
UserDto user2 = db.users().insertUser();
GroupDto group1 = db.users().insertGroup();
}
@Test
- public void delete_by_user() {
+ public void deleteUserGroupByUserIsPersisted() {
UserDto user1 = db.users().insertUser();
UserDto user2 = db.users().insertUser();
GroupDto group1 = db.users().insertGroup();
private UserPropertiesDao underTest = db.getDbClient().userPropertiesDao();
@Test
- public void insert_tracked_property() {
+ public void insertTrackedUserPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true);
UserDto user = db.users().insertUser();
.setValue("a_value"),
user.getLogin());
- verify(auditPersister).addUserProperty(eq(db.getSession()), newValueCaptor.capture());
+ verify(auditPersister).addProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
verify(auditPersister).isTrackedProperty(PROPERTY_KEY);
assertThat(newValueCaptor.getValue())
.extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
}
@Test
- public void insert_tracked_secured_property() {
+ public void insertTrackedAndSecuredUserPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(SECURED_PROPERTY_KEY)).thenReturn(true);
UserDto user = db.users().insertUser();
user.getLogin());
verify(auditPersister).isTrackedProperty(SECURED_PROPERTY_KEY);
- verify(auditPersister).addUserProperty(eq(db.getSession()), newValueCaptor.capture());
+ verify(auditPersister).addProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
.extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
PropertyNewValue::getUserLogin)
.containsExactly(userSetting.getKey(), null, user.getUuid(), user.getLogin());
- assertThat(newValue.toString()).doesNotContain("'propertyValue':");
+ assertThat(newValue.toString()).doesNotContain("propertyValue");
}
@Test
- public void insert_not_tracked_property() {
+ public void insertNotTrackedUserPropertyIsNotPersisted() {
when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(false);
UserDto user = db.users().insertUser();
}
@Test
- public void update() {
+ public void updateTrackedUserPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true);
UserDto user = db.users().insertUser();
user.getLogin());
verify(auditPersister).addUser(eq(db.getSession()), any());
- verify(auditPersister).addUserProperty(eq(db.getSession()), any());
- verify(auditPersister).updateUserProperty(eq(db.getSession()), newValueCaptor.capture());
+ verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true));
+ verify(auditPersister).updateProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
assertThat(newValueCaptor.getValue())
.extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
PropertyNewValue::getUserLogin)
}
@Test
- public void delete_by_user() {
+ public void deleteTrackedUserPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true);
when(auditPersister.isTrackedProperty(SECURED_PROPERTY_KEY)).thenReturn(false);
underTest.deleteByUser(db.getSession(), user);
verify(auditPersister).addUser(eq(db.getSession()), any());
- verify(auditPersister).addUserProperty(eq(db.getSession()), any());
- verify(auditPersister).addUserProperty(eq(db.getSession()), any());
+ verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true));
+ verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true));
verify(auditPersister, times(2)).isTrackedProperty(PROPERTY_KEY);
verify(auditPersister, times(2)).isTrackedProperty(SECURED_PROPERTY_KEY);
- verify(auditPersister).deleteUserProperty(eq(db.getSession()), newValueCaptor.capture());
+ verify(auditPersister).deleteProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
verifyNoMoreInteractions(auditPersister);
assertThat(newValueCaptor.getValue())
.extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
assertThat(newValue)
.extracting(UserTokenNewValue::getTokenUuid, UserTokenNewValue::getTokenName, UserTokenNewValue::getUserUuid, UserTokenNewValue::getLastConnectionDate)
.containsExactly(userToken.getUuid(), userToken.getName(), userToken.getUserUuid(), userToken.getLastConnectionDate());
- assertThat(newValue.toString()).contains("'tokenUuid':");
+ assertThat(newValue.toString()).contains("tokenUuid");
}
@Test
.setUrl("URL_1")
.setSecret("a_secret");
- underTest.insert(dbSession, dto);
+ underTest.insert(dbSession, dto, null);
WebhookDto stored = selectByUuid(dto.getUuid());
.setProjectUuid("UUID_2")
.setSecret("a_secret");
- underTest.insert(dbSession, dto);
+ underTest.insert(dbSession, dto, "project_name");
WebhookDto reloaded = selectByUuid(dto.getUuid());
WebhookDto dto = webhookDbTester.insertGlobalWebhook();
underTest.update(dbSession, dto
- .setName("a-fancy-webhook")
- .setUrl("http://www.fancy-webhook.io")
- .setSecret(null));
+ .setName("a-fancy-webhook")
+ .setUrl("http://www.fancy-webhook.io")
+ .setSecret(null),
+ null);
Optional<WebhookDto> optionalResult = underTest.selectByUuid(dbSession, dto.getUuid());
assertThat(optionalResult).isPresent();
WebhookDto dto = webhookDbTester.insertGlobalWebhook();
underTest.update(dbSession, dto
- .setName("a-fancy-webhook")
- .setUrl("http://www.fancy-webhook.io")
- .setSecret("a_new_secret"));
+ .setName("a-fancy-webhook")
+ .setUrl("http://www.fancy-webhook.io")
+ .setSecret("a_new_secret"),
+ null);
Optional<WebhookDto> optionalResult = underTest.selectByUuid(dbSession, dto.getUuid());
assertThat(optionalResult).isPresent();
public void delete() {
WebhookDto dto = webhookDbTester.insertGlobalWebhook();
- underTest.delete(dbSession, dto.getUuid());
+ underTest.delete(dbSession, dto.getUuid(), dto.getName());
Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid());
assertThat(reloaded).isEmpty();
.setName("NAME_1")
.setUrl("URL_1");
- underTest.insert(dbSession, dto);
+ underTest.insert(dbSession, dto, null);
Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid());
assertThat(reloaded).isPresent();
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.webhook;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.WebhookNewValue;
+import org.sonar.db.component.ComponentDbTester;
+import org.sonar.db.project.ProjectDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class WebhookDaoWithPersisterTest {
+ private AuditPersister auditPersister = mock(AuditPersister.class);
+
+ @Rule
+ public final DbTester dbTester = DbTester.create(System2.INSTANCE, auditPersister);
+
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final DbSession dbSession = dbTester.getSession();
+ private final WebhookDao underTest = dbClient.webhookDao();
+ private final WebhookDbTester webhookDbTester = dbTester.webhooks();
+ private final ComponentDbTester componentDbTester = dbTester.components();
+
+ private final ArgumentCaptor<WebhookNewValue> newValueCaptor = ArgumentCaptor.forClass(WebhookNewValue.class);
+
+ @Test
+ public void insertGlobalWebhookIsPersisted() {
+ WebhookDto dto = new WebhookDto()
+ .setUuid("UUID_1")
+ .setName("NAME_1")
+ .setUrl("URL_1")
+ .setSecret("a_secret");
+
+ underTest.insert(dbSession, dto, null);
+
+ verify(auditPersister).addWebhook(eq(dbSession), newValueCaptor.capture());
+ WebhookNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName)
+ .containsExactly(dto.getUuid(), dto.getName());
+ assertThat(newValue.toString()).doesNotContain("url");
+ }
+
+ @Test
+ public void insertProjectWebhookIsPersisted() {
+ WebhookDto dto = new WebhookDto()
+ .setUuid("UUID_1")
+ .setName("NAME_1")
+ .setUrl("URL_1")
+ .setProjectUuid("UUID_2")
+ .setSecret("a_secret");
+
+ underTest.insert(dbSession, dto, "project_name");
+
+ verify(auditPersister).addWebhook(eq(dbSession), newValueCaptor.capture());
+ WebhookNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getProjectUuid,
+ WebhookNewValue::getProjectName)
+ .containsExactly(dto.getUuid(), dto.getName(), dto.getProjectUuid(), "project_name");
+ assertThat(newValue.toString()).doesNotContain("url");
+ }
+
+ @Test
+ public void updateWebhookIsPersisted() {
+ WebhookDto dto = webhookDbTester.insertGlobalWebhook();
+ dto = dto
+ .setName("a-fancy-webhook")
+ .setUrl("http://www.fancy-webhook.io")
+ .setSecret(null);
+
+ underTest.update(dbSession, dto, null);
+
+ verify(auditPersister).updateWebhook(eq(dbSession), newValueCaptor.capture());
+ WebhookNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getUrl)
+ .containsExactly(dto.getUuid(), dto.getName(), dto.getUrl());
+ assertThat(newValue.toString()).doesNotContain("projectUuid");
+ }
+
+ @Test
+ public void deleteProjectWebhooksIsPersisted() {
+ ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
+ webhookDbTester.insertWebhook(projectDto);
+
+ underTest.deleteByProject(dbSession, projectDto);
+
+ verify(auditPersister).deleteWebhook(eq(dbSession), newValueCaptor.capture());
+ WebhookNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(WebhookNewValue::getProjectUuid, WebhookNewValue::getProjectName)
+ .containsExactly(projectDto.getUuid(), projectDto.getName());
+ assertThat(newValue.toString()).doesNotContain("webhookUuid");
+ }
+
+ @Test
+ public void deleteWebhookIsPersisted() {
+ WebhookDto dto = webhookDbTester.insertGlobalWebhook();
+
+ underTest.delete(dbSession, dto.getUuid(), dto.getName());
+
+ verify(auditPersister).deleteWebhook(eq(dbSession), newValueCaptor.capture());
+ WebhookNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName)
+ .containsExactly(dto.getUuid(), dto.getName());
+ assertThat(newValue.toString()).doesNotContain("url");
+ }
+}
@Test
public void selectByWebhookUuid_returns_records_ordered_by_date() {
- WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
+ WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW);
WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
@Test
public void selectByWebhookUuid_returns_records_according_to_pagination() {
- WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
+ WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D3", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
@Test
public void selectLatestDelivery_of_a_webhook() {
- WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
+ WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
- WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
+ WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
@Test
public void deleteByWebhook() {
- WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
+ WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
return new DbTester(System2.INSTANCE, null, null);
}
+ public static DbTester create(AuditPersister auditPersister) {
+ return new DbTester(System2.INSTANCE, null, auditPersister);
+ }
+
public static DbTester create(System2 system2, AuditPersister auditPersister) {
return new DbTester(system2, null, auditPersister);
}
private AlmPatDto insert(AlmPatDto dto, Consumer<AlmPatDto>[] populators) {
stream(populators).forEach(p -> p.accept(dto));
- db.getDbClient().almPatDao().insert(db.getSession(), dto);
+ db.getDbClient().almPatDao().insert(db.getSession(), dto, null, null);
db.commit();
return dto;
}
}
@SafeVarargs
- public final ProjectAlmSettingDto insertGitHubProjectAlmSetting(AlmSettingDto githubAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
- return insertProjectAlmSetting(newGithubProjectAlmSettingDto(githubAlmSetting, project), populators);
+ public final ProjectAlmSettingDto insertGitHubProjectAlmSetting(AlmSettingDto githubAlmSetting, ProjectDto project,
+ Consumer<ProjectAlmSettingDto>... populators) {
+ return insertProjectAlmSetting(newGithubProjectAlmSettingDto(githubAlmSetting, project), githubAlmSetting.getKey(),
+ project.getName(), populators);
}
public ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project) {
- return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project));
+ return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(),
+ project.getName());
}
public ProjectAlmSettingDto insertAzureMonoRepoProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project) {
- return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), d -> d.setMonorepo(true));
+ return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(),
+ project.getName(), d -> d.setMonorepo(true));
}
public ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project) {
- return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project));
+ return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project), gitlabAlmSetting.getKey(),
+ project.getName());
}
@SafeVarargs
- public final ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
- return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), populators);
+ public final ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project,
+ Consumer<ProjectAlmSettingDto>... populators) {
+ return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(),
+ project.getName(), populators);
}
@SafeVarargs
- public final ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
- return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project), populators);
+ public final ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project,
+ Consumer<ProjectAlmSettingDto>... populators) {
+ return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project), gitlabAlmSetting.getKey(),
+ project.getName(), populators);
}
@SafeVarargs
- public final ProjectAlmSettingDto insertBitbucketCloudProjectAlmSetting(AlmSettingDto bbCloudAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
- return insertProjectAlmSetting(newBitbucketCloudProjectAlmSettingDto(bbCloudAlmSetting, project), populators);
+ public final ProjectAlmSettingDto insertBitbucketCloudProjectAlmSetting(AlmSettingDto bbCloudAlmSetting, ProjectDto project,
+ Consumer<ProjectAlmSettingDto>... populators) {
+ return insertProjectAlmSetting(newBitbucketCloudProjectAlmSettingDto(bbCloudAlmSetting, project), bbCloudAlmSetting.getKey(),
+ project.getName(), populators);
}
@SafeVarargs
- public final ProjectAlmSettingDto insertBitbucketProjectAlmSetting(AlmSettingDto bitbucketAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
- return insertProjectAlmSetting(newBitbucketProjectAlmSettingDto(bitbucketAlmSetting, project), populators);
+ public final ProjectAlmSettingDto insertBitbucketProjectAlmSetting(AlmSettingDto bitbucketAlmSetting,
+ ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
+ return insertProjectAlmSetting(newBitbucketProjectAlmSettingDto(bitbucketAlmSetting, project),
+ bitbucketAlmSetting.getKey(), project.getName(), populators);
}
@SafeVarargs
- private final ProjectAlmSettingDto insertProjectAlmSetting(ProjectAlmSettingDto dto, Consumer<ProjectAlmSettingDto>... populators) {
+ private final ProjectAlmSettingDto insertProjectAlmSetting(ProjectAlmSettingDto dto, String key, String projectName,
+ Consumer<ProjectAlmSettingDto>... populators) {
stream(populators).forEach(p -> p.accept(dto));
- db.getDbClient().projectAlmSettingDao().insertOrUpdate(db.getSession(), dto);
+ db.getDbClient().projectAlmSettingDao().insertOrUpdate(db.getSession(), dto, key, projectName);
db.commit();
return dto;
}
this.dbSession = db.getSession();
}
- public void add(ComponentDto componentDto, String userUuid) {
+ public void add(ComponentDto componentDto, String userUuid, String userLogin) {
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
- .setKey(PROP_FAVORITE_KEY)
- .setUserUuid(userUuid)
- .setComponentUuid(componentDto.uuid()));
+ .setKey(PROP_FAVORITE_KEY)
+ .setUserUuid(userUuid)
+ .setComponentUuid(componentDto.uuid()),
+ userLogin, componentDto.name());
dbSession.commit();
}
}
public void addGroupToTemplate(PermissionTemplateDto permissionTemplate, GroupDto group, String permission) {
- addGroupToTemplate(permissionTemplate.getUuid(), group.getUuid(), permission);
+ addGroupToTemplate(permissionTemplate.getUuid(), group.getUuid(), permission, permissionTemplate.getName(), group.getName());
}
- public void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission) {
- dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateUuid, groupUuid, permission);
+ public void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission, String templateName, @Nullable String groupName) {
+ dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateUuid, groupUuid, permission, templateName, groupName);
db.commit();
}
public void addAnyoneToTemplate(PermissionTemplateDto permissionTemplate, String permission) {
- addGroupToTemplate(permissionTemplate.getUuid(), null, permission);
+ addGroupToTemplate(permissionTemplate.getUuid(), null, permission, permissionTemplate.getName(), null);
}
public void addUserToTemplate(PermissionTemplateDto permissionTemplate, UserDto user, String permission) {
- addUserToTemplate(permissionTemplate.getUuid(), user.getUuid(), permission);
+ addUserToTemplate(permissionTemplate.getUuid(), user.getUuid(), permission, permissionTemplate.getName(), user.getName());
}
- public void addUserToTemplate(String templateUuid, String userUuid, String permission) {
- dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateUuid, userUuid, permission);
+ public void addUserToTemplate(String templateUuid, String userUuid, String permission, String templateName, String userLogin) {
+ dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateUuid, userUuid, permission, templateName, userLogin);
db.commit();
}
public void addProjectCreatorToTemplate(PermissionTemplateDto permissionTemplate, String permission) {
- addProjectCreatorToTemplate(permissionTemplate.getUuid(), permission);
+ addProjectCreatorToTemplate(permissionTemplate.getUuid(), permission, permissionTemplate.getName());
}
- public void addProjectCreatorToTemplate(String templateUuid, String permission) {
+ public void addProjectCreatorToTemplate(String templateUuid, String permission, String templateName) {
dbClient.permissionTemplateCharacteristicDao().insert(dbSession, newPermissionTemplateCharacteristicDto()
- .setWithProjectCreator(true)
- .setTemplateUuid(templateUuid)
- .setPermission(permission));
+ .setWithProjectCreator(true)
+ .setTemplateUuid(templateUuid)
+ .setPermission(permission),
+ templateName);
db.commit();
}
}
this.dbSession = db.getSession();
}
- public PropertyDto insertProperty(PropertyDto property) {
- dbClient.propertiesDao().saveProperty(dbSession, property);
+ public PropertyDto insertProperty(PropertyDto property, @Nullable String componentName, @Nullable String userLogin) {
+ dbClient.propertiesDao().saveProperty(dbSession, property, userLogin, componentName);
db.commit();
return property;
}
- public void insertProperties(PropertyDto... properties) {
- insertProperties(asList(properties));
+ public void insertProperties(@Nullable String userLogin, @Nullable String projectName, PropertyDto... properties) {
+ insertProperties(asList(properties), userLogin, projectName);
}
- public void insertProperties(List<PropertyDto> properties) {
+ public void insertProperties(List<PropertyDto> properties, @Nullable String userLogin, @Nullable String projectName) {
for (PropertyDto propertyDto : properties) {
- dbClient.propertiesDao().saveProperty(dbSession, propertyDto);
+ dbClient.propertiesDao().saveProperty(dbSession, propertyDto, userLogin, projectName);
}
dbSession.commit();
}
} else {
propertyDtos.add(newGlobalPropertyDto().setKey(settingBaseKey).setValue(idsValue));
}
- insertProperties(propertyDtos);
+ String componentName = componentDto == null ? null : componentDto.name();
+ insertProperties(propertyDtos, null, componentName);
}
public PropertyDbTester verifyInternal(String key, @Nullable String expectedValue) {
.setUuid(Uuids.createFast())
.setGroupUuid(null)
.setRole(permission);
- db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+ db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, null);
db.commit();
return dto;
}
.setUuid(Uuids.createFast())
.setGroupUuid(group.getUuid())
.setRole(permission);
- db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+ db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, null);
db.commit();
return dto;
}
}
public void deletePermissionFromGroup(GroupDto group, String permission) {
- db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, group.getUuid(), null);
+ db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, group.getUuid(), null, null);
db.commit();
}
.setGroupUuid(null)
.setRole(permission)
.setComponentUuid(project.uuid());
- db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+ db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project);
db.commit();
return dto;
}
public void deleteProjectPermissionFromAnyone(ComponentDto project, String permission) {
- db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, null, project.uuid());
+ db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, null, project.uuid(), project);
db.commit();
}
.setGroupUuid(group.getUuid())
.setRole(permission)
.setComponentUuid(project.uuid());
- db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+ db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project);
db.commit();
return dto;
}
@Deprecated
public UserPermissionDto insertPermissionOnUser(UserDto user, String permission) {
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), null);
- db.getDbClient().userPermissionDao().insert(db.getSession(), dto);
+ db.getDbClient().userPermissionDao().insert(db.getSession(), dto, null);
db.commit();
return dto;
}
}
public void deletePermissionFromUser(ComponentDto project, UserDto user, String permission) {
- db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user.getUuid(), permission, project.uuid());
+ db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user.getUuid(), permission, project.uuid(), project.name());
db.commit();
}
"%s can't be granted on a public project", permission);
checkArgument(project.getMainBranchProjectUuid() == null, "Permissions can't be granted on branches");
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), project.uuid());
- db.getDbClient().userPermissionDao().insert(db.getSession(), dto);
+ db.getDbClient().userPermissionDao().insert(db.getSession(), dto, project);
db.commit();
return dto;
}
package org.sonar.db.webhook;
import java.util.Optional;
+import javax.annotation.Nullable;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.project.ProjectDto;
}
public WebhookDto insertGlobalWebhook() {
- return insert(newGlobalWebhook());
+ return insert(newGlobalWebhook(), null);
}
public WebhookDto insertWebhook(ProjectDto project) {
- return insert(newWebhook(project));
+ return insert(newWebhook(project), project.getName());
}
- public WebhookDto insert(WebhookDto dto) {
+ public WebhookDto insert(WebhookDto dto, @Nullable String projectName) {
DbSession dbSession = dbTester.getSession();
- dbTester.getDbClient().webhookDao().insert(dbSession, dto);
+ dbTester.getDbClient().webhookDao().insert(dbSession, dto, projectName);
dbSession.commit();
return dto;
}
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnBuilder("user_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnBuilder("user_login").setIsNullable(false).setLimit(255).build())
- .addColumn(newVarcharColumnBuilder("category").setIsNullable(false).setLimit(20).build())
+ .addColumn(newVarcharColumnBuilder("category").setIsNullable(false).setLimit(25).build())
.addColumn(newVarcharColumnBuilder("operation").setIsNullable(false).setLimit(50).build())
.addColumn(newVarcharColumnBuilder("new_value").setIsNullable(true).setLimit(4000).build())
.addColumn(createdAtColumn)
/**
* Set favorite to the logged in user. If no user, no action is done
*/
- public void add(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid, boolean failIfTooManyFavorites) {
+ public void add(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid, @Nullable String userLogin, boolean failIfTooManyFavorites) {
if (userUuid == null) {
return;
}
return;
}
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
- .setKey(PROP_FAVORITE_KEY)
- .setComponentUuid(componentDto.uuid())
- .setUserUuid(userUuid));
+ .setKey(PROP_FAVORITE_KEY)
+ .setComponentUuid(componentDto.uuid())
+ .setUserUuid(userUuid),
+ userLogin,
+ componentDto.name());
}
/**
* Remove a favorite to the user.
+ *
* @throws IllegalArgumentException if the component is not a favorite
*/
- public void remove(DbSession dbSession, ComponentDto component, @Nullable String userUuid) {
+ public void remove(DbSession dbSession, ComponentDto component, @Nullable String userUuid, @Nullable String userLogin) {
if (userUuid == null) {
return;
}
int result = dbClient.propertiesDao().delete(dbSession, new PropertyDto()
- .setKey(PROP_FAVORITE_KEY)
- .setComponentUuid(component.uuid())
- .setUserUuid(userUuid));
+ .setKey(PROP_FAVORITE_KEY)
+ .setComponentUuid(component.uuid())
+ .setUserUuid(userUuid),
+ userLogin, component.name());
checkArgument(result == 1, "Component '%s' is not a favorite", component.getDbKey());
}
}
UserDto user = db.users().insertUser();
assertNoFavorite(project, user);
- underTest.add(dbSession, project, user.getUuid(), true);
+ underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true);
assertFavorite(project, user);
}
public void do_nothing_when_no_user() {
ComponentDto project = db.components().insertPrivateProject();
- underTest.add(dbSession, project, null, true);
+ underTest.add(dbSession, project, null, null,true);
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setComponentUuid(project.uuid())
@Test
public void do_not_add_favorite_when_already_100_favorite_projects() {
UserDto user = db.users().insertUser();
- IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+ IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid(), user.getName()));
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setUserUuid(user.getUuid())
.build(), dbSession)).hasSize(100);
ComponentDto project = db.components().insertPrivateProject();
- underTest.add(dbSession, project, user.getUuid(), false);
+ underTest.add(dbSession, project, user.getUuid(), user.getLogin(), false);
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setUserUuid(user.getUuid())
@Test
public void do_not_add_favorite_when_already_100_favorite_portfolios() {
UserDto user = db.users().insertUser();
- IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+ IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(),
+ user.getUuid(), user.getLogin()));
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setUserUuid(user.getUuid())
.build(), dbSession)).hasSize(100);
ComponentDto project = db.components().insertPrivateProject();
- underTest.add(dbSession, project, user.getUuid(), false);
+ underTest.add(dbSession, project, user.getUuid(), user.getLogin(), false);
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setUserUuid(user.getUuid())
@Test
public void fail_when_more_than_100_projects_favorites() {
UserDto user = db.users().insertUser();
- IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+ IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(),
+ user.getUuid(), user.getLogin()));
ComponentDto project = db.components().insertPrivateProject();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You cannot have more than 100 favorites on components with qualifier 'TRK'");
- underTest.add(dbSession, project, user.getUuid(), true);
+ underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true);
}
@Test
public void fail_when_adding_existing_favorite() {
ComponentDto project = db.components().insertPrivateProject();
UserDto user = db.users().insertUser();
- underTest.add(dbSession, project, user.getUuid(), true);
+ underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true);
assertFavorite(project, user);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(String.format("Component '%s' is already a favorite", project.getKey()));
- underTest.add(dbSession, project, user.getUuid(), true);
+ underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true);
}
private void assertFavorite(ComponentDto project, UserDto user) {
}
private void testLoadingFromDatabase(SonarRuntime runtime, boolean isStartupLeader) {
- dbTester.properties().insertProperty(new PropertyDto().setKey(CoreProperties.SERVER_STARTTIME).setValue(formatDateTime(A_DATE)));
+ dbTester.properties().insertProperty(new PropertyDto().setKey(CoreProperties.SERVER_STARTTIME).setValue(formatDateTime(A_DATE)),
+ null, null);
when(webServer.isStartupLeader()).thenReturn(isStartupLeader);
StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient());
@Test
public void send_global_webhooks() {
ComponentDto project = componentDbTester.insertPrivateProject();
- webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"));
- webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"));
+ webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"), null);
+ webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"), null);
caller.enqueueSuccess(NOW, 200, 1_234);
caller.enqueueFailure(NOW, new IOException("Fail to connect"));
@Test
public void isEnabled_returns_true_if_one_valid_global_webhook() {
ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
- webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"));
+ webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName());
assertThat(underTest.isEnabled(projectDto)).isTrue();
}
@Test
public void isEnabled_returns_true_if_one_valid_project_webhook() {
ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
- webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"));
+ webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName());
assertThat(underTest.isEnabled(projectDto)).isTrue();
}
@Test
public void send_global_webhooks() {
ComponentDto componentDto = componentDbTester.insertPrivateProject();
- webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"));
- webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"));
+ webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"), null);
+ webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"), null);
caller.enqueueSuccess(NOW, 200, 1_234);
caller.enqueueFailure(NOW, new IOException("Fail to connect"));
@Test
public void send_project_webhooks() {
ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
- webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"));
+ webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName());
caller.enqueueSuccess(NOW, 200, 1_234);
underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(projectDto.getUuid(), "1", "#1"), () -> mock, taskStatistics);
@Test
public void send_global_and_project_webhooks() {
ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
- webhookDbTester.insert(newWebhook(projectDto).setName("1First").setUrl("http://url1"));
- webhookDbTester.insert(newWebhook(projectDto).setName("2Second").setUrl("http://url2"));
- webhookDbTester.insert(newGlobalWebhook().setName("3Third").setUrl("http://url3"));
- webhookDbTester.insert(newGlobalWebhook().setName("4Fourth").setUrl("http://url4"));
- webhookDbTester.insert(newGlobalWebhook().setName("5Fifth").setUrl("http://url5"));
+ webhookDbTester.insert(newWebhook(projectDto).setName("1First").setUrl("http://url1"), projectDto.getName());
+ webhookDbTester.insert(newWebhook(projectDto).setName("2Second").setUrl("http://url2"), projectDto.getName());
+ webhookDbTester.insert(newGlobalWebhook().setName("3Third").setUrl("http://url3"), null);
+ webhookDbTester.insert(newGlobalWebhook().setName("4Fourth").setUrl("http://url4"), null);
+ webhookDbTester.insert(newGlobalWebhook().setName("5Fifth").setUrl("http://url5"), null);
caller.enqueueSuccess(NOW, 200, 1_234);
caller.enqueueFailure(NOW, new IOException("Fail to connect 1"));
caller.enqueueFailure(NOW, new IOException("Fail to connect 2"));
if (hasExternalPlugins && NOT_ACCEPTED == PluginRiskConsent.valueOf(property.getValue())) {
addWarningInSonarDotLog();
property.setValue(REQUIRED.name());
- dbClient.propertiesDao().saveProperty(session, property);
+ dbClient.propertiesDao().saveProperty(session, property, null, null);
session.commit();
} else if (!hasExternalPlugins && REQUIRED == PluginRiskConsent.valueOf(property.getValue())) {
dbClient.propertiesDao().deleteGlobalProperty(PLUGINS_RISK_CONSENT, session);
public void set(DbSession dbSession, Visibility visibility) {
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
.setKey(PROJECTS_DEFAULT_VISIBILITY_PROPERTY_NAME)
- .setValue(visibility.getLabel()));
+ .setValue(visibility.getLabel()), null, null);
}
}
.setName("Marius2")
.setEmail("marius2@mail.com")
.setScmAccounts(singletonList("ma2")), u -> {
- });
+ });
UserDto updatedUser = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(updatedUser.isActive()).isTrue();
.setName("Marius2")
.setEmail("marius2@email.com")
.setExternalIdentity(new ExternalIdentity("github", "john", "ABCD")), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getExternalId()).isEqualTo("ABCD");
.setName("Marius2")
.setEmail("marius2@email.com")
.setExternalIdentity(new ExternalIdentity("github", "john", "ABCD")), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getExternalId()).isEqualTo("ABCD");
.setEmail("marius2@mail.com")
.setPassword("password2")
.setScmAccounts(asList("ma2", "", null)), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getScmAccountsAsList()).containsOnly("ma2");
underTest.updateAndCommit(session, user, new UpdateUser()
.setLogin("new_login"), u -> {
- });
+ });
assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN)).isNull();
UserDto userReloaded = dbClient.userDao().selectByUuid(session, user.getUuid());
underTest.updateAndCommit(session, user, new UpdateUser()
.setLogin("new_login"), u -> {
- });
+ });
assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN)).isNull();
UserDto userReloaded = dbClient.userDao().selectByUuid(session, user.getUuid());
underTest.updateAndCommit(session, oldUser, new UpdateUser()
.setLogin("new_login"), u -> {
- });
+ });
List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
assertThat(indexUsers).hasSize(1);
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
ComponentDto anotherProject = db.components().insertPrivateProject();
- db.properties().insertProperties(
+ db.properties().insertProperties(oldUser.getLogin(), project1.name(),
new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()),
- new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project1.uuid()),
- new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()),
+ new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project1.uuid()));
+ db.properties().insertProperties(oldUser.getLogin(), project2.name(),
+ new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()));
+ db.properties().insertProperties(oldUser.getLogin(), anotherProject.name(),
new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setComponentUuid(anotherProject.uuid()));
userIndexer.indexAll();
underTest.updateAndCommit(session, oldUser, new UpdateUser()
.setLogin("new_login"), u -> {
- });
+ });
assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setKey(DEFAULT_ISSUE_ASSIGNEE).build(), db.getSession()))
.extracting(PropertyDto::getValue, PropertyDto::getComponentUuid)
underTest.updateAndCommit(session, user, new UpdateUser()
.setName("Marius2"), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getName()).isEqualTo("Marius2");
underTest.updateAndCommit(session, user, new UpdateUser()
.setEmail("marius2@mail.com"), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getEmail()).isEqualTo("marius2@mail.com");
underTest.updateAndCommit(session, user, new UpdateUser()
.setScmAccounts(asList("ma2")), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getScmAccountsAsList()).containsOnly("ma2");
underTest.updateAndCommit(session, user, new UpdateUser()
.setScmAccounts(asList("ma", "marius33")), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
underTest.updateAndCommit(session, user, new UpdateUser()
.setScmAccounts(null), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getScmAccounts()).isNull();
underTest.updateAndCommit(session, user, new UpdateUser()
.setPassword("password2"), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getSalt()).isNotEqualTo("salt");
underTest.updateAndCommit(session, user, new UpdateUser()
.setPassword("password2"), u -> {
- });
+ });
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
assertThat(dto.getSalt()).isNotEqualTo("salt");
.setEmail(user.getEmail())
.setScmAccounts(user.getScmAccountsAsList())
.setExternalIdentity(new ExternalIdentity(user.getExternalIdentityProvider(), user.getExternalLogin(), user.getExternalId())), u -> {
- });
+ });
assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN).getUpdatedAt()).isEqualTo(user.getUpdatedAt());
}
.setEmail(user.getEmail())
.setScmAccounts(asList("ma2", "ma1"))
.setExternalIdentity(new ExternalIdentity(user.getExternalIdentityProvider(), user.getExternalLogin(), user.getExternalId())), u -> {
- });
+ });
assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN).getUpdatedAt()).isEqualTo(user.getUpdatedAt());
}
.setEmail("marius2@mail.com")
.setPassword("password2")
.setScmAccounts(asList("ma2")), u -> {
- }, otherUser);
+ }, otherUser);
assertThat(es.getIds(UserIndexDefinition.TYPE_USER)).containsExactlyInAnyOrder(user.getUuid(), otherUser.getUuid());
}
.setEmail("marius2@mail.com")
.setPassword("password2")
.setScmAccounts(asList("ma2")), u -> {
- });
+ });
Multimap<String, String> groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(defaultGroup.getName()))).isFalse();
.setEmail("marius2@mail.com")
.setPassword("password2")
.setScmAccounts(asList("ma2")), u -> {
- });
+ });
// Nothing as changed
groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
if (value == null) {
dbClient.propertiesDao().deleteGlobalProperty(key, dbSession);
} else {
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value));
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value), null, null);
}
// refresh the cache of settings
delegate.setProperty(key, value);
}
private void persistServerId(DbSession dbSession, ServerId serverId) {
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SERVER_ID).setValue(serverId.toString()));
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SERVER_ID).setValue(serverId.toString()), null, null);
}
private void persistChecksum(DbSession dbSession, String checksump) {
}
private void insertGroupPermission(DbSession dbSession, PermissionTemplateDto template, String permission, GroupDto group) {
- dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission);
+ dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission, template.getName(), group.getName());
}
}
try {
test(SERVER);
fail("An ISE should have been raised");
- }
- catch (IllegalStateException e) {
+ } catch (IllegalStateException e) {
assertThat(e.getMessage()).isEqualTo("Server ID is invalid");
// no changes
verifyDb(serverId, dbChecksum);
try {
test(SERVER);
fail("An ISE should have been raised");
- }
- catch (IllegalStateException e) {
+ } catch (IllegalStateException e) {
assertThat(e.getMessage()).isEqualTo("Server ID is invalid");
// no changes
verifyDb(serverId, dbChecksum);
@DataProvider
public static Object[][] allFormatsOfServerId() {
- return new Object[][] {
- {OLD_FORMAT_SERVER_ID},
- {NO_DATABASE_ID_SERVER_ID},
- {WITH_DATABASE_ID_SERVER_ID}
+ return new Object[][]{
+ {OLD_FORMAT_SERVER_ID},
+ {NO_DATABASE_ID_SERVER_ID},
+ {WITH_DATABASE_ID_SERVER_ID}
};
}
}
private void insertServerId(String serverId) {
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(CoreProperties.SERVER_ID).setValue(serverId));
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(CoreProperties.SERVER_ID).setValue(serverId),
+ null, null);
dbSession.commit();
}
.setGroupUuid(group.getUuid())
.setRole(USER)
.setComponentUuid(project.uuid());
- dbClient.groupPermissionDao().insert(dbSession, dto);
+ dbClient.groupPermissionDao().insert(dbSession, dto, project);
}
dbSession.commit();
if (almPatDto.isPresent()) {
AlmPatDto almPat = almPatDto.get();
almPat.setPersonalAccessToken(resultingPat);
- dbClient.almPatDao().update(dbSession, almPat);
+ dbClient.almPatDao().update(dbSession, almPat, userSession.getLogin(), almSetting.getKey());
} else {
AlmPatDto almPat = new AlmPatDto()
.setPersonalAccessToken(resultingPat)
.setAlmSettingUuid(almSetting.getUuid())
.setUserUuid(userUuid);
- dbClient.almPatDao().insert(dbSession, almPat);
+ dbClient.almPatDao().insert(dbSession, almPat, userSession.getLogin(), almSetting.getKey());
}
dbSession.commit();
}
package org.sonar.server.almintegration.ws.azure;
import com.google.common.annotations.VisibleForTesting;
-
import java.util.Optional;
-
import org.sonar.alm.client.azure.AzureDevOpsHttpClient;
import org.sonar.alm.client.azure.GsonAzureRepo;
import org.sonar.api.server.ws.Request;
.setQualifier(PROJECT)
.build(),
userSession.isLoggedIn() ? userSession.getUuid() : null,
+ userSession.isLoggedIn() ? userSession.getLogin() : null,
repo.getDefaultBranchName(),
s -> {
});
.setAlmSlug(repo.getProject().getName())
.setProjectUuid(componentDto.uuid())
.setMonorepo(false);
- dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto);
+ dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name());
}
@VisibleForTesting
.setQualifier(PROJECT)
.build();
String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
+ String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
- return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, defaultBranchName, p -> {
+ return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userLogin, defaultBranchName, p -> {
});
}
.setAlmRepo(repo.getSlug())
.setProjectUuid(componentDto.uuid())
.setMonorepo(false);
- dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto);
+ dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name());
}
}
.setQualifier(PROJECT)
.build();
String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
+ String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
- return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, defaultBranchName, p -> {});
+ return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userLogin, defaultBranchName, p -> {});
}
private void populatePRSetting(DbSession dbSession, Repository repo, ComponentDto componentDto, AlmSettingDto almSettingDto) {
.setAlmSlug(repo.getSlug())
.setProjectUuid(componentDto.uuid())
.setMonorepo(false);
- dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto);
+ dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name());
}
}
.setPrivate(visibility)
.setQualifier(PROJECT)
.build(),
- userSession.getUuid(), mainBranchName, s -> {});
+ userSession.getUuid(), userSession.getLogin(), mainBranchName, s -> {});
}
static String getProjectKeyFromRepository(Repository repo) {
.setProjectUuid(componentDto.uuid())
.setSummaryCommentEnabled(true)
.setMonorepo(false);
- dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto);
+ dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name());
}
}
if (almPatDto.isPresent()) {
AlmPatDto almPat = almPatDto.get();
almPat.setPersonalAccessToken(accessToken.getValue());
- dbClient.almPatDao().update(dbSession, almPat);
+ dbClient.almPatDao().update(dbSession, almPat, userSession.getLogin(), almSettingDto.getKey());
} else {
AlmPatDto almPat = new AlmPatDto()
.setPersonalAccessToken(accessToken.getValue())
.setAlmSettingUuid(almSettingDto.getUuid())
.setUserUuid(userUuid);
- dbClient.almPatDao().insert(dbSession, almPat);
+ dbClient.almPatDao().insert(dbSession, almPat, userSession.getLogin(), almSettingDto.getKey());
}
dbSession.commit();
} else {
private void populateMRSetting(DbSession dbSession, Long gitlabProjectId, ComponentDto componentDto, AlmSettingDto almSettingDto) {
dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, new ProjectAlmSettingDto()
- .setProjectUuid(componentDto.projectUuid())
- .setAlmSettingUuid(almSettingDto.getUuid())
- .setAlmRepo(gitlabProjectId.toString())
- .setAlmSlug(null)
- .setMonorepo(false));
+ .setProjectUuid(componentDto.projectUuid())
+ .setAlmSettingUuid(almSettingDto.getUuid())
+ .setAlmRepo(gitlabProjectId.toString())
+ .setAlmSlug(null)
+ .setMonorepo(false),
+ almSettingDto.getKey(),
+ componentDto.name());
}
private ComponentDto createProject(DbSession dbSession, Project gitlabProject, @Nullable String mainBranchName) {
String sqProjectKey = generateProjectKey(gitlabProject.getPathWithNamespace(), uuidFactory.create());
return componentUpdater.createWithoutCommit(dbSession, newComponentBuilder()
- .setKey(sqProjectKey)
- .setName(gitlabProject.getName())
- .setPrivate(visibility)
- .setQualifier(PROJECT)
- .build(),
- userSession.getUuid(), mainBranchName, s -> {
+ .setKey(sqProjectKey)
+ .setName(gitlabProject.getName())
+ .setPrivate(visibility)
+ .setQualifier(PROJECT)
+ .build(),
+ userSession.getUuid(), userSession.getLogin(), mainBranchName, s -> {
});
}
private ComponentDto createProject(DbSession dbSession, BranchSupport.ComponentKey componentKey, @Nullable String projectName) {
userSession.checkPermission(GlobalPermission.PROVISION_PROJECTS);
String userUuid = userSession.getUuid();
+ String userName = userSession.getLogin();
boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(
dbSession, userUuid, componentKey.getDbKey());
.setQualifier(Qualifiers.PROJECT)
.setPrivate(getDefaultVisibility(dbSession).isPrivate())
.build();
- return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, c -> {
+ return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userName, c -> {
});
}
* - Add component to favorite if the component has the 'Project Creators' permission
* - Index component in es indexes
*/
- public ComponentDto create(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid) {
- ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, c -> {
+ public ComponentDto create(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid, @Nullable String userLogin) {
+ ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, userLogin, c -> {
});
commitAndIndex(dbSession, componentDto);
return componentDto;
* Don't forget to call commitAndIndex(...) when ready to commit.
*/
public ComponentDto createWithoutCommit(DbSession dbSession, NewComponent newComponent,
- @Nullable String userUuid, Consumer<ComponentDto> componentModifier) {
- return createWithoutCommit(dbSession, newComponent, userUuid, null, componentModifier);
+ @Nullable String userUuid, @Nullable String userLogin, Consumer<ComponentDto> componentModifier) {
+ return createWithoutCommit(dbSession, newComponent, userUuid, userLogin, null, componentModifier);
}
/**
* Don't forget to call commitAndIndex(...) when ready to commit.
*/
public ComponentDto createWithoutCommit(DbSession dbSession, NewComponent newComponent,
- @Nullable String userUuid, @Nullable String mainBranchName,
+ @Nullable String userUuid, @Nullable String userLogin, @Nullable String mainBranchName,
Consumer<ComponentDto> componentModifier) {
checkKeyFormat(newComponent.qualifier(), newComponent.key());
ComponentDto componentDto = createRootComponent(dbSession, newComponent, componentModifier);
if (isRootProject(componentDto)) {
createMainBranch(dbSession, componentDto.uuid(), mainBranchName);
}
- handlePermissionTemplate(dbSession, componentDto, userUuid);
+ handlePermissionTemplate(dbSession, componentDto, userUuid, userLogin);
return componentDto;
}
dbClient.branchDao().upsert(session, branch);
}
- private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid) {
+ private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid, @Nullable String userLogin) {
permissionTemplateService.applyDefault(dbSession, componentDto, userUuid);
if (componentDto.qualifier().equals(PROJECT)
&& permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(dbSession, componentDto)) {
- favoriteUpdater.add(dbSession, componentDto, userUuid, false);
+ favoriteUpdater.add(dbSession, componentDto, userUuid, userLogin, false);
}
}
userSession
.checkLoggedIn()
.checkComponentPermission(USER, componentDto);
- favoriteUpdater.add(dbSession, componentDto, userSession.isLoggedIn() ? userSession.getUuid() : null, true);
+ String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
+ String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
+ favoriteUpdater.add(dbSession, componentDto, userUuid, userLogin, true);
dbSession.commit();
}
};
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByKey(dbSession, request.mandatoryParam(PARAM_COMPONENT));
userSession.checkLoggedIn();
- favoriteUpdater.remove(dbSession, component, userSession.isLoggedIn() ? userSession.getUuid() : null);
+ favoriteUpdater.remove(dbSession, component,
+ userSession.isLoggedIn() ? userSession.getUuid() : null,
+ userSession.isLoggedIn() ? userSession.getLogin() : null);
dbSession.commit();
}
};
public void add(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) {
String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel);
String projectUuid = project == null ? null : project.uuid();
+ String projectName = project == null ? null : project.name();
List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery(
PropertyQuery.builder()
.setKey(key)
.setUserUuid(user.getUuid())
.setValue(PROP_NOTIFICATION_VALUE)
- .setComponentUuid(projectUuid));
+ .setComponentUuid(projectUuid),
+ user.getLogin(), projectName);
}
/**
public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) {
String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel);
String projectUuid = project == null ? null : project.uuid();
+ String projectName = project == null ? null : project.name();
List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery(
PropertyQuery.builder()
.setKey(key)
.setUserUuid(user.getUuid())
.setValue(PROP_NOTIFICATION_VALUE)
- .setComponentUuid(projectUuid));
+ .setComponentUuid(projectUuid), user.getLogin(), projectName);
}
private static Predicate<PropertyDto> notificationScope(@Nullable ComponentDto project) {
.setRole(change.getPermission())
.setGroupUuid(change.getGroupUuidOrAnyone().getUuid())
.setComponentUuid(change.getProjectUuid());
- dbClient.groupPermissionDao().insert(dbSession, addedDto);
+ dbClient.groupPermissionDao().insert(dbSession, addedDto, change.getProject());
return true;
}
dbClient.groupPermissionDao().delete(dbSession,
change.getPermission(),
change.getGroupUuidOrAnyone().getUuid(),
- change.getProjectUuid());
+ change.getProjectUuid(),
+ change.getProject());
return true;
}
}
private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable String projectCreatorUserUuid) {
- dbClient.groupPermissionDao().deleteByRootComponentUuid(dbSession, project.uuid());
- dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.uuid());
+ dbClient.groupPermissionDao().deleteByRootComponentUuid(dbSession, project.uuid(), project.name());
+ dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.uuid(), project.name());
List<PermissionTemplateUserDto> usersPermissions = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateId(dbSession, template.getUuid());
Map<String, String> userDtoMap = dbClient.userDao().selectByUuids(dbSession, usersPermissions.stream().map(PermissionTemplateUserDto::getUserUuid).collect(Collectors.toSet()))
.filter(up -> permissionValidForProject(project, up.getPermission()))
.forEach(up -> {
UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), up.getPermission(), userDtoMap.get(up.getUserUuid()), project.uuid());
- dbClient.userPermissionDao().insert(dbSession, dto);
+ dbClient.userPermissionDao().insert(dbSession, dto, project);
});
List<PermissionTemplateGroupDto> groupsPermissions = dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateUuid(dbSession, template.getUuid());
.setGroupUuid(isAnyone(gp.getGroupName()) ? null : gp.getGroupUuid())
.setRole(gp.getPermission())
.setComponentUuid(project.uuid());
- dbClient.groupPermissionDao().insert(dbSession, dto);
+ dbClient.groupPermissionDao().insert(dbSession, dto, project);
});
List<PermissionTemplateCharacteristicDto> characteristics = dbClient.permissionTemplateCharacteristicDao().selectByTemplateUuids(dbSession, singletonList(template.getUuid()));
.filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission()))
.forEach(c -> {
UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), c.getPermission(), userDto.getUuid(), project.uuid());
- dbClient.userPermissionDao().insert(dbSession, dto);
+ dbClient.userPermissionDao().insert(dbSession, dto, project);
});
}
}
}
UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), change.getPermission(), change.getUserId().getUuid(),
change.getProjectUuid());
- dbClient.userPermissionDao().insert(dbSession, dto);
+ dbClient.userPermissionDao().insert(dbSession, dto, change.getProject());
return true;
}
}
checkOtherAdminsExist(dbSession, change);
String projectUuid = change.getProjectUuid();
+ String projectName = change.getProject() == null ? null : change.getProject().name();
if (projectUuid != null) {
- dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getUuid(), change.getPermission(), projectUuid);
+ dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getUuid(), change.getPermission(),
+ projectUuid, projectName);
} else {
dbClient.userPermissionDao().deleteGlobalPermission(dbSession, change.getUserId().getUuid(), change.getPermission());
}
import static org.sonar.server.permission.ws.WsParameters.createGroupNameParameter;
import static org.sonar.server.permission.ws.WsParameters.createTemplateParameters;
import static org.sonar.server.permission.ws.template.WsTemplateRef.fromRequest;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
public class AddGroupToTemplateAction implements PermissionsWsAction {
checkGlobalAdmin(userSession);
if (!groupAlreadyAdded(dbSession, template.getUuid(), permission, group)) {
- dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission);
+ dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission,
+ template.getName(), request.param(PARAM_GROUP_NAME));
dbSession.commit();
}
}
Optional<PermissionTemplateCharacteristicDto> templatePermission = dbClient.permissionTemplateCharacteristicDao()
.selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getUuid());
if (templatePermission.isPresent()) {
- updateTemplatePermission(dbSession, templatePermission.get());
+ updateTemplatePermission(dbSession, templatePermission.get(), template.getName());
} else {
addTemplatePermission(dbSession, request, template);
}
private void addTemplatePermission(DbSession dbSession, AddProjectCreatorToTemplateRequest request, PermissionTemplateDto template) {
long now = system.now();
dbClient.permissionTemplateCharacteristicDao().insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid(Uuids.create())
- .setPermission(request.getPermission())
- .setTemplateUuid(template.getUuid())
- .setWithProjectCreator(true)
- .setCreatedAt(now)
- .setUpdatedAt(now));
+ .setUuid(Uuids.create())
+ .setPermission(request.getPermission())
+ .setTemplateUuid(template.getUuid())
+ .setWithProjectCreator(true)
+ .setCreatedAt(now)
+ .setUpdatedAt(now),
+ template.getName());
dbSession.commit();
}
- private void updateTemplatePermission(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission) {
+ private void updateTemplatePermission(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission, String templateName) {
PermissionTemplateCharacteristicDto targetTemplatePermission = templatePermission
.setUpdatedAt(system.now())
.setWithProjectCreator(true);
- dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission);
+ dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission, templateName);
dbSession.commit();
}
UserId user = wsSupport.findUser(dbSession, userLogin);
if (!isUserAlreadyAdded(dbSession, template.getUuid(), userLogin, permission)) {
- dbClient.permissionTemplateDao().insertUserPermission(dbSession, template.getUuid(), user.getUuid(), permission);
+ dbClient.permissionTemplateDao().insertUserPermission(dbSession, template.getUuid(), user.getUuid(), permission,
+ template.getName(), user.getLogin());
dbSession.commit();
}
}
checkGlobalAdmin(userSession);
checkTemplateUuidIsNotDefault(dbSession, template);
- dbClient.permissionTemplateDao().deleteByUuid(dbSession, template.getUuid());
+ dbClient.permissionTemplateDao().deleteByUuid(dbSession, template.getUuid(), template.getName());
dbSession.commit();
}
}
import static org.sonar.server.permission.ws.WsParameters.createGroupIdParameter;
import static org.sonar.server.permission.ws.WsParameters.createGroupNameParameter;
import static org.sonar.server.permission.ws.WsParameters.createTemplateParameters;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
checkGlobalAdmin(userSession);
GroupUuidOrAnyone group = wsSupport.findGroup(dbSession, request);
- dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission);
+ dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission,
+ template.getName(), request.param(PARAM_GROUP_NAME));
dbSession.commit();
}
response.noContent();
PermissionTemplateCharacteristicDao dao = dbClient.permissionTemplateCharacteristicDao();
dao.selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getUuid())
- .ifPresent(permissionTemplateCharacteristicDto -> updateTemplateCharacteristic(dbSession, permissionTemplateCharacteristicDto));
+ .ifPresent(permissionTemplateCharacteristicDto -> updateTemplateCharacteristic(dbSession, permissionTemplateCharacteristicDto,
+ template.getName()));
}
}
- private void updateTemplateCharacteristic(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission) {
+ private void updateTemplateCharacteristic(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission, String templateName) {
PermissionTemplateCharacteristicDto targetTemplatePermission = templatePermission
.setUpdatedAt(system.now())
.setWithProjectCreator(false);
- dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission);
+ dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission, templateName);
dbSession.commit();
}
UserId user = wsSupport.findUser(dbSession, userLogin);
- dbClient.permissionTemplateDao().deleteUserPermission(dbSession, template.getUuid(), user.getUuid(), permission);
+ dbClient.permissionTemplateDao().deleteUserPermission(dbSession, template.getUuid(), user.getUuid(), permission, template.getName(), user.getLogin());
dbSession.commit();
}
}
.setPrivate(changeToPrivate)
.setQualifier(PROJECT)
.build(),
- userSession.isLoggedIn() ? userSession.getUuid() : null);
+ userSession.isLoggedIn() ? userSession.getUuid() : null,
+ userSession.isLoggedIn() ? userSession.getLogin() : null);
return toCreateResponse(componentDto);
}
}
private final Configuration configuration;
public UpdateVisibilityAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession,
- ProjectIndexers projectIndexers, UuidFactory uuidFactory, Configuration configuration) {
+ ProjectIndexers projectIndexers, UuidFactory uuidFactory, Configuration configuration) {
this.dbClient = dbClient;
this.componentFinder = componentFinder;
this.userSession = userSession;
private void updatePermissionsToPrivate(DbSession dbSession, ComponentDto component) {
// delete project permissions for group AnyOne
- dbClient.groupPermissionDao().deleteByRootComponentUuidAndGroupUuid(dbSession, component.uuid(), null);
+ dbClient.groupPermissionDao().deleteByRootComponentUuidAndGroupUuid(dbSession, component.uuid(), null, component.name());
// grant UserRole.CODEVIEWER and UserRole.USER to any group or user with at least one permission on project
PUBLIC_PERMISSIONS.forEach(permission -> {
dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnProjectBut(dbSession, component.uuid(), permission)
}
private void insertProjectPermissionOnUser(DbSession dbSession, ComponentDto component, String permission, String userUuid) {
- dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), permission, userUuid, component.uuid()));
+ dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), permission, userUuid, component.uuid()),
+ component);
}
private void insertProjectPermissionOnGroup(DbSession dbSession, ComponentDto component, String permission, String groupUuid) {
dbClient.groupPermissionDao().insert(dbSession, new GroupPermissionDto()
- .setUuid(uuidFactory.create())
- .setComponentUuid(component.uuid())
- .setGroupUuid(groupUuid)
- .setRole(permission));
+ .setUuid(uuidFactory.create())
+ .setComponentUuid(component.uuid())
+ .setGroupUuid(groupUuid)
+ .setRole(permission),
+ component);
}
private void updatePermissionsToPublic(DbSession dbSession, ComponentDto component) {
PUBLIC_PERMISSIONS.forEach(permission -> {
// delete project group permission for UserRole.CODEVIEWER and UserRole.USER
- dbClient.groupPermissionDao().deleteByRootComponentUuidAndPermission(dbSession, component.uuid(), permission);
+ dbClient.groupPermissionDao().deleteByRootComponentUuidAndPermission(dbSession, component.uuid(), permission, component.name());
// delete project user permission for UserRole.CODEVIEWER and UserRole.USER
- dbClient.userPermissionDao().deleteProjectPermissionOfAnyUser(dbSession, component.uuid(), permission);
+ dbClient.userPermissionDao().deleteProjectPermissionOfAnyUser(dbSession, component.uuid(), permission, component.name());
});
}
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Settings.GenerateSecretKeyWsResponse;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
public class GenerateSecretKeyAction implements SettingsWsAction {
+ private final DbClient dbClient;
private final Settings settings;
private final UserSession userSession;
+ private AuditPersister auditPersister;
- public GenerateSecretKeyAction(Settings settings, UserSession userSession) {
+ public GenerateSecretKeyAction(DbClient dbClient, Settings settings, UserSession userSession) {
+ this.dbClient = dbClient;
this.settings = settings;
this.userSession = userSession;
}
+ public GenerateSecretKeyAction(DbClient dbClient, Settings settings, UserSession userSession, AuditPersister auditPersister) {
+ this.dbClient = dbClient;
+ this.settings = settings;
+ this.userSession = userSession;
+ this.auditPersister = auditPersister;
+ }
+
@Override
public void define(WebService.NewController context) {
context.createAction("generate_secret_key")
userSession.checkIsSystemAdministrator();
writeProtobuf(GenerateSecretKeyWsResponse.newBuilder().setSecretKey(settings.getEncryption().generateRandomSecretKey()).build(), request, response);
+
+ if (auditPersister != null) {
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ auditPersister.generateSecretKey(dbSession);
+ dbSession.commit();
+ }
+ }
}
}
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("set")
.setDescription("Update a setting value.<br>" +
- "Either '%s' or '%s' must be provided.<br> " +
- "The settings defined in conf/sonar.properties are read-only and can't be changed.<br/>" +
- "Requires one of the following permissions: " +
- "<ul>" +
- "<li>'Administer System'</li>" +
- "<li>'Administer' rights on the specified component</li>" +
- "</ul>",
+ "Either '%s' or '%s' must be provided.<br> " +
+ "The settings defined in conf/sonar.properties are read-only and can't be changed.<br/>" +
+ "Requires one of the following permissions: " +
+ "<ul>" +
+ "<li>'Administer System'</li>" +
+ "<li>'Administer' rights on the specified component</li>" +
+ "</ul>",
PARAM_VALUE, PARAM_VALUES)
.setSince("6.1")
.setChangelog(
private void doHandle(DbSession dbSession, SetRequest request) {
Optional<ComponentDto> component = searchComponent(dbSession, request);
+ String projectName = component.isPresent() ? component.get().name() : null;
checkPermissions(component);
PropertyDefinition definition = propertyDefinitions.get(request.getKey());
validate(request);
PropertyDto property = toProperty(request, component);
value = property.getValue();
- dbClient.propertiesDao().saveProperty(dbSession, property);
+ dbClient.propertiesDao().saveProperty(dbSession, property, null, projectName);
}
dbSession.commit();
String inlinedFieldKeys = IntStream.of(fieldIds).mapToObj(String::valueOf).collect(COMMA_JOINER);
String key = persistedKey(request);
String componentUuid = component.isPresent() ? component.get().uuid() : null;
+ String componentName = component.isPresent() ? component.get().name() : null;
deleteSettings(dbSession, component, key);
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setComponentUuid(componentUuid));
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys)
+ .setComponentUuid(componentUuid), null, componentName);
List<String> fieldValues = request.getFieldValues();
IntStream.of(fieldIds).boxed()
.flatMap(i -> readOneFieldValues(fieldValues.get(i - 1), request.getKey()).entrySet().stream()
.map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue())))
- .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentUuid)));
+ .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentUuid),
+ null, componentName));
return inlinedFieldKeys;
}
private void deleteSetting(DbSession dbSession, String settingKey, Optional<ComponentDto> componentDto) {
if (componentDto.isPresent()) {
- dbClient.propertiesDao().deleteProjectProperty(settingKey, componentDto.get().uuid(), dbSession);
+ dbClient.propertiesDao().deleteProjectProperty(settingKey, componentDto.get().uuid(), dbSession, componentDto.get().name());
} else {
dbClient.propertiesDao().deleteGlobalProperty(settingKey, dbSession);
}
dbClient.propertiesDao().deleteByQuery(dbSession, PropertyQuery.builder().setUserUuid(userUuid).build());
dbClient.userGroupDao().deleteByUserUuid(dbSession, user);
dbClient.userPermissionDao().deleteByUserUuid(dbSession, userUuid);
- dbClient.permissionTemplateDao().deleteUserPermissionsByUserUuid(dbSession, userUuid);
+ dbClient.permissionTemplateDao().deleteUserPermissionsByUserUuid(dbSession, userUuid, user.getLogin());
dbClient.qProfileEditUsersDao().deleteByUser(dbSession, user);
dbClient.userPropertiesDao().deleteByUser(dbSession, user);
dbClient.almPatDao().deleteByUser(dbSession, user);
}
private void removeFromPermissionTemplates(DbSession dbSession, GroupDto group) {
- dbClient.permissionTemplateDao().deleteByGroup(dbSession, group.getUuid());
+ dbClient.permissionTemplateDao().deleteByGroup(dbSession, group.getUuid(), group.getName());
}
private void removeGroupMembers(DbSession dbSession, GroupDto group) {
webhookSupport.checkUrlPattern(url, "Url parameter with value '%s' is not a valid url", url);
WebhookDto dto = doHandle(dbSession, projectDto, name, url, secret);
- dbClient.webhookDao().insert(dbSession, dto);
+ String projectName = projectDto == null ? null : projectDto.getName();
+ dbClient.webhookDao().insert(dbSession, dto, projectName);
dbSession.commit();
writeResponse(request, response, dto);
}
private void deleteWebhook(DbSession dbSession, WebhookDto webhookDto) {
dbClient.webhookDeliveryDao().deleteByWebhook(dbSession, webhookDto);
- dbClient.webhookDao().delete(dbSession, webhookDto.getUuid());
+ dbClient.webhookDao().delete(dbSession, webhookDto.getUuid(), webhookDto.getName());
}
}
if (projectUuid != null) {
ProjectDto projectDto = componentFinder.getProjectByUuid(dbSession, projectUuid);
webhookSupport.checkPermission(projectDto);
- updateWebhook(dbSession, webhookDto, name, url, secret);
+ updateWebhook(dbSession, webhookDto, name, url, secret, projectDto.getName());
} else {
webhookSupport.checkPermission();
- updateWebhook(dbSession, webhookDto, name, url, secret);
+ updateWebhook(dbSession, webhookDto, name, url, secret, null);
}
dbSession.commit();
response.noContent();
}
- private void updateWebhook(DbSession dbSession, WebhookDto dto, String name, String url, @Nullable String secret) {
+ private void updateWebhook(DbSession dbSession, WebhookDto dto, String name, String url, @Nullable String secret, @Nullable String projectName) {
dto
.setName(name)
.setUrl(url)
.setSecret(secret);
- dbClient.webhookDao().update(dbSession, dto);
+ dbClient.webhookDao().update(dbSession, dto, projectName);
}
}
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest().setParam("almSetting", "testKey");
assertThatThrownBy(request::execute)
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest()
.setParam("almSetting", "testKey");
@Test
public void fail_check_alm_setting_not_found() {
- insertUser();
+ UserDto user = insertUser();
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest()
.setParam("almSetting", "testKey");
@Test
public void fail_check_pat_alm_setting_not_found() {
- insertUser();
+ UserDto user = insertUser();
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest()
.setParam("almSetting", "testKey");
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest()
.setParam("almSetting", "testKey")
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest().setParam("almSetting", "testKey");
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("ALM Setting 'testKey' not found");
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest()
.setParam("almSetting", "testKey");
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("ALM Setting 'testKey' not found");
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
- db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+ db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest()
.setParam("almSetting", "testKey");
BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch);
when(branchSupportDelegate.createComponentKey(nonExistingProject.getDbKey(), randomCharacteristics))
.thenReturn(componentKey);
- when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), any()))
+ when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), eq(user.getLogin()), any()))
.thenAnswer((Answer<ComponentDto>) invocation -> db.components().insertPrivateProject(nonExistingProject));
when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), any()))
.thenReturn(createdBranch);
@Test
public void do_no_add_favorite_when_already_100_favorite_projects_and_no_project_creator_permission_on_permission_template() {
UserDto user = db.users().insertUser();
- rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+ rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid(), user.getLogin()));
userSession
.logIn(user)
.addPermission(GlobalPermission.SCAN)
.setName(DEFAULT_PROJECT_NAME)
.setPrivate(true)
.build();
- ComponentDto returned = underTest.create(db.getSession(), project, null);
+ ComponentDto returned = underTest.create(db.getSession(), project, null, null);
ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
assertThat(loaded.getDbKey()).isEqualTo(DEFAULT_PROJECT_KEY);
.setName(DEFAULT_PROJECT_NAME)
.setPrivate(true)
.build();
- ComponentDto returned = underTest.create(db.getSession(), project, null);
+ ComponentDto returned = underTest.create(db.getSession(), project, null, null);
ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
assertThat(loaded.isPrivate()).isEqualTo(project.isPrivate());
}
.setName(DEFAULT_PROJECT_NAME)
.setPrivate(false)
.build();
- ComponentDto returned = underTest.create(db.getSession(), project, null);
+ ComponentDto returned = underTest.create(db.getSession(), project, null, null);
ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
assertThat(loaded.isPrivate()).isEqualTo(project.isPrivate());
}
.setQualifier(VIEW)
.build();
- ComponentDto returned = underTest.create(db.getSession(), view, null);
+ ComponentDto returned = underTest.create(db.getSession(), view, null, null);
ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
assertThat(loaded.getDbKey()).isEqualTo("view-key");
.setQualifier(APP)
.build();
- ComponentDto returned = underTest.create(db.getSession(), application, null);
+ ComponentDto returned = underTest.create(db.getSession(), application, null, null);
ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
assertThat(loaded.getDbKey()).isEqualTo("app-key");
.setKey(DEFAULT_PROJECT_KEY)
.setName(DEFAULT_PROJECT_NAME)
.build();
- ComponentDto dto = underTest.create(db.getSession(), project, userUuid);
+ ComponentDto dto = underTest.create(db.getSession(), project, userUuid, "user-login");
verify(permissionTemplateService).applyDefault(db.getSession(), dto, userUuid);
}
when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), any(ComponentDto.class)))
.thenReturn(true);
- ComponentDto dto = underTest.create(db.getSession(), project, userDto.getUuid());
+ ComponentDto dto = underTest.create(db.getSession(), project, userDto.getUuid(), userDto.getLogin());
assertThat(db.favorites().hasFavorite(dto, userDto.getUuid())).isTrue();
}
@Test
public void do_not_add_project_to_user_favorites_if_project_creator_is_defined_in_permission_template_and_already_100_favorites() {
UserDto user = db.users().insertUser();
- rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+ rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid(), user.getLogin()));
NewComponent project = NewComponent.newComponentBuilder()
.setKey(DEFAULT_PROJECT_KEY)
.setName(DEFAULT_PROJECT_NAME)
ComponentDto dto = underTest.create(db.getSession(),
project,
- user.getUuid());
+ user.getUuid(),
+ user.getLogin());
assertThat(db.favorites().hasFavorite(dto, user.getUuid())).isFalse();
}
.setKey(DEFAULT_PROJECT_KEY)
.setName(DEFAULT_PROJECT_NAME)
.build(),
- null);
+ null, null);
assertThat(db.favorites().hasNoFavorite(project)).isTrue();
}
.setKey(DEFAULT_PROJECT_KEY)
.setName(DEFAULT_PROJECT_NAME)
.build(),
- null);
+ null, null);
assertThat(db.favorites().hasNoFavorite(project)).isTrue();
}
.setKey(existing.getDbKey())
.setName(DEFAULT_PROJECT_NAME)
.build();
- assertThatThrownBy(() -> underTest.create(session, newComponent, null))
+ assertThatThrownBy(() -> underTest.create(session, newComponent, null, null))
.isInstanceOf(BadRequestException.class)
.hasMessage("Could not create Project, key already exists: " + existing.getDbKey());
}
.setKey("1234")
.setName(DEFAULT_PROJECT_NAME)
.build();
- assertThatThrownBy(() -> underTest.create(session, newComponent, null))
+ assertThatThrownBy(() -> underTest.create(session, newComponent, null, null))
.isInstanceOf(BadRequestException.class)
.hasMessageContaining("Malformed key for Project: '1234'");
}
.setKey("roject%Key")
.setName(DEFAULT_PROJECT_NAME)
.build();
- assertThatThrownBy(() -> underTest.create(session, newComponent, null))
+ assertThatThrownBy(() -> underTest.create(session, newComponent, null, null))
.isInstanceOf(BadRequestException.class)
.hasMessageContaining("Malformed key for Project: 'roject%Key'");
}
public void component_is_favorite() {
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn("john").addProjectPermission(USER, project);
- db.favorites().add(project, userSession.getUuid());
+ db.favorites().add(project, userSession.getUuid(), userSession.getLogin());
String result = ws.newRequest()
.setParam("component", project.getKey())
@DataProvider
public static Object[][] rating_metric_keys() {
- return new Object[][] {{SQALE_RATING_KEY}, {RELIABILITY_RATING_KEY}, {SECURITY_RATING_KEY}};
+ return new Object[][]{{SQALE_RATING_KEY}, {RELIABILITY_RATING_KEY}, {SECURITY_RATING_KEY}};
}
@DataProvider
public static Object[][] new_rating_metric_keys() {
- return new Object[][] {{NEW_MAINTAINABILITY_RATING_KEY}, {NEW_RELIABILITY_RATING_KEY}, {NEW_SECURITY_RATING_KEY}};
+ return new Object[][]{{NEW_MAINTAINABILITY_RATING_KEY}, {NEW_RELIABILITY_RATING_KEY}, {NEW_SECURITY_RATING_KEY}};
}
@DataProvider
public static Object[][] component_qualifiers_for_valid_editions() {
- return new Object[][] {
- {new String[] {Qualifiers.PROJECT}, Edition.COMMUNITY},
- {new String[] {Qualifiers.APP, Qualifiers.PROJECT}, Edition.DEVELOPER},
- {new String[] {Qualifiers.APP, Qualifiers.PROJECT}, Edition.ENTERPRISE},
- {new String[] {Qualifiers.APP, Qualifiers.PROJECT}, Edition.DATACENTER},
+ return new Object[][]{
+ {new String[]{Qualifiers.PROJECT}, Edition.COMMUNITY},
+ {new String[]{Qualifiers.APP, Qualifiers.PROJECT}, Edition.DEVELOPER},
+ {new String[]{Qualifiers.APP, Qualifiers.PROJECT}, Edition.ENTERPRISE},
+ {new String[]{Qualifiers.APP, Qualifiers.PROJECT}, Edition.DATACENTER},
};
}
@DataProvider
public static Object[][] community_or_developer_edition() {
- return new Object[][] {
+ return new Object[][]{
{Edition.COMMUNITY},
{Edition.DEVELOPER},
};
@DataProvider
public static Object[][] enterprise_or_datacenter_edition() {
- return new Object[][] {
+ return new Object[][]{
{Edition.ENTERPRISE},
{Edition.DATACENTER},
};
Stream.of(javaProject, markDownProject).forEach(this::addFavourite);
index();
- addFavourite((String) null);
+ addFavourite(null, null);
SearchProjectsWsResponse result = call(request.setFilter("isFavorite"));
List<Component> projects = call(request
.setFilter("alert_status = WARN"))
- .getComponentsList();
+ .getComponentsList();
assertThat(projects)
.extracting(Component::getKey)
}
private void addFavourite(ComponentDto project) {
- addFavourite(project.uuid());
+ addFavourite(project.uuid(), project.name());
}
- private void addFavourite(@Nullable String componentUuid) {
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setComponentUuid(componentUuid).setUserUuid(userSession.getUuid()));
+ private void addFavourite(@Nullable String componentUuid, @Nullable String componentName) {
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite")
+ .setComponentUuid(componentUuid).setUserUuid(userSession.getUuid()), userSession.getLogin(), componentName);
dbSession.commit();
}
public void remove_a_favorite_project() {
ComponentDto project = insertProjectAndPermissions();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- db.favorites().add(project, user.getUuid());
- db.favorites().add(file, user.getUuid());
+ db.favorites().add(project, user.getUuid(), user.getLogin());
+ db.favorites().add(file, user.getUuid(), user.getLogin());
TestResponse result = call(PROJECT_KEY);
public class SearchActionTest {
private String userUuid;
+ private String userLogin;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
UserDto userDto = db.users().insertUser();
userSession.logIn(userDto);
userUuid = userDto.getUuid();
+ userLogin = userDto.getLogin();
}
@Test
public void filter_authorized_components() {
addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1"));
ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto());
- db.favorites().add(unauthorizedProject, userUuid);
+ db.favorites().add(unauthorizedProject, userUuid, userLogin);
SearchResponse result = call();
IntStream.rangeClosed(1, 9)
.forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K" + i).setName("N" + i)));
ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto());
- db.favorites().add(unauthorizedProject, userUuid);
+ db.favorites().add(unauthorizedProject, userUuid, userLogin);
SearchResponse result = call(2, 3);
addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1"));
ComponentDto otherUserFavorite = ComponentTesting.newPrivateProjectDto().setDbKey("K42");
db.components().insertComponent(otherUserFavorite);
- db.favorites().add(otherUserFavorite, "42");
+ db.favorites().add(otherUserFavorite, "42", userLogin);
db.commit();
SearchResponse result = call();
private void addComponent(ComponentDto component) {
db.components().insertComponent(component);
- db.favorites().add(component, userUuid);
+ db.favorites().add(component, userUuid, userLogin);
db.commit();
userSession.addProjectPermission(UserRole.USER, component);
}
.setUuid(Uuids.createFast())
.setGroupUuid(null)
.setComponentUuid(project.uuid())
- .setRole(permission));
+ .setRole(permission),
+ project);
session.commit();
userSession.logIn().addProjectPermission(permission, project);
}
.setGroupUuid(null)
.setRole(perm)
.setComponentUuid(privateProject.uuid());
- db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+ db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, privateProject);
db.commit();
}
}
dbTester.users().insertMember(group, user);
PermissionTemplateDto template = templateDb.insertTemplate();
dbTester.permissionTemplates().setDefaultTemplates(template, null, null);
- templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN.getKey());
- templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER);
- templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER);
- templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN);
+ templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN.getKey(), template.getName());
+ templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER, template.getName(), user.getLogin());
+ templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER, template.getName(), group.getName());
+ templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN, template.getName(), null);
// authenticated user
checkWouldUserHaveScanPermission(user.getUuid(), true);
.setGroupUuid(null)
.setRole(perm)
.setComponentUuid(project.uuid());
- db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+ db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project);
db.commit();
}
}
.setPermission(UserRole.USER)
.setWithProjectCreator(false)
.setCreatedAt(1_000_000_000L)
- .setUpdatedAt(1_000_000_000L));
+ .setUpdatedAt(1_000_000_000L),
+ template.getName());
db.commit();
when(system.now()).thenReturn(3_000_000_000L);
}
private void addUserToTemplate(UserDto user, PermissionTemplateDto permissionTemplate, String permission) {
- db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), permissionTemplate.getUuid(), user.getUuid(), permission);
+ db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), permissionTemplate.getUuid(), user.getUuid(),
+ permission, permissionTemplate.getName(), user.getLogin());
db.commit();
}
private void addGroupToTemplate(GroupDto group, PermissionTemplateDto permissionTemplate, String permission) {
- db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(), permission);
+ db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(),
+ permission, permissionTemplate.getName(), group.getName());
db.commit();
}
}
private void addUserToTemplate(UserDto user, PermissionTemplateDto permissionTemplate, String permission) {
- db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), permissionTemplate.getUuid(), user.getUuid(), permission);
+ db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), permissionTemplate.getUuid(), user.getUuid(),
+ permission, permissionTemplate.getName(), user.getLogin());
db.commit();
}
private void addGroupToTemplate(GroupDto group, PermissionTemplateDto permissionTemplate, String permission) {
- db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(), permission);
+ db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(),
+ permission, permissionTemplate.getName(), group.getName());
db.commit();
}
PermissionTemplateDto dto = db.permissionTemplates().insertTemplate();
UserDto user = db.getDbClient().userDao().insert(db.getSession(), UserTesting.newUserDto().setActive(true));
GroupDto group = db.getDbClient().groupDao().insert(db.getSession(), GroupTesting.newGroupDto());
- db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getUuid(), user.getUuid(), UserRole.ADMIN);
- db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), dto.getUuid(), group.getUuid(), UserRole.CODEVIEWER);
+ db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getUuid(), user.getUuid(), UserRole.ADMIN,
+ dto.getName(), user.getLogin());
+ db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), dto.getUuid(), group.getUuid(), UserRole.CODEVIEWER,
+ dto.getName(), group.getName());
db.commit();
return dto;
}
group = db.users().insertGroup("group-name");
template = db.permissionTemplates().insertTemplate();
- addGroupToTemplate(template, group.getUuid(), PERMISSION);
+ addGroupToTemplate(template, group.getUuid(), PERMISSION, group.getName());
}
@Test
@Test
public void remove_anyone_group_from_template() {
- addGroupToTemplate(template, null, PERMISSION);
+ addGroupToTemplate(template, null, PERMISSION, null);
newRequest(ANYONE, template.getUuid(), PERMISSION);
request.execute();
}
- private void addGroupToTemplate(PermissionTemplateDto template, @Nullable String groupUuid, String permission) {
- db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), groupUuid, permission);
+ private void addGroupToTemplate(PermissionTemplateDto template, @Nullable String groupUuid, String permission, String groupName) {
+ db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), groupUuid,
+ permission, template.getName(), groupName);
db.commit();
}
.setPermission(UserRole.USER)
.setWithProjectCreator(false)
.setCreatedAt(1_000_000_000L)
- .setUpdatedAt(1_000_000_000L));
+ .setUpdatedAt(1_000_000_000L),
+ template.getName());
db.commit();
when(system.now()).thenReturn(3_000_000_000L);
}
private void addUserToTemplate(UserDto user, PermissionTemplateDto template, String permission) {
- db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), template.getUuid(), user.getUuid(), permission);
+ db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), template.getUuid(), user.getUuid(), permission,
+ template.getName(), user.getLogin());
db.commit();
}
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();
- addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.ISSUE_ADMIN);
- addUserToTemplate(projectTemplate.getUuid(), user2.getUuid(), UserRole.ISSUE_ADMIN);
- addUserToTemplate(projectTemplate.getUuid(), user3.getUuid(), UserRole.ISSUE_ADMIN);
- addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.CODEVIEWER);
- addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN);
- addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN);
+ addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user1.getLogin());
+ addUserToTemplate(projectTemplate.getUuid(), user2.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user2.getLogin());
+ addUserToTemplate(projectTemplate.getUuid(), user3.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user3.getLogin());
+ addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.CODEVIEWER, projectTemplate.getName(), user1.getLogin());
+ addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN, projectTemplate.getName(), group1.getName());
+ addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN, projectTemplate.getName());
db.permissionTemplates().setDefaultTemplates(projectTemplate, null, null);
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();
- addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.ISSUE_ADMIN);
- addUserToTemplate(projectTemplate.getUuid(), user2.getUuid(), UserRole.ISSUE_ADMIN);
- addUserToTemplate(projectTemplate.getUuid(), user3.getUuid(), UserRole.ISSUE_ADMIN);
- addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.CODEVIEWER);
- addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN);
- addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN);
+ addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user1.getLogin());
+ addUserToTemplate(projectTemplate.getUuid(), user2.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user2.getLogin());
+ addUserToTemplate(projectTemplate.getUuid(), user3.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user3.getLogin());
+ addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.CODEVIEWER, projectTemplate.getName(), user1.getLogin());
+ addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN, projectTemplate.getName(), group1.getName());
+ addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN, projectTemplate.getName());
- addUserToTemplate(portfoliosTemplate.getUuid(), user1.getUuid(), UserRole.USER);
- addUserToTemplate(portfoliosTemplate.getUuid(), user2.getUuid(), UserRole.USER);
- addGroupToTemplate(portfoliosTemplate.getUuid(), group1.getUuid(), UserRole.ISSUE_ADMIN);
- addGroupToTemplate(portfoliosTemplate.getUuid(), group2.getUuid(), UserRole.ISSUE_ADMIN);
- addGroupToTemplate(portfoliosTemplate.getUuid(), group3.getUuid(), UserRole.ISSUE_ADMIN);
+ addUserToTemplate(portfoliosTemplate.getUuid(), user1.getUuid(), UserRole.USER, portfoliosTemplate.getName(), user1.getLogin());
+ addUserToTemplate(portfoliosTemplate.getUuid(), user2.getUuid(), UserRole.USER, portfoliosTemplate.getName(), user2.getLogin());
+ addGroupToTemplate(portfoliosTemplate.getUuid(), group1.getUuid(), UserRole.ISSUE_ADMIN, portfoliosTemplate.getName(), group1.getName());
+ addGroupToTemplate(portfoliosTemplate.getUuid(), group2.getUuid(), UserRole.ISSUE_ADMIN, portfoliosTemplate.getName(), group2.getName());
+ addGroupToTemplate(portfoliosTemplate.getUuid(), group3.getUuid(), UserRole.ISSUE_ADMIN, portfoliosTemplate.getName(), group3.getName());
db.permissionTemplates().setDefaultTemplates(projectTemplate, applicationsTemplate, portfoliosTemplate);
return insert;
}
- private void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission) {
- dbClient.permissionTemplateDao().insertGroupPermission(db.getSession(), templateUuid, groupUuid, permission);
+ private void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission, String templateName, String groupName) {
+ dbClient.permissionTemplateDao().insertGroupPermission(db.getSession(), templateUuid, groupUuid, permission, templateName, groupName);
db.getSession().commit();
}
- private void addUserToTemplate(String templateUuid, String userId, String permission) {
- dbClient.permissionTemplateDao().insertUserPermission(db.getSession(), templateUuid, userId, permission);
+ private void addUserToTemplate(String templateUuid, String userId, String permission, String templateName, String userLogin) {
+ dbClient.permissionTemplateDao().insertUserPermission(db.getSession(), templateUuid, userId, permission, templateName, userLogin);
db.getSession().commit();
}
- private void addPermissionTemplateWithProjectCreator(String templateUuid, String permission) {
+ private void addPermissionTemplateWithProjectCreator(String templateUuid, String permission, String templateName) {
dbClient.permissionTemplateCharacteristicDao().insert(dbSession, new PermissionTemplateCharacteristicDto()
- .setUuid(Uuids.createFast())
- .setWithProjectCreator(true)
- .setTemplateUuid(templateUuid)
- .setPermission(permission)
- .setCreatedAt(1_000_000_000L)
- .setUpdatedAt(2_000_000_000L));
+ .setUuid(Uuids.createFast())
+ .setWithProjectCreator(true)
+ .setTemplateUuid(templateUuid)
+ .setPermission(permission)
+ .setCreatedAt(1_000_000_000L)
+ .setUpdatedAt(2_000_000_000L),
+ templateName);
db.commit();
}
GroupDto userGroup = insertGroup("sonar-users", "Any new users created will automatically join this group");
PermissionTemplateDto template = addTemplate();
- addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), adminGroup.getUuid()));
- addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), userGroup.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), adminGroup.getUuid()), template.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), userGroup.getUuid()), template.getName());
// Anyone group
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
- addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null), template.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null), template.getName());
loginAsAdmin();
String response = newRequest()
PermissionTemplateDto template = addTemplate();
GroupDto group1 = db.users().insertGroup("group-1-name");
- addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()));
- addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group1.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()), template.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group1.getUuid()), template.getName());
GroupDto group2 = db.users().insertGroup("group-2-name");
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid()));
- addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid()), template.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()), template.getName());
GroupDto group3 = db.users().insertGroup("group-3-name");
// Anyone
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
- addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null), template.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null), template.getName());
PermissionTemplateDto anotherTemplate = addTemplate();
GroupDto group4 = db.users().insertGroup("group-4-name");
- addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()));
- addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group4.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()), anotherTemplate.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group4.getUuid()), anotherTemplate.getName());
loginAsAdmin();
WsGroupsResponse response = newRequest()
PermissionTemplateDto template = addTemplate();
GroupDto group1 = db.users().insertGroup("group-1-name");
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
- addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()), template.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()), template.getName());
GroupDto group2 = db.users().insertGroup("group-2-name");
- addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()), template.getName());
GroupDto group3 = db.users().insertGroup("group-3-name");
// Anyone
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null), template.getName());
PermissionTemplateDto anotherTemplate = addTemplate();
- addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()), anotherTemplate.getName());
loginAsAdmin();
WsGroupsResponse response = newRequest()
GroupDto group3 = db.users().insertGroup("group-3-name");
PermissionTemplateDto template = addTemplate();
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
- addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()));
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()), template.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()), template.getName());
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null), template.getName());
PermissionTemplateDto anotherTemplate = addTemplate();
- addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getUuid(), group1.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getUuid(), group1.getUuid()), anotherTemplate.getName());
loginAsAdmin();
WsGroupsResponse response = newRequest()
public void search_with_pagination() {
PermissionTemplateDto template = addTemplate();
GroupDto group1 = db.users().insertGroup("group-1-name");
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()), template.getName());
GroupDto group2 = db.users().insertGroup("group-2-name");
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid()), template.getName());
loginAsAdmin();
WsGroupsResponse response = newRequest()
public void search_with_text_query() {
PermissionTemplateDto template = addTemplate();
GroupDto group1 = db.users().insertGroup("group-1-name");
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()), template.getName());
GroupDto group2 = db.users().insertGroup("group-2-name");
GroupDto group3 = db.users().insertGroup("group-3");
loginAsAdmin();
public void search_with_text_query_return_anyone_group_even_when_no_permission_set() {
PermissionTemplateDto template = addTemplate();
GroupDto group = db.users().insertGroup("group");
- addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group.getUuid()));
+ addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group.getUuid()), template.getName());
loginAsAdmin();
WsGroupsResponse response = newRequest()
return db.users().insertGroup(newGroupDto().setName(name).setDescription(description));
}
- private void addGroupToTemplate(PermissionTemplateGroupDto permissionTemplateGroup) {
- db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplateGroup);
+ private void addGroupToTemplate(PermissionTemplateGroupDto permissionTemplateGroup, String templateName) {
+ db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplateGroup, templateName);
db.commit();
}
UserDto user2 = insertUser(newUserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net"));
PermissionTemplateDto template1 = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user1));
- addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user2));
- addUserToTemplate(newPermissionTemplateUser(ADMIN, template1, user2));
+ addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user1), template1.getName());
+ addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user2), template1.getName());
+ addUserToTemplate(newPermissionTemplateUser(ADMIN, template1, user2), template1.getName());
loginAsAdmin();
String result = newRequest(null, template1.getUuid()).execute().getInput();
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
PermissionTemplateDto template = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
- addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
PermissionTemplateDto anotherTemplate = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
+ addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1), anotherTemplate.getName());
Permissions.UsersWsResponse response = newRequest(null, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
PermissionTemplateDto template = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
- addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
PermissionTemplateDto anotherTemplate = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
+ addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1), anotherTemplate.getName());
Permissions.UsersWsResponse response = newRequest(null, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
PermissionTemplateDto template = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
- addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
PermissionTemplateDto anotherTemplate = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
+ addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1), anotherTemplate.getName());
loginAsAdmin();
Permissions.UsersWsResponse response = newRequest(USER, template.getUuid())
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
PermissionTemplateDto template = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
- addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
PermissionTemplateDto anotherTemplate = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
+ addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1), anotherTemplate.getName());
loginAsAdmin();
Permissions.UsersWsResponse response = newRequest(USER, null)
UserDto user3 = insertUser(newUserDto().setLogin("login-1").setName("name-1"));
PermissionTemplateDto template = addTemplate();
- addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
- addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
- addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+ addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
loginAsAdmin();
Permissions.UsersWsResponse response = newRequest(null, null)
return userDto;
}
- private void addUserToTemplate(PermissionTemplateUserDto dto) {
- db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getTemplateUuid(), dto.getUserUuid(), dto.getPermission());
+ private void addUserToTemplate(PermissionTemplateUserDto dto, String templateName) {
+ db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getTemplateUuid(), dto.getUserUuid(),
+ dto.getPermission(), templateName, dto.getUserLogin());
db.commit();
}
public void do_not_add_project_to_user_favorites_if_project_creator_is_defined_in_permission_template_and_already_100_favorites() {
UserDto user = db.users().insertUser();
when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), any(ComponentDto.class))).thenReturn(true);
- rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+ rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid(), user.getLogin()));
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
ws.newRequest()
.setGroupUuid(null)
.setRole(permission)
.setComponentUuid(component.uuid());
- dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto);
+ dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto, component);
dbTester.commit();
}
.setGroupUuid(group.getUuid())
.setRole(permission)
.setComponentUuid(component.uuid());
- dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto);
+ dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto, component);
dbTester.commit();
}
private void unsafeInsertProjectPermissionOnUser(ComponentDto component, UserDto user, String permission) {
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), component.uuid());
- dbTester.getDbClient().userPermissionDao().insert(dbTester.getSession(), dto);
+ dbTester.getDbClient().userPermissionDao().insert(dbTester.getSession(), dto, component);
dbTester.commit();
}
import org.sonar.api.config.internal.Encryption;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsActionTester;
public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+ private DbClient dbClient = db.getDbClient();
private MapSettings settings = new MapSettings();
private Encryption encryption = settings.getEncryption();
- private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(settings, userSession);
+ private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(dbClient, settings, userSession);
private WsActionTester ws = new WsActionTester(underTest);
@Test
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.setting.ws;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
+import org.sonarqube.ws.Settings.GenerateSecretKeyWsResponse;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class GenerateSecretKeyActionWithPersisterTest {
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+ @Rule
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+
+ private DbClient dbClient = db.getDbClient();
+ private MapSettings settings = new MapSettings();
+ private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(dbClient, settings, userSession, auditPersister);
+ private WsActionTester ws = new WsActionTester(underTest);
+
+ @Test
+ public void generateValidSecretKeyIsPersisted() {
+ call();
+
+ verify(auditPersister).generateSecretKey(any());
+ }
+
+ private GenerateSecretKeyWsResponse call() {
+ return ws.newRequest()
+ .setMethod("GET")
+ .executeProtobuf(GenerateSecretKeyWsResponse.class);
+ }
+
+}
import java.util.Random;
import javax.annotation.Nullable;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
public void remove_global_setting() {
logInAsSystemAdministrator();
definitions.addComponent(PropertyDefinition.builder("foo").build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
executeRequestOnGlobalSetting("foo");
assertGlobalPropertyDoesNotExist("foo");
@Test
public void remove_global_setting_even_if_not_defined() {
logInAsSystemAdministrator();
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
executeRequestOnGlobalSetting("foo");
assertGlobalPropertyDoesNotExist("foo");
public void remove_component_setting() {
logInAsProjectAdmin();
definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build());
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
+ propertyDb.insertProperties(null, null, newComponentPropertyDto(project).setKey("foo").setValue("value"));
executeRequestOnProjectSetting("foo");
assertProjectPropertyDoesNotExist("foo");
@Test
public void remove_component_setting_even_if_not_defined() {
logInAsProjectAdmin();
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
+ propertyDb.insertProperties(null, null, newComponentPropertyDto(project).setKey("foo").setValue("value"));
executeRequestOnProjectSetting("foo");
assertProjectPropertyDoesNotExist("foo");
public void remove_hidden_setting() {
logInAsSystemAdministrator();
definitions.addComponent(PropertyDefinition.builder("foo").hidden().build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
executeRequestOnGlobalSetting("foo");
assertGlobalPropertyDoesNotExist("foo");
@Test
public void ignore_project_setting_when_removing_global_setting() {
logInAsSystemAdministrator();
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("foo").setValue("value"));
executeRequestOnGlobalSetting("foo");
@Test
public void ignore_global_setting_when_removing_project_setting() {
logInAsProjectAdmin();
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("foo").setValue("value"));
executeRequestOnProjectSetting("foo");
public void ignore_user_setting_when_removing_global_setting() {
logInAsSystemAdministrator();
UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto());
- propertyDb.insertProperties(newUserPropertyDto("foo", "one", user));
+ propertyDb.insertProperties(user.getLogin(), null, newUserPropertyDto("foo", "one", user));
executeRequestOnGlobalSetting("foo");
assertUserPropertyExists("foo", user);
public void ignore_user_setting_when_removing_project_setting() {
logInAsProjectAdmin();
UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto());
- propertyDb.insertProperties(newUserPropertyDto("foo", "one", user));
+ propertyDb.insertProperties(user.getLogin(), null, newUserPropertyDto("foo", "one", user));
executeRequestOnProjectSetting("foo");
assertUserPropertyExists("foo", user);
public void remove_setting_by_deprecated_key() {
logInAsSystemAdministrator();
definitions.addComponent(PropertyDefinition.builder("foo").deprecatedKey("old").build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
executeRequestOnGlobalSetting("old");
assertGlobalPropertyDoesNotExist("foo");
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build());
- propertyDb.insertProperties(newComponentPropertyDto(branch).setKey("foo").setValue("value"));
+ propertyDb.insertProperties(null, branch.name(), newComponentPropertyDto(branch).setKey("foo").setValue("value"));
userSession.logIn().addProjectPermission(ADMIN, project);
ws.newRequest()
@Test
public void update_existing_global_setting() {
- propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my value"));
+ propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my value"), null, null);
assertGlobalSetting("my.key", "my value");
callForGlobalSetting("my.key", "my new value");
@Test
public void persist_new_project_setting() {
- propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
+ propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null);
ComponentDto project = db.components().insertPrivateProject();
logInAsProjectAdministrator(project);
@Test
public void update_existing_project_setting() {
- propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
+ propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null);
ComponentDto project = db.components().insertPrivateProject();
- propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project));
+ propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project), project.name(), null);
assertComponentSetting("my.key", "my project value", project.uuid());
logInAsProjectAdministrator(project);
.type(PropertyType.STRING)
.build()))
.build());
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto("my.key", "1,2,3,4"),
newGlobalPropertyDto("my.key.1.firstField", "oldFirstValue"),
newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue"),
.build()))
.build());
ComponentDto project = db.components().insertPrivateProject();
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto("my.key", "1"),
newGlobalPropertyDto("my.key.1.firstField", "oldFirstValue"),
- newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue"),
+ newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue"));
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto("my.key", "1", project),
newComponentPropertyDto("my.key.1.firstField", "componentFirstValue", project),
newComponentPropertyDto("my.key.1.firstField", "componentSecondValue", project));
@Test
public void user_setting_is_not_updated() {
- propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserUuid("42"));
- propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
+ propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserUuid("42"), null, "user_login");
+ propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null);
callForGlobalSetting("my.key", "my new global value");
@Test
public void delete_global_settings() {
definitions.addComponent(PropertyDefinition.builder("foo").build());
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("bar").setValue("two"));
+ propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("foo").setValue("value"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("bar").setValue("two"));
underTest.deleteGlobalSettings(dbSession, "foo", "bar");
@Test
public void delete_component_settings() {
definitions.addComponent(PropertyDefinition.builder("foo").build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("value"));
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("one"));
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("bar").setValue("two"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("value"));
+ propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("bar").setValue("two"));
underTest.deleteComponentSettings(dbSession, project, "foo", "bar");
@Test
public void does_not_fail_when_deleting_unknown_setting() {
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
underTest.deleteGlobalSettings(dbSession, "unknown");
@Test
public void does_not_delete_user_settings() {
UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto());
- propertyDb.insertProperties(newUserPropertyDto("foo", "one", user));
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(user.getLogin(), null, newUserPropertyDto("foo", "one", user));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
underTest.deleteGlobalSettings(dbSession, "foo");
PropertyFieldDefinition.build("key").name("Key").build(),
PropertyFieldDefinition.build("size").name("Size").build()))
.build());
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto().setKey("foo").setValue("1,2"),
newGlobalPropertyDto().setKey("foo.1.key").setValue("key1"),
newGlobalPropertyDto().setKey("foo.1.size").setValue("size1"),
PropertyFieldDefinition.build("key").name("Key").build(),
PropertyFieldDefinition.build("size").name("Size").build()))
.build());
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("foo").setValue("1,2"),
newComponentPropertyDto(project).setKey("foo.1.key").setValue("key1"),
newComponentPropertyDto(project).setKey("foo.1.size").setValue("size1"),
PropertyFieldDefinition.build("key").name("Key").build(),
PropertyFieldDefinition.build("size").name("Size").build()))
.build());
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("other").setValue("1,2"),
newComponentPropertyDto(project).setKey("other.1.key").setValue("key1"));
private void assertUserPropertyExists(String key, UserDto user) {
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
- .setKey(key)
- .setUserUuid(user.getUuid())
- .build(),
+ .setKey(key)
+ .setUserUuid(user.getUuid())
+ .build(),
dbSession)).isNotEmpty();
}
}
definitions.addComponent(PropertyDefinition
.builder("foo")
.build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
ValuesWsResponse result = executeRequestForGlobalProperties("foo");
definitions.addComponent(PropertyDefinition.builder("global")
.multiValues(true)
.build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("global").setValue("three,four"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("global").setValue("three,four"));
ValuesWsResponse result = executeRequestForGlobalProperties("default", "global");
assertThat(result.getSettingsList()).hasSize(2);
public void return_multi_value_with_coma() {
logIn();
definitions.addComponent(PropertyDefinition.builder("global").multiValues(true).build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("global").setValue("three,four%2Cfive"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("global").setValue("three,four%2Cfive"));
ValuesWsResponse result = executeRequestForGlobalProperties("global");
public void return_global_values() {
logIn();
definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").build());
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
// The property is overriding default value
newGlobalPropertyDto().setKey("property").setValue("one"));
logInAsProjectUser();
definitions.addComponent(
PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT).build());
- propertyDb.insertProperties(
- newGlobalPropertyDto().setKey("property").setValue("one"),
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("property").setValue("one"));
+ propertyDb.insertProperties(null, project.name(),
// The property is overriding global value
newComponentPropertyDto(project).setKey("property").setValue("two"));
PropertyDefinition.builder("global").build(),
PropertyDefinition.builder("global.default").defaultValue("default").build(),
PropertyDefinition.builder("project").onQualifiers(PROJECT).build()));
- propertyDb.insertProperties(
- newGlobalPropertyDto().setKey("global").setValue("one"),
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("global").setValue("one"));
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("project").setValue("two"));
ValuesWsResponse result = executeRequestForProjectProperties();
logInAsProjectUser();
definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT).build());
// The property is not defined on project
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("property").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("property").setValue("one"));
ValuesWsResponse result = executeRequestForProjectProperties("property");
@Test
public void return_values_even_if_no_property_definition() {
logIn();
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("globalPropertyWithoutDefinition").setValue("value"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("globalPropertyWithoutDefinition").setValue("value"));
ValuesWsResponse result = executeRequestForGlobalProperties("globalPropertyWithoutDefinition");
@Test
public void return_values_of_component_even_if_no_property_definition() {
logInAsProjectUser();
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("property").setValue("foo"));
ValuesWsResponse response = executeRequestForComponentProperties(project, "property");
.builder("foo")
.defaultValue("default")
.build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("bar").setValue(""));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("bar").setValue(""));
ValuesWsResponse result = executeRequestForGlobalProperties("unknown");
logInAsProjectUser();
ComponentDto module = componentDb.insertComponent(newModuleDto(project));
definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT, MODULE).build());
- propertyDb.insertProperties(
- newGlobalPropertyDto().setKey("property").setValue("one"),
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("property").setValue("one"));
+ propertyDb.insertProperties(null, module.name(),
// The property is overriding global value
newComponentPropertyDto(module).setKey("property").setValue("two"));
PropertyDefinition.builder("globalProperty").onQualifiers(PROJECT, MODULE).build(),
PropertyDefinition.builder("projectProperty").onQualifiers(PROJECT, MODULE).build(),
PropertyDefinition.builder("moduleProperty").onQualifiers(PROJECT, MODULE).build()));
- propertyDb.insertProperties(
- newGlobalPropertyDto().setKey("globalProperty").setValue("global"),
- newComponentPropertyDto(project).setKey("projectProperty").setValue("project"),
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("globalProperty").setValue("global"));
+ propertyDb.insertProperties(null, project.name(),
+ newComponentPropertyDto(project).setKey("projectProperty").setValue("project"));
+ propertyDb.insertProperties(null, module.name(),
newComponentPropertyDto(module).setKey("moduleProperty").setValue("module"));
ValuesWsResponse result = executeRequestForComponentProperties(module, "defaultProperty", "globalProperty", "projectProperty", "moduleProperty");
definitions.addComponents(asList(
PropertyDefinition.builder("defaultProperty").defaultValue("default").build(),
PropertyDefinition.builder("globalProperty").build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto().setKey("globalProperty").setValue("global"));
ValuesWsResponse result = executeRequestForGlobalProperties("defaultProperty", "globalProperty");
ComponentDto subModule = componentDb.insertComponent(newModuleDto(module));
definitions.addComponents(asList(
PropertyDefinition.builder("foo").defaultValue("default").onQualifiers(PROJECT, MODULE).build()));
- propertyDb.insertProperties(
- newGlobalPropertyDto().setKey("foo").setValue("global"),
- newComponentPropertyDto(project).setKey("foo").setValue("project"),
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("foo").setValue("global"));
+ propertyDb.insertProperties(null, project.name(),
+ newComponentPropertyDto(project).setKey("foo").setValue("project"));
+ propertyDb.insertProperties(null, module.name(),
newComponentPropertyDto(module).setKey("foo").setValue("module"));
assertParentValue(executeRequestForComponentProperties(subModule, "foo").getSettings(0), "module");
ComponentDto subModule = componentDb.insertComponent(newModuleDto(module));
definitions.addComponents(asList(
PropertyDefinition.builder("foo").defaultValue("default1,default2").multiValues(true).onQualifiers(PROJECT, MODULE).build()));
- propertyDb.insertProperties(
- newGlobalPropertyDto().setKey("foo").setValue("global1,global2"),
- newComponentPropertyDto(project).setKey("foo").setValue("project1,project2"),
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("foo").setValue("global1,global2"));
+ propertyDb.insertProperties(null, project.name(),
+ newComponentPropertyDto(project).setKey("foo").setValue("project1,project2"));
+ propertyDb.insertProperties(null, module.name(),
newComponentPropertyDto(module).setKey("foo").setValue("module1,module2"));
assertParentValues(executeRequestForComponentProperties(subModule, "foo").getSettings(0), "module1", "module2");
PropertyFieldDefinition.build("key").name("Key").build(),
PropertyFieldDefinition.build("size").name("Size").build()))
.build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, module.name(),
newComponentPropertyDto(module).setKey("simple").setValue("module"),
newComponentPropertyDto(module).setKey("multi").setValue("module1,module2"));
propertyDb.insertPropertySet("set", module, ImmutableMap.of("key", "keyM1", "size", "sizeM1"));
public void return_parent_value_when_no_definition() {
logInAsProjectUser();
ComponentDto module = componentDb.insertComponent(newModuleDto(project));
- propertyDb.insertProperties(
- newGlobalPropertyDto().setKey("foo").setValue("global"),
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("foo").setValue("global"));
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("foo").setValue("project"));
assertParentValue(executeRequestForComponentProperties(module, "foo").getSettings(0), "project");
.builder("foo")
.deprecatedKey("deprecated")
.build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
ValuesWsResponse result = executeRequestForGlobalProperties("deprecated");
definitions.addComponents(asList(
PropertyDefinition.builder("foo").build(),
PropertyDefinition.builder("secret.secured").build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto().setKey("foo").setValue("one"),
newGlobalPropertyDto().setKey("secret.secured").setValue("password"));
definitions.addComponents(asList(
PropertyDefinition.builder("foo").build(),
PropertyDefinition.builder("secret.secured").build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto().setKey("foo").setValue("one"),
newGlobalPropertyDto().setKey("secret.secured").setValue("password"));
PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(),
PropertyDefinition.builder("global.secret.secured").build(),
PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"));
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("foo").setValue("one"),
- newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"),
newComponentPropertyDto(project).setKey("secret.secured").setValue("password"));
ValuesWsResponse result = executeRequestForProjectProperties();
userSession
.addProjectPermission(USER, project)
.addProjectPermission(SCAN_EXECUTION, project);
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
+ propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured");
definitions.addComponents(asList(
PropertyDefinition.builder("foo").build(),
PropertyDefinition.builder("secret.secured").build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto().setKey("foo").setValue("one"),
newGlobalPropertyDto().setKey("secret.secured").setValue("password"));
PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(),
PropertyDefinition.builder("global.secret.secured").build(),
PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
+ newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"));
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("foo").setValue("one"),
- newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"),
newComponentPropertyDto(project).setKey("secret.secured").setValue("password"));
ValuesWsResponse result = executeRequestForProjectProperties();
@Test
public void return_secured_settings_even_if_not_defined_when_project_admin() {
logInAsProjectAdmin();
- propertyDb.insertProperties(newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
+ propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured");
definitions.addComponents(asList(
PropertyDefinition.builder("foo").build(),
PropertyDefinition.builder("secret.secured").build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto().setKey("foo").setValue("one"),
newGlobalPropertyDto().setKey("secret.secured").setValue("password"));
definitions.addComponents(asList(
PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(),
PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build()));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, project.name(),
newComponentPropertyDto(project).setKey("foo").setValue("one"),
newComponentPropertyDto(project).setKey("secret.secured").setValue("password"));
public void return_additional_settings_specific_for_scanner_when_no_keys() {
logInAsAdmin();
definitions.addComponent(PropertyDefinition.builder("secret.secured").build());
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto().setKey("sonar.core.id").setValue("ID"),
newGlobalPropertyDto().setKey("sonar.core.startTime").setValue("2017-01-01"));
definitions.addComponent(PropertyDefinition
.builder("foo")
.build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("fi±∞…"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("fi±∞…"));
ValuesWsResponse result = executeRequestForGlobalProperties("foo");
.builder("foo")
.deprecatedKey("deprecated")
.build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'foo' and 'deprecated' cannot be used at the same time as they refer to the same setting");
.builder("sonar.autogenerated")
.multiValues(true)
.build());
- propertyDb.insertProperties(newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3"));
+ propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3"));
definitions.addComponent(PropertyDefinition
.builder("sonar.demo")
.type(PropertyType.PROPERTY_SET)
PropertyDefinition securedDef = PropertyDefinition.builder("my.password.secured").build();
PropertyDefinition standardDef = PropertyDefinition.builder("my.property").build();
definitions.addComponents(asList(securedDef, standardDef));
- propertyDb.insertProperties(
+ propertyDb.insertProperties(null, null,
newGlobalPropertyDto().setKey(securedDef.key()).setValue("securedValue"),
newGlobalPropertyDto().setKey(standardDef.key()).setValue("standardValue"));
public void return_component_info_with_favourite() {
ComponentDto project = insertProject();
UserDto user = db.users().insertUser("obiwan");
- propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()));
+ propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()),
+ project.name(), user.getLogin());
userSession.logIn(user).addProjectPermission(UserRole.USER, project);
init();
ComponentDto project = insertProject();
ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz"));
UserDto user = db.users().insertUser("obiwan");
- propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()));
+ propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()),
+ project.name(), user.getLogin());
userSession.logIn(user).addProjectPermission(UserRole.USER, project);
init();
componentDbTester.insertSnapshot(analysis);
when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType());
UserDto user = db.users().insertUser("obiwan");
- propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()));
+ propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()),
+ project.name(), user.getLogin());
addQualityProfiles(project,
createQProfile("qp1", "Sonar Way Java", "java"),
createQProfile("qp2", "Sonar Way Xoo", "xoo"));
logInAsSystemAdministrator();
UserDto user = db.users().insertUser();
ComponentDto project = db.components().insertPrivateProject();
- db.properties().insertProperty(newUserPropertyDto(user));
- db.properties().insertProperty(newUserPropertyDto(user));
- db.properties().insertProperty(newUserPropertyDto(user).setComponentUuid(project.uuid()));
+ db.properties().insertProperty(newUserPropertyDto(user), null, user.getLogin());
+ db.properties().insertProperty(newUserPropertyDto(user), null, user.getLogin());
+ db.properties().insertProperty(newUserPropertyDto(user).setComponentUuid(project.uuid()), project.name(), user.getLogin());
deactivate(user.getLogin());
UserDto user = db.users().insertUser();
PermissionTemplateDto template = db.permissionTemplates().insertTemplate();
PermissionTemplateDto anotherTemplate = db.permissionTemplates().insertTemplate();
- db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), USER);
- db.permissionTemplates().addUserToTemplate(anotherTemplate.getUuid(), user.getUuid(), CODEVIEWER);
+ db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), USER, template.getName(), user.getLogin());
+ db.permissionTemplates().addUserToTemplate(anotherTemplate.getUuid(), user.getUuid(), CODEVIEWER, anotherTemplate.getName(), user.getLogin());
deactivate(user.getLogin());
UserDto user = db.users().insertUser();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto anotherProject = db.components().insertPrivateProject();
- db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setComponentUuid(project.uuid()));
- db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setComponentUuid(anotherProject.uuid()));
- db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setComponentUuid(anotherProject.uuid()));
+ db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin())
+ .setComponentUuid(project.uuid()), project.name(), user.getLogin());
+ db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin())
+ .setComponentUuid(anotherProject.uuid()), anotherProject.name(), user.getLogin());
+ db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin())
+ .setComponentUuid(anotherProject.uuid()), anotherProject.name(), user.getLogin());
deactivate(user.getLogin());
@Test
public void administrators_can_be_deactivated_if_there_are_still_other_administrators() {
UserDto admin = createAdminUser();
- ;
+
UserDto anotherAdmin = createAdminUser();
logInAsSystemAdministrator();
GroupDto group = db.users().insertGroup();
PermissionTemplateDto template = db.getDbClient().permissionTemplateDao().insert(db.getSession(),
PermissionTemplateTesting.newPermissionTemplateDto());
- db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), group.getUuid(), "perm");
+ db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), group.getUuid(), "perm",
+ template.getName(), group.getName());
db.commit();
loginAsAdmin();
assertThat(db.countRowsOfTable("perm_templates_groups")).isEqualTo(1);
@Test
public void list_webhooks_and_their_latest_delivery() {
- WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"));
+ WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null);
webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
- WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"));
+ WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null);
webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
@Test
public void list_webhooks_when_no_delivery() {
- WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"));
- WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"));
+ WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null);
+ WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null);
userSession.logIn().addPermission(ADMINISTER);
public void obfuscate_credentials_in_webhook_URLs() {
String url = "http://foo:barouf@toto/bop";
String expectedUrl = "http://***:******@toto/bop";
- WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa", t -> t.setUrl(url)));
+ WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa", t -> t.setUrl(url)), null);
webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
- webhookDbTester.insert(newGlobalWebhook("bbb", t -> t.setUrl(url)));
+ webhookDbTester.insert(newGlobalWebhook("bbb", t -> t.setUrl(url)), null);
userSession.logIn().addPermission(ADMINISTER);