Search in sources :

Example 1 with ResourceAccessLevel

use of com.walmartlabs.concord.server.org.ResourceAccessLevel in project concord by walmartlabs.

the class ProjectManager method update.

private void update(DSLContext tx, UUID projectId, ProjectEntry entry) {
    ProjectEntry e = projectDao.get(projectId);
    if (e == null) {
        throw new ValidationErrorsException("Project not found: " + projectId);
    }
    UserEntry owner = getOwner(entry.getOwner(), null);
    policyManager.checkEntity(e.getOrgId(), projectId, EntityType.PROJECT, EntityAction.UPDATE, owner, PolicyUtils.projectToMap(e.getOrgId(), e.getOrgName(), entry));
    UUID currentOwnerId = e.getOwner() != null ? e.getOwner().id() : null;
    UUID updatedOwnerId = owner != null ? owner.getId() : null;
    ResourceAccessLevel level = ResourceAccessLevel.WRITER;
    if (updatedOwnerId != null && !updatedOwnerId.equals(currentOwnerId)) {
        level = ResourceAccessLevel.OWNER;
    }
    ProjectEntry prevEntry = accessManager.assertAccess(projectId, level, true);
    UUID orgId = prevEntry.getOrgId();
    OrganizationEntry organizationEntry = null;
    if (entry.getOrgId() != null) {
        organizationEntry = orgManager.assertAccess(entry.getOrgId(), true);
    } else if (entry.getOrgName() != null) {
        organizationEntry = orgManager.assertAccess(entry.getOrgName(), true);
    }
    UUID orgIdUpdate = organizationEntry != null ? organizationEntry.getId() : orgId;
    RawPayloadMode rawPayloadMode = entry.getRawPayloadMode();
    if (rawPayloadMode == null && entry.getAcceptsRawPayload() != null && entry.getAcceptsRawPayload()) {
        rawPayloadMode = RawPayloadMode.ORG_MEMBERS;
    }
    if (!orgIdUpdate.equals(orgId)) {
        secretDao.updateProjectScopeByProjectId(tx, orgId, projectId, null);
        repositoryDao.clearSecretMappingByProjectId(tx, projectId);
    }
    projectDao.update(tx, orgIdUpdate, projectId, entry.getVisibility(), entry.getName(), entry.getDescription(), entry.getCfg(), rawPayloadMode, updatedOwnerId, entry.getMeta(), entry.getOutVariablesMode());
    Map<String, RepositoryEntry> repos = entry.getRepositories();
    if (repos != null) {
        repositoryDao.deleteAll(tx, projectId);
        repos.forEach((k, v) -> projectRepositoryManager.insert(tx, orgId, prevEntry.getOrgName(), projectId, prevEntry.getName(), v, false));
    }
    ProjectEntry newEntry = projectDao.get(tx, projectId);
    Map<String, Object> changes = DiffUtils.compare(prevEntry, newEntry);
    addAuditLog(AuditAction.UPDATE, prevEntry.getOrgId(), prevEntry.getOrgName(), prevEntry.getId(), prevEntry.getName(), changes);
}
Also used : ResourceAccessLevel(com.walmartlabs.concord.server.org.ResourceAccessLevel) UserEntry(com.walmartlabs.concord.server.user.UserEntry) AuditObject(com.walmartlabs.concord.server.audit.AuditObject) UUID(java.util.UUID) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) RawPayloadMode(com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)

Aggregations

AuditObject (com.walmartlabs.concord.server.audit.AuditObject)1 RawPayloadMode (com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)1 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)1 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)1 UserEntry (com.walmartlabs.concord.server.user.UserEntry)1 UUID (java.util.UUID)1 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)1