implemented transfer of project ownership to other user
This commit is contained in:
@@ -5,6 +5,7 @@ import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Paths.LIST;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Permission.EDIT;
|
||||
import static de.srsoftware.umbrella.core.model.Permission.OWNER;
|
||||
import static de.srsoftware.umbrella.core.model.Status.OPEN;
|
||||
import static de.srsoftware.umbrella.project.Constants.CONFIG_DATABASE;
|
||||
@@ -176,6 +177,11 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
||||
}
|
||||
if (!(json.get(key) instanceof Number number)) throw invalidFieldException(PERMISSION,"int");
|
||||
var permission = Permission.of(number.intValue());
|
||||
if (permission == OWNER) { // if a new person is about to become the project owner
|
||||
for (var member : members.values()){ // alter the previous owners to editors
|
||||
if (member.permission() == OWNER) members.put(member.user().id(),new Member(member.user(),EDIT));
|
||||
}
|
||||
}
|
||||
members.put(userId,new Member(users.loadUser(userId),permission));
|
||||
project.dirtyFields().add(MEMBERS);
|
||||
}
|
||||
@@ -186,6 +192,7 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
||||
if (!project.hasMember(user)) throw forbidden("You are not a member of {0}",project.name());
|
||||
var json = json(ex);
|
||||
if (json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject memberJson) patchMembers(project,memberJson);
|
||||
|
||||
projects.save(project.patch(json));
|
||||
return sendContent(ex,project.toMap());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user