Commit ce3eb353 by Tuomas Riihimäki

Rolemanagement

1 parent 5b6f2c04
...@@ -71,4 +71,5 @@ public interface EventBeanLocal { ...@@ -71,4 +71,5 @@ public interface EventBeanLocal {
List<LanEvent> findFutureEvents(); List<LanEvent> findFutureEvents();
List<LanEvent> findAllEventsForOrganizer(EventOrganiser organiser); List<LanEvent> findAllEventsForOrganizer(EventOrganiser organiser);
} }
...@@ -30,6 +30,7 @@ import javax.ejb.Local; ...@@ -30,6 +30,7 @@ import javax.ejb.Local;
import fi.codecrew.moya.enums.apps.IAppPermission; import fi.codecrew.moya.enums.apps.IAppPermission;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User;
/** /**
* *
...@@ -57,6 +58,7 @@ public interface RoleBeanLocal { ...@@ -57,6 +58,7 @@ public interface RoleBeanLocal {
public List<Role> getRoles(EventUser selectedUser); public List<Role> getRoles(EventUser selectedUser);
Role addRole(EventUser eventuser, Role role); Role addRole(EventUser eventuser, Role role);
Role removeRole(EventUser user, Role role);
List<Role> listUserSelectableRoles(); List<Role> listUserSelectableRoles();
......
...@@ -35,6 +35,8 @@ import javax.ejb.LocalBean; ...@@ -35,6 +35,8 @@ import javax.ejb.LocalBean;
import javax.ejb.SessionContext; import javax.ejb.SessionContext;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import fi.codecrew.moya.model.User;
import org.primefaces.model.DualListModel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -195,11 +197,6 @@ public class RoleBean implements RoleBeanLocal { ...@@ -195,11 +197,6 @@ public class RoleBean implements RoleBeanLocal {
return role; return role;
} }
private void checkRoleLdap()
{
}
@Override @Override
@RolesAllowed(UserPermission.S_WRITE_ROLES) @RolesAllowed(UserPermission.S_WRITE_ROLES)
public Role addRole(EventUser eventuser, Role role) public Role addRole(EventUser eventuser, Role role)
...@@ -219,6 +216,22 @@ public class RoleBean implements RoleBeanLocal { ...@@ -219,6 +216,22 @@ public class RoleBean implements RoleBeanLocal {
@Override @Override
@RolesAllowed(UserPermission.S_WRITE_ROLES) @RolesAllowed(UserPermission.S_WRITE_ROLES)
public Role removeRole(EventUser eventuser, Role role) {
eventuser = eventuserfacade.reload(eventuser);
role = roleFacade.reload(role);
if (eventuser.getRoles().contains(role)) {
eventuser.getRoles().remove(role);
}
if (role.getUsers().contains(eventuser)) {
role.getUsers().remove(eventuser);
}
cardTemplateBean.checkPrintedCard(eventuser);
return role;
}
@Override
@RolesAllowed(UserPermission.S_WRITE_ROLES)
public void saveRoles(EventUser usr, List<Role> usersRoles) { public void saveRoles(EventUser usr, List<Role> usersRoles) {
List<Role> allRoles = roleFacade.findAll(); List<Role> allRoles = roleFacade.findAll();
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.2"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd"> xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="MoyaDb"> <persistence-unit name="MoyaDb">
<jta-data-source>jdbc/moyaDb</jta-data-source> <jta-data-source>jdbc/moyaDb</jta-data-source>
<properties> <properties>
<property name="eclipselink.cache.size.default" value="16384" /> <property name="eclipselink.cache.size.default" value="16384"/>
<property name="eclipselink.logging.logger" value="ServerLogger" /> <property name="eclipselink.logging.logger" value="ServerLogger"/>
<property name="eclipselink.jdbc.uppercase-columns" value="false" /> <property name="eclipselink.jdbc.uppercase-columns" value="false"/>
<property name="eclipselink.target-database" value="PostgreSQL" /> <property name="eclipselink.target-database" value="PostgreSQL"/>
<property name="eclipselink.create-ddl-jdbc-file-name" value="moyaCreateDDL.sql" /> <property name="eclipselink.create-ddl-jdbc-file-name" value="moyaCreateDDL.sql"/>
<property name="eclipselink.drop-ddl-jdbc-file-name" value="moyaDropDDL.sql" /> <property name="eclipselink.drop-ddl-jdbc-file-name" value="moyaDropDDL.sql"/>
<property name="eclipselink.target-server" value="Glassfish" /> <property name="eclipselink.target-server" value="Glassfish"/>
<property name="eclipselink.session.customizer" <property name="eclipselink.session.customizer"
value="fi.codecrew.moya.database.eclipselink.MoyaSessionCustomizer" /> value="fi.codecrew.moya.database.eclipselink.MoyaSessionCustomizer"/>
<property name="eclipselink.ddl-generation" value="create-tables"/> <property name="eclipselink.ddl-generation" value="create-tables"/>
<!--property name="eclipselink.ddl-generation" value="create-tables"/--> <!--property name="eclipselink.ddl-generation" value="create-tables"/-->
<property name="eclipselink.ddl-generation.output-mode" value="sql-script"/> <property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>
</properties> </properties>
</persistence-unit> </persistence-unit>
</persistence> </persistence>
package fi.codecrew.moya.permissions;
/**
* This is a list of distinct "applications" available in moya.
* All applications can be enabled or disabled in a moya instance.
* All applications have three possible permission types:
* - GUEST - Roles assigned to a guest of the event
* - ORGANIZER - Permissions assigned to a generic organizer, who will manage the event-time activities of the application
* - ADMIN - Administrator, who has all permissions for the activities on the application
* <p>
* All more distinct permissions assigned to an application should be managed by event or application specific properties.
*/
public enum MoyaApplication {
/**
* - Guest have the permission to manage themselves
* - organizers have the permission to view all users
* - Admin has the rights to modify all users basic information
* <p>
* Note that nobody should have the right to reset a password or email
* because of security concerns. (except superadmin, maybe?)
*/
User,
/**
* - User: View and reserve places from the map to themselves
* - Org: View all information about places, and assign people to places
* - Admin: Create and modify maps and layouts
*/
Map,
/**
* - User: View and buy items in shop
* - Org: Sell products to others.
* - Admin: Create and modify products
*/
Shop,
/**
* - User: No permissions
* - Org: View and give out vip list enries
* - Admin: Add vips
*/
Viplist,
/**
* - Guest: Vote and submit entries to compos
* - Org: View compos and assist users in entry submissions
* - Admin: Create and manage categories, view results
*/
Compo,
/**
* - User: View and enroll to lectures
* - Org: Enroll others to lectures and view all registrants
* - Admin: Create and modify lectures, remove enrollments
*/
Lecture,
// Licence, This might not be relevant
/**
* - Guest: Answer the polls
* - Organizer: No special permissions
* - Admin: Create and manage polls, View results
*/
Poll,
/**
* Most events have some content added on the pages
* - User: View content
* - Org: No special permissions
* - Admin: Manage and create content
*/
Content,;
public static final String USER = "User";
public static final String ORGANIZER = "Organizer";
public static final String ADMIN = "Admin";
}
...@@ -61,8 +61,26 @@ ...@@ -61,8 +61,26 @@
</p> </p>
<p:fieldset id="rolecopy" legend="#{i18n['role.rolecopy']}" collapsed="true" toggleable="true">
<h:form>
<p:selectOneMenu value="#{organizerEventSelector.selectedEvent}" converter="#{lanEventConverter}">
<f:selectItem itemLabel="----" />
<f:selectItems value="#{organizerEventSelector.organizerEvents}" var="event" itemLabel="#{event.name}"/>
</p:selectOneMenu>
<p:selectOneMenu value="#{organizerEventSelector.selectedEvent}" converter="#{lanEventConverter}">
<f:selectItem itemLabel="----" />
<f:selectItems value="#{organizerEventSelector.selectedEvent.roles}" var="role" itemLabel="#{role.name}"/>
<p:ajax event="change" update="rolecopy" />
</p:selectOneMenu>
<p:pickList value="#{roleView.transferList}" converter="#{userConverter}" var="user" itemLabel="#{user.wholeName} / #{user.nick}" >
<p:ajax event="transfer" listener="#{roleView.transferRole}" update="@form userfield" />
</p:pickList>
</h:form>
</p:fieldset>
<p:fieldset id="userfield" legend="#{i18n['roleView.members']}" toggleable="true" collapsed="true"> <p:fieldset id="userfield" legend="#{i18n['roleView.members']}" toggleable="true" collapsed="true">
<h:form id="addmember"> <h:form id="addmember">
......
package fi.codecrew.moya.web.cdiview.organisation;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.model.LanEvent;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
@Named
@ConversationScoped
public class OrganizerEventSelector implements Serializable {
private List<LanEvent> orgnizersEvents;
private LanEvent selectedEvent;
@EJB
private EventBeanLocal eventbean;
@EJB
private PermissionBeanLocal permbean;
public List<LanEvent> getOrganizerEvents() {
if (orgnizersEvents == null) {
orgnizersEvents = eventbean.findAllEventsForOrganizer(permbean.getCurrentUser().getEvent().getOrganiser());
}
return orgnizersEvents;
}
public List<LanEvent> getOrgnizersEvents() {
return orgnizersEvents;
}
public void setOrgnizersEvents(List<LanEvent> orgnizersEvents) {
this.orgnizersEvents = orgnizersEvents;
}
public LanEvent getSelectedEvent() {
return selectedEvent;
}
public void setSelectedEvent(LanEvent selectedEvent) {
this.selectedEvent = selectedEvent;
}
}
/* /*
* Copyright Codecrew Ry * Copyright Codecrew Ry
* *
* All rights reserved. * All rights reserved.
* *
* This license applies to any software containing a notice placed by the * This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software. * copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software. * This license covers modification, distribution and use of the Software.
* *
* Any distribution and use in source and binary forms, with or without * Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the * modification is not permitted without explicit written permission from the
* copyright owner. * copyright owner.
* *
* A non-exclusive royalty-free right is granted to the copyright owner of the * A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in * Software to use, modify and distribute all modifications to the Software in
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.web.cdiview.user; package fi.codecrew.moya.web.cdiview.user;
...@@ -26,6 +26,8 @@ import javax.enterprise.context.ConversationScoped; ...@@ -26,6 +26,8 @@ import javax.enterprise.context.ConversationScoped;
import javax.inject.Named; import javax.inject.Named;
import fi.codecrew.moya.model.*; import fi.codecrew.moya.model.*;
import org.primefaces.event.TransferEvent;
import org.primefaces.model.DualListModel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -44,10 +46,12 @@ import fi.codecrew.moya.web.helpers.BortalApplicationWrapper; ...@@ -44,10 +46,12 @@ import fi.codecrew.moya.web.helpers.BortalApplicationWrapper;
public class RoleView extends GenericCDIView { public class RoleView extends GenericCDIView {
/** /**
* *
*/ */
private static final long serialVersionUID = -5165373936500592099L; private static final long serialVersionUID = -5165373936500592099L;
private Role sourceRole;
private Role role; private Role role;
private Integer roleid; private Integer roleid;
...@@ -79,14 +83,12 @@ public class RoleView extends GenericCDIView { ...@@ -79,14 +83,12 @@ public class RoleView extends GenericCDIView {
} }
} }
public void addUser() public void addUser() {
{
role = rolebean.addRole(addableUser, role); role = rolebean.addRole(addableUser, role);
addableUser = null; addableUser = null;
} }
public List<EventUser> searchUser(String user) public List<EventUser> searchUser(String user) {
{
// By default this returns only 20 first results. // By default this returns only 20 first results.
UserSearchQuery usq = new UserSearchQuery(); UserSearchQuery usq = new UserSearchQuery();
usq.setSearch(user); usq.setSearch(user);
...@@ -160,6 +162,32 @@ public class RoleView extends GenericCDIView { ...@@ -160,6 +162,32 @@ public class RoleView extends GenericCDIView {
return null; return null;
} }
public DualListModel<User> getTransferList(){
DualListModel<User> ret = new DualListModel<>();
ret.setSource(sourceRole.getUsers().stream().map(u -> u.getUser()).collect(Collectors.toList()));
ret.setTarget(role.getUsers().stream().map(u -> u.getUser()).sorted(Comparator.comparing(User::getWholeName)).collect(Collectors.toList()));
return ret;
}
public void transferRole(TransferEvent event) {
StringBuilder builder = new StringBuilder();
for (Object item : event.getItems()) {
User transferredUser = (User) item;
logger.info("Transferring user user", transferredUser);
if (transferredUser == null) {
continue;
}
if (event.isAdd()) {
role = rolebean.addRole( userbean.getEventUser(transferredUser, true), role);
} else if (event.isRemove()) {
role = rolebean.removeRole(userbean.getEventUser(transferredUser, false), role);
}
}
}
public String savePermissions() { public String savePermissions() {
if (isCanWriteRoles()) { if (isCanWriteRoles()) {
ArrayList<IAppPermission> newPerms = new ArrayList<IAppPermission>(); ArrayList<IAppPermission> newPerms = new ArrayList<IAppPermission>();
...@@ -222,4 +250,11 @@ public class RoleView extends GenericCDIView { ...@@ -222,4 +250,11 @@ public class RoleView extends GenericCDIView {
this.addableUser = addableUser; this.addableUser = addableUser;
} }
public Role getSourceRole() {
return sourceRole;
}
public void setSourceRole(Role sourceRole) {
this.sourceRole = sourceRole;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!