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);
}
Aggregations