implemented removal of project members
This commit is contained in:
@@ -25,6 +25,7 @@ public class Constants {
|
|||||||
public static final String DEFAULT_THEME = "winter";
|
public static final String DEFAULT_THEME = "winter";
|
||||||
public static final String DESCRIPTION = "description";
|
public static final String DESCRIPTION = "description";
|
||||||
public static final String DOMAIN = "domain";
|
public static final String DOMAIN = "domain";
|
||||||
|
public static final String DROP_MEMBER = "drop_member";
|
||||||
public static final String DUE_DATE = "due_date";
|
public static final String DUE_DATE = "due_date";
|
||||||
public static final String DURATION = "duration";
|
public static final String DURATION = "duration";
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
let {
|
let {
|
||||||
members,
|
members,
|
||||||
updatePermission = (uid,perm) => console.log(`no handler for updatePermission(${uid}, ${perm})`),
|
updatePermission = (uid,perm) => console.log(`no handler for updatePermission(${uid}, ${perm})`),
|
||||||
|
dropMember = (member) => console.log(`no handler for dropMember(${member})`),
|
||||||
addMember = (entry) => console.log(`no handler for addMember(${entry})`)
|
addMember = (entry) => console.log(`no handler for addMember(${entry})`)
|
||||||
} = $props();
|
} = $props();
|
||||||
let error = $state(null);
|
let error = $state(null);
|
||||||
@@ -59,6 +60,9 @@
|
|||||||
<td>{member.user.name}</td>
|
<td>{member.user.name}</td>
|
||||||
<td>
|
<td>
|
||||||
<PermissionSelector {permissions} selected={member.permission.code} onchange={(perm) => updatePermission(member.user.id,perm)} />
|
<PermissionSelector {permissions} selected={member.permission.code} onchange={(perm) => updatePermission(member.user.id,perm)} />
|
||||||
|
{#if member.permission.name != 'OWNER'}
|
||||||
|
<button onclick={() => dropMember(member)}>x</button>
|
||||||
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -20,6 +20,10 @@
|
|||||||
if (ids) update({new_member:+ids.pop()});
|
if (ids) update({new_member:+ids.pop()});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function dropMember(member){
|
||||||
|
update({drop_member:member.user.id});
|
||||||
|
}
|
||||||
|
|
||||||
async function loadProject(){
|
async function loadProject(){
|
||||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/project/${id}`;
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/project/${id}`;
|
||||||
const resp = await fetch(url,{credentials:'include'});
|
const resp = await fetch(url,{credentials:'include'});
|
||||||
@@ -131,6 +135,6 @@
|
|||||||
{#if showSettings}
|
{#if showSettings}
|
||||||
<fieldset class="project settings">
|
<fieldset class="project settings">
|
||||||
<legend>{t('settings')}</legend>
|
<legend>{t('settings')}</legend>
|
||||||
<MemberEditor members={project.members} {updatePermission} {addMember} />
|
<MemberEditor members={project.members} {updatePermission} {addMember} {dropMember} />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -7,9 +7,11 @@ import de.srsoftware.umbrella.core.model.Project;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface ProjectDb {
|
public interface ProjectDb {
|
||||||
|
void dropMember(long projectId, long userId);
|
||||||
Map<Long, Permission> getMembers(Project project);
|
Map<Long, Permission> getMembers(Project project);
|
||||||
Project load(long projectId) throws UmbrellaException;
|
Project load(long projectId) throws UmbrellaException;
|
||||||
Map<Long, Project> ofCompany(long companyId, boolean includeClosed) throws UmbrellaException;
|
Map<Long, Project> ofCompany(long companyId, boolean includeClosed) throws UmbrellaException;
|
||||||
Map<Long, Project> ofUser(long userId, boolean includeClosed) throws UmbrellaException;
|
Map<Long, Project> ofUser(long userId, boolean includeClosed) throws UmbrellaException;
|
||||||
|
|
||||||
Project save(Project prj) 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));
|
var project = loadMembers(projects.load(projectId));
|
||||||
if (!project.hasMember(user)) throw forbidden("You are not a member of {0}",project.name());
|
if (!project.hasMember(user)) throw forbidden("You are not a member of {0}",project.name());
|
||||||
var json = json(ex);
|
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(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());
|
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());
|
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 {
|
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
|
@Override
|
||||||
public Map<Long, Permission> getMembers(Project project) {
|
public Map<Long, Permission> getMembers(Project project) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user