Commit d535b6fb by Tuomas Riihimäki

Add user management to rolepage. Add ldap-parameter to role entity

1 parent 219a3554
...@@ -34,6 +34,7 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -34,6 +34,7 @@ public class BootstrapBean implements BootstrapBeanLocal {
dbUpdates.add(new String[] { "DELETE FROM application_permissions WHERE application = 'MAP' and permission = 'RELEASE_PLACE'" }); dbUpdates.add(new String[] { "DELETE FROM application_permissions WHERE application = 'MAP' and permission = 'RELEASE_PLACE'" });
dbUpdates.add(new String[] { "ALTER TABLE site_page_content ADD COLUMN locale varchar(10)" }); dbUpdates.add(new String[] { "ALTER TABLE site_page_content ADD COLUMN locale varchar(10)" });
dbUpdates.add(new String[] { "ALTER TABLE products ALTER COLUMN vat TYPE NUMERIC(4,3)" }); dbUpdates.add(new String[] { "ALTER TABLE products ALTER COLUMN vat TYPE NUMERIC(4,3)" });
dbUpdates.add(new String[] { "ALTER TABLE roles ADD ldap_role boolean not null default false" });
} }
@EJB @EJB
......
...@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory; ...@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.enums.apps.IAppPermission; import fi.codecrew.moya.enums.apps.IAppPermission;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.RoleFacade; import fi.codecrew.moya.facade.RoleFacade;
import fi.codecrew.moya.facade.UserFacade; import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.ApplicationPermission; import fi.codecrew.moya.model.ApplicationPermission;
...@@ -51,6 +52,9 @@ public class RoleBean implements RoleBeanLocal { ...@@ -51,6 +52,9 @@ public class RoleBean implements RoleBeanLocal {
@EJB @EJB
private UserFacade userFacade; private UserFacade userFacade;
@EJB
private EventUserFacade eventuserfacade;
// VIEW_ALL pitää olla että voidaan hakea roolien perusteella. // VIEW_ALL pitää olla että voidaan hakea roolien perusteella.
@Override @Override
@RolesAllowed({ UserPermission.S_READ_ROLES, UserPermission.S_VIEW_ALL }) @RolesAllowed({ UserPermission.S_READ_ROLES, UserPermission.S_VIEW_ALL })
...@@ -163,6 +167,22 @@ public class RoleBean implements RoleBeanLocal { ...@@ -163,6 +167,22 @@ public class RoleBean implements RoleBeanLocal {
@Override @Override
@RolesAllowed(UserPermission.S_WRITE_ROLES) @RolesAllowed(UserPermission.S_WRITE_ROLES)
public Role addRole(EventUser eventuser, Role role)
{
eventuser = eventuserfacade.reload(eventuser);
role = roleFacade.reload(role);
if (!eventuser.getRoles().contains(role)) {
eventuser.getRoles().add(role);
}
if (!role.getUsers().contains(eventuser)) {
role.getUsers().add(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();
......
...@@ -408,12 +408,6 @@ public class UserBean implements UserBeanLocal { ...@@ -408,12 +408,6 @@ public class UserBean implements UserBeanLocal {
// return userFacade.find(id); // return userFacade.find(id);
// } // }
@Override
@RolesAllowed(UserPermission.S_VIEW_ALL)
public SearchResult<User> getUsers(SearchQuery search) {
return userFacade.searchAllUsers(search);
}
// @Override // @Override
// public long getUsersCount(String search) { // public long getUsersCount(String search) {
// return userFacade.searchUserCount(search); // return userFacade.searchUserCount(search);
...@@ -643,17 +637,23 @@ public class UserBean implements UserBeanLocal { ...@@ -643,17 +637,23 @@ public class UserBean implements UserBeanLocal {
} }
@Override @Override
public SearchResult<User> getEventUsers(SearchQuery search) { @RolesAllowed(UserPermission.S_VIEW_ALL)
if (search.getSearch() == null || search.getSearch().isEmpty()) public SearchResult<User> getUsers(SearchQuery search) {
{ return userFacade.searchAllUsers(search);
throw new RuntimeException("You should be using getThisEventsUsers if not searching globally...");
// return userFacade.searchEventUsers(search);
} else {
return userFacade.searchAllUsers(search);
}
} }
// @Override
// public SearchResult<User> getEventUsers(SearchQuery search) {
// if (search.getSearch() == null || search.getSearch().isEmpty())
// {
// throw new RuntimeException("You should be using getThisEventsUsers if not searching globally...");
// // return userFacade.searchEventUsers(search);
// } else {
// return userFacade.searchAllUsers(search);
// }
//
// }
//
@Override @Override
public SearchResult<EventUser> getThisEventsUsers(UserSearchQuery searchQuery) { public SearchResult<EventUser> getThisEventsUsers(UserSearchQuery searchQuery) {
SearchResult<EventUser> returnUsers = eventUserFacade.searchEventUsers(searchQuery); SearchResult<EventUser> returnUsers = eventUserFacade.searchEventUsers(searchQuery);
...@@ -729,4 +729,9 @@ public class UserBean implements UserBeanLocal { ...@@ -729,4 +729,9 @@ public class UserBean implements UserBeanLocal {
return false; return false;
} }
@Override
public User getUser(Integer id) {
return userFacade.find(id);
}
} }
\ No newline at end of file
...@@ -36,4 +36,6 @@ public interface RoleBeanLocal { ...@@ -36,4 +36,6 @@ public interface RoleBeanLocal {
public List<Role> getRoles(EventUser selectedUser); public List<Role> getRoles(EventUser selectedUser);
Role addRole(EventUser eventuser, Role role);
} }
...@@ -26,7 +26,7 @@ public interface UserBeanLocal { ...@@ -26,7 +26,7 @@ public interface UserBeanLocal {
SearchResult<User> getUsers(SearchQuery search); SearchResult<User> getUsers(SearchQuery search);
SearchResult<User> getEventUsers(SearchQuery search); //SearchResult<User> getEventUsers(SearchQuery search);
EventUser mergeChanges(EventUser user); EventUser mergeChanges(EventUser user);
...@@ -40,6 +40,8 @@ public interface UserBeanLocal { ...@@ -40,6 +40,8 @@ public interface UserBeanLocal {
boolean resetPassword(User user, String password, String hash); boolean resetPassword(User user, String password, String hash);
public User getUser(Integer id);
/** /**
* Search EventUser entity by User entity ID * Search EventUser entity by User entity ID
* *
......
...@@ -107,7 +107,7 @@ public class EventUser extends GenericEntity { ...@@ -107,7 +107,7 @@ public class EventUser extends GenericEntity {
@OneToMany(mappedBy = "eventUser") @OneToMany(mappedBy = "eventUser")
private List<GameID> gameIDs; private List<GameID> gameIDs;
public List<GameID> getGameIDs() { public List<GameID> getGameIDs() {
return gameIDs; return gameIDs;
} }
...@@ -115,7 +115,7 @@ public class EventUser extends GenericEntity { ...@@ -115,7 +115,7 @@ public class EventUser extends GenericEntity {
public void setGameIDs(List<GameID> gameIDs) { public void setGameIDs(List<GameID> gameIDs) {
this.gameIDs = gameIDs; this.gameIDs = gameIDs;
} }
public EventUser getCreator() { public EventUser getCreator() {
return creator; return creator;
} }
...@@ -449,11 +449,9 @@ public class EventUser extends GenericEntity { ...@@ -449,11 +449,9 @@ public class EventUser extends GenericEntity {
return ret; return ret;
} }
public String getShortUserDescriptor() { public String getShortUserDescriptor() {
StringBuilder sb = new StringBuilder(); return user.getShortUserDescriptor();
sb.append(getNick()).append(" // ").append(getWholeName()).append(" // ").append(getEmail());
return sb.toString();
} }
} }
...@@ -8,6 +8,11 @@ public enum LanEventPrivatePropertyKey { ...@@ -8,6 +8,11 @@ public enum LanEventPrivatePropertyKey {
CHECKOUT_FI_MERCHANT_PASSWORD(Type.TEXT, null), CHECKOUT_FI_MERCHANT_PASSWORD(Type.TEXT, null),
CHECKOUT_FI_MERCHANT_ID(Type.TEXT, null), CHECKOUT_FI_MERCHANT_ID(Type.TEXT, null),
CHECKOUT_FI_KEY_EXPIRE(Type.DATE, null), CHECKOUT_FI_KEY_EXPIRE(Type.DATE, null),
LDAP_URL(Type.TEXT, null),
LDAP_BIND_DN(Type.TEXT, null),
LDAP_BIND_PW(Type.TEXT, null),
LDAP_USER_OU(Type.TEXT, null),
LDAP_GROUP_OU(Type.TEXT, null),
; ;
private enum Type { private enum Type {
......
...@@ -83,6 +83,9 @@ public class Role extends GenericEntity { ...@@ -83,6 +83,9 @@ public class Role extends GenericEntity {
inverseJoinColumns = { @JoinColumn(name = "org_role_id", referencedColumnName = OrgRole.ID_COLUMN) }) inverseJoinColumns = { @JoinColumn(name = "org_role_id", referencedColumnName = OrgRole.ID_COLUMN) })
private List<OrgRole> orgRoles; private List<OrgRole> orgRoles;
@Column(name = "ldap_role", nullable = false)
private boolean ldapRole = false;
public Role() { public Role() {
super(); super();
} }
...@@ -206,4 +209,12 @@ public class Role extends GenericEntity { ...@@ -206,4 +209,12 @@ public class Role extends GenericEntity {
this.orgRoles = orgRoles; this.orgRoles = orgRoles;
} }
public boolean isLdapRole() {
return ldapRole;
}
public void setLdapRole(boolean ldapRole) {
this.ldapRole = ldapRole;
}
} }
...@@ -12,7 +12,6 @@ import javax.persistence.EnumType; ...@@ -12,7 +12,6 @@ import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
...@@ -367,4 +366,10 @@ public class User extends GenericEntity implements IUser { ...@@ -367,4 +366,10 @@ public class User extends GenericEntity implements IUser {
this.licenseCodes = codes; this.licenseCodes = codes;
} }
public String getShortUserDescriptor() {
StringBuilder sb = new StringBuilder();
sb.append(getNick()).append(" // ").append(getWholeName()).append(" // ").append(getEmail());
return sb.toString();
}
} }
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:role="http://java.sun.com/jsf/composite/tools/role"> xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface> <composite:interface>
...@@ -10,6 +11,7 @@ ...@@ -10,6 +11,7 @@
<composite:implementation> <composite:implementation>
<p> <p>
<h:form id="roleform"> <h:form id="roleform">
<f:facet name="errorMessage"> <f:facet name="errorMessage">
...@@ -20,33 +22,65 @@ ...@@ -20,33 +22,65 @@
</h:form> </h:form>
</p> </p>
<h2>#{i18n['role.permissionheader']}</h2> <h:form id="addmember">
<p> <h:outputText value="#{i18n['roleView.adduser']}" />
<h:form id="permissionform">
<h:commandButton id="save1" value="#{i18n['role.savePermissions']}" action="#{roleView.savePermissions}" /> <p:autoComplete id="useradder" value="#{roleView.addableUser}" completeMethod="#{roleView.searchUser}" converter="#{userConverter}" var="usr" itemValue="#{usr}"
<h:dataTable border="1" id="bortalApps" value="#{roleView.rolePermissions}" var="bapp"> itemLabel="#{usr.shortUserDescriptor}">
<h:column> <p:ajax onerror="location.reload(true);" update=":editor:addmember,:editor:memberlist" event="itemSelect" listener="#{roleView.addUser}" />
<f:facet name="header"> </p:autoComplete>
<h:outputText value="#{i18n['applicationPermission.name']}" />
</f:facet>
<h:outputText value="#{bapp.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['applicationPermission.description']}" />
</f:facet>
<h:outputText value="#{i18n[bapp.key]}" />
</h:column>
<h:column>
<h:selectManyCheckbox id="permissions" layout="pageDirection" value="#{bapp.selected}">
<f:selectItems value="#{bapp.permissions}" var="per" itemLabel="#{i18n[per.i18nKey]}" />
</h:selectManyCheckbox>
</h:column>
</h:dataTable>
<h:commandButton id="save2" value="#{i18n['role.savePermissions']}" action="#{roleView.savePermissions}" />
</h:form> </h:form>
</p> <h:dataTable id="memberlist" value="#{roleView.role.users}" var="usr">
<h:column>
<h:outputText value="#{usr.login}" />
</h:column>
<h:column>
<h:outputText value="#{usr.nick}" />
</h:column>
<h:column>
<h:outputText value="#{usr.wholeName}" />
</h:column>
<h:column>
<h:outputText value="#{usr.email}" />
</h:column>
</h:dataTable>
<button id="roledisplayer" onclick='$("#roleeditor").show(); $(this).hide();'>#{i18n['role.showPermissioneditor']}</button>
<div id="roleeditor" style="display: none">
<button onclick='$("#roleeditor").hide(); $("#roledisplayer").show();'>#{i18n['role.hidePermissioneditor']}</button>
<h2>#{i18n['role.permissionheader']}</h2>
<p>
<h:form id="permissionform">
<h:commandButton id="save1" value="#{i18n['role.savePermissions']}" action="#{roleView.savePermissions}" />
<h:dataTable border="1" id="bortalApps" value="#{roleView.rolePermissions}" var="bapp">
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['applicationPermission.name']}" />
</f:facet>
<h:outputText value="#{bapp.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['applicationPermission.description']}" />
</f:facet>
<h:outputText value="#{i18n[bapp.key]}" />
</h:column>
<h:column>
<h:selectManyCheckbox id="permissions" layout="pageDirection" value="#{bapp.selected}">
<f:selectItems value="#{bapp.permissions}" var="per" itemLabel="#{i18n[per.i18nKey]}" />
</h:selectManyCheckbox>
</h:column>
</h:dataTable>
<h:commandButton id="save2" value="#{i18n['role.savePermissions']}" action="#{roleView.savePermissions}" />
</h:form>
</p>
</div>
</composite:implementation> </composite:implementation>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<f:event type="preRenderView" listener="#{roleView.initViewFromId()}" /> <f:event type="preRenderView" listener="#{roleView.initViewFromId()}" />
</f:metadata> </f:metadata>
<ui:define name="content"> <ui:define name="content">
<role:edit /> <role:edit id="editor"/>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -15,11 +15,16 @@ import org.slf4j.LoggerFactory; ...@@ -15,11 +15,16 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.RoleBeanLocal; import fi.codecrew.moya.beans.RoleBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.BortalApplication; import fi.codecrew.moya.enums.BortalApplication;
import fi.codecrew.moya.enums.apps.IAppPermission; import fi.codecrew.moya.enums.apps.IAppPermission;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.model.ApplicationPermission; import fi.codecrew.moya.model.ApplicationPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.util.UserSearchQuery;
import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.helpers.BortalApplicationWrapper; import fi.codecrew.moya.web.helpers.BortalApplicationWrapper;
...@@ -41,6 +46,10 @@ public class RoleView extends GenericCDIView { ...@@ -41,6 +46,10 @@ public class RoleView extends GenericCDIView {
private transient EventBeanLocal eventbean; private transient EventBeanLocal eventbean;
private ArrayList<BortalApplicationWrapper> rolePermissions; private ArrayList<BortalApplicationWrapper> rolePermissions;
@EJB
private UserBeanLocal userbean;
private User addableUser;
private static final Logger logger = LoggerFactory.getLogger(RoleView.class); private static final Logger logger = LoggerFactory.getLogger(RoleView.class);
...@@ -59,6 +68,23 @@ public class RoleView extends GenericCDIView { ...@@ -59,6 +68,23 @@ public class RoleView extends GenericCDIView {
} }
} }
public void addUser()
{
EventUser eu = userbean.getEventUser(addableUser);
role = rolebean.addRole(eu, role);
addableUser = null;
}
public List<User> searchUser(String user)
{
// By default this returns only 20 first results.
UserSearchQuery usq = new UserSearchQuery();
usq.setSearch(user);
usq.setOnlyThisEvent(false);
SearchResult<User> ret = userbean.getUsers(usq);
return ret.getResults();
}
public boolean isCanReadRoles() { public boolean isCanReadRoles() {
return permbean.hasPermission(UserPermission.READ_ROLES); return permbean.hasPermission(UserPermission.READ_ROLES);
} }
...@@ -170,4 +196,12 @@ public class RoleView extends GenericCDIView { ...@@ -170,4 +196,12 @@ public class RoleView extends GenericCDIView {
initPermissions(); initPermissions();
} }
public User getAddableUser() {
return addableUser;
}
public void setAddableUser(User addableUser) {
this.addableUser = addableUser;
}
} }
...@@ -76,11 +76,11 @@ public class UserSearchView extends PaginationView<User> { ...@@ -76,11 +76,11 @@ public class UserSearchView extends PaginationView<User> {
this.setRowCount(new Long(sr.getResultcount()).intValue()); this.setRowCount(new Long(sr.getResultcount()).intValue());
setResultcount(sr.getResultcount()); setResultcount(sr.getResultcount());
setEventUserResults(sr.getResults()); setEventUserResults(sr.getResults());
return sr.getResults(); return sr.getResults();
} }
@Override @Override
public void setRowIndex(int rowIndex) { public void setRowIndex(int rowIndex) {
if (getPageSize() == 0) { if (getPageSize() == 0) {
...@@ -99,7 +99,7 @@ public class UserSearchView extends PaginationView<User> { ...@@ -99,7 +99,7 @@ public class UserSearchView extends PaginationView<User> {
this.setEventUserResults(eventusers.getResults()); this.setEventUserResults(eventusers.getResults());
} }
else { else {
super.setResult(userbean.getEventUsers(getSearchQuery())); super.setResult(userbean.getUsers(getSearchQuery()));
} }
super.beginConversation(); super.beginConversation();
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!