implemented removal of project members
This commit is contained in:
@@ -7,9 +7,11 @@ import de.srsoftware.umbrella.core.model.Project;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ProjectDb {
|
||||
void dropMember(long projectId, long userId);
|
||||
Map<Long, Permission> getMembers(Project project);
|
||||
Project load(long projectId) throws UmbrellaException;
|
||||
Map<Long, Project> ofCompany(long companyId, boolean includeClosed) throws UmbrellaException;
|
||||
Map<Long, Project> ofUser(long userId, boolean includeClosed) throws UmbrellaException;
|
||||
|
||||
Project save(Project prj) throws UmbrellaException;
|
||||
}
|
||||
|
||||
@@ -194,6 +194,7 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
||||
var project = loadMembers(projects.load(projectId));
|
||||
if (!project.hasMember(user)) throw forbidden("You are not a member of {0}",project.name());
|
||||
var json = json(ex);
|
||||
if (json.has(DROP_MEMBER) && json.get(DROP_MEMBER) instanceof Number id) dropMember(project,id.longValue());
|
||||
if (json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject memberJson) patchMembers(project,memberJson);
|
||||
if (json.has(NEW_MEMBER) && json.get(NEW_MEMBER) instanceof Number num) addMember(project,num.longValue());
|
||||
|
||||
@@ -201,6 +202,11 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
||||
return sendContent(ex,project.toMap());
|
||||
}
|
||||
|
||||
private void dropMember(Project project, long userId) {
|
||||
if (project.members().get(userId).permission() == OWNER) throw forbidden("You may not remove the owner of the project");
|
||||
projects.dropMember(project.id(),userId);
|
||||
project.members().remove(userId);
|
||||
}
|
||||
|
||||
|
||||
private boolean postProject(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
|
||||
|
||||
@@ -115,6 +115,18 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropMember(long projectId, long userId) {
|
||||
try {
|
||||
delete().from(TABLE_PROJECT_USERS)
|
||||
.where(PROJECT_ID,equal(projectId))
|
||||
.where(USER_ID,equal(userId))
|
||||
.execute(db);
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException("Failed to delete member (userId = {0} from project {1}",userId,projectId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Permission> getMembers(Project project) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user