Commit 2cf56407 by Tuomas Riihimäki

Participate role checking.

1 parent 1eeae2e4
......@@ -118,9 +118,9 @@ public class MenuBean implements MenuBeanLocal {
userprofile.addPage(menuitemfacade.findOrCreate("/user/edit"), UserPermission.VIEW_SELF);
userprofile.addPage(menuitemfacade.findOrCreate("/user/changePassword"), UserPermission.VIEW_SELF);
userprofile.addPage(menuitemfacade.findOrCreate("/user/gameids"), TournamentPermission.VIEW);
userprofile.addPage(menuitemfacade.findOrCreate("/user/gameids"), TournamentPermission.PARTICIPATE);
userprofile.addPage(menuitemfacade.findOrCreate("/auth/logout"), UserPermission.LOGOUT);
MenuNavigation tournaments = usermenu.addPage(null, null);
tournaments.setKey("tournaments.menutitle");
tournaments.addPage(menuitemfacade.findOrCreate("/tournaments/index"), TournamentPermission.VIEW);
......@@ -240,7 +240,7 @@ public class MenuBean implements MenuBeanLocal {
// shopnavi.addPage(menuitemfacade.findOrCreate("/index3"),
// UserPermission.ANYUSER);
navifacade.create(shopmenu);
MenuNavigation tournamentsadm = adminmenu.addPage(null, null);
tournamentsadm.setKey("tournaments.menutitle");
tournamentsadm.addPage(menuitemfacade.findOrCreate("/tournaments/admin/index"), TournamentPermission.MANAGE_ALL);
......
......@@ -6,6 +6,7 @@
<project>lib-AuthModule-depends</project>
<project>MoyaAuthModule</project>
<project>MoyaCardPrinter</project>
<project>MoyaEventMgmtWeb</project>
</projects>
<buildSpec>
<buildCommand>
......
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" version="7">
<display-name>moya-ear</display-name>
<module>
<ejb>moya-beans-0.2.0.jar</ejb>
</module>
<module>
<web>
<web-uri>moya-web-0.2.0.war</web-uri>
<context-root>/MoyaWeb</context-root>
</web>
</module>
<library-directory>lib</library-directory>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd"
version="7">
<display-name>moya-ear</display-name>
<module>
<ejb>moya-beans-0.2.0.jar</ejb>
</module>
<module>
<web>
<web-uri>moya-web-0.2.0.war</web-uri>
<context-root>/MoyaWeb</context-root>
</web>
</module>
<!-- <module> <web> <web-uri>MoyaEventMgmtWeb.war</web-uri> <context-root>EventMgmt</context-root>
</web> </module> -->
<library-directory>lib</library-directory>
</application>
\ No newline at end of file
......@@ -17,6 +17,8 @@
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<filter>
<display-name>PrimefacesFileupload</display-name>
<filter-name>PrimefacesFileupload</filter-name>
......
......@@ -5,6 +5,8 @@
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{tournamentDeleteView.initView()}" />
</f:metadata>
<ui:define name="content">
......
......@@ -5,6 +5,7 @@
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{tournamentEditView.initView()}" />
</f:metadata>
<ui:define name="content">
......
......@@ -5,6 +5,7 @@
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{tournamentAdminView.initView()}" />
</f:metadata>
<ui:define name="content">
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:users="http://java.sun.com/jsf/composite/cditools/user"
xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{tournamentListView.initView()}" />
</f:metadata>
<ui:define name="content">
......@@ -14,10 +17,10 @@
<p>#{i18n['tournaments.description']}</p>
<h2>#{i18n['tournaments.open_tournaments']}</h2>
<p:dataTable value="#{tournamentListView.setupPhaseTournaments}" var="tournament">
<p:column style="width:2%">
<p:rowToggler />
</p:column>
<p:column>
<p:column style="width:2%">
<p:rowToggler />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.name']}" />
</f:facet>
......@@ -49,7 +52,7 @@
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.participation_time']}" />
<h:outputText value="#{i18n['tournament.participation_time']}" />
</f:facet>
<h:outputText value="#{tournament.registrationOpensAt}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
......@@ -67,32 +70,31 @@
<f:param name="tournament_id" value="#{tournament.id}" />
</h:link>
</p:column>
<p:column>
<p:column rendered="#{tournamentListView.canParticipate()}">
<f:facet name="header">
<h:outputText value="#{i18n['tournament.control']}" />
</f:facet>
<h:panelGroup>
<p:commandButton value="#{i18n['tournament.participate']}" action="#{tournamentParticipateView.participate(tournament.id)}" rendered="#{tournament.participants.size() lt tournament.maxParticipants}" ajax="false"/>
<h:outputText value="#{i18n['tournament.full']}" rendered="#{tournament.participants.size() ge tournament.maxParticipants}"/>
<p:commandButton value="#{i18n['tournament.participate']}" action="#{tournamentParticipateView.participate(tournament.id)}"
rendered="#{tournament.participants.size() lt tournament.maxParticipants}" ajax="false" />
<h:outputText value="#{i18n['tournament.full']}" rendered="#{tournament.participants.size() ge tournament.maxParticipants}" />
</h:panelGroup>
</p:column>
<p:rowExpansion>
<h:panelGrid id="display" columns="2" cellpadding="4" styleClass=" ui-widget-content grid">
<h:outputText value="#{i18n['tournament.participants']}" />
<h:panelGroup>
<ul>
<ui:repeat var="participant" value="#{tournament.participants}">
<li>
<h:outputText value="#{participant.teamName}" rendered="#{not empty participant.teamName}" />
<h:outputText value="#{participant.participator.user.nick}" rendered="#{empty participant.teamName}" />
</li>
</ui:repeat>
</ul>
</h:panelGroup>
</h:panelGrid>
<p:rowExpansion>
<h:panelGrid id="display" columns="2" cellpadding="4" styleClass=" ui-widget-content grid">
<h:outputText value="#{i18n['tournament.participants']}" />
<h:panelGroup>
<ul>
<ui:repeat var="participant" value="#{tournament.participants}">
<li><h:outputText value="#{participant.teamName}" rendered="#{not empty participant.teamName}" /> <h:outputText value="#{participant.participator.user.nick}"
rendered="#{empty participant.teamName}" /></li>
</ui:repeat>
</ul>
</h:panelGroup>
</h:panelGrid>
</p:rowExpansion>
</p:dataTable>
</h:form>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
......
......@@ -5,6 +5,7 @@
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{tournamentParticipateView.initView()}" />
</f:metadata>
<ui:define name="content">
......
......@@ -5,6 +5,7 @@
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{tournamentParticipateView.initView()}" />
</f:metadata>
<ui:define name="content">
......
......@@ -81,7 +81,7 @@
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0-SNAPSHOT</version>
<version>4.0.RC1</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -7,18 +7,30 @@ import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@RequestScoped
@Named
public class TournamentAdminView {
@EJB private TournamentBeanLocal tournamentBean;
public class TournamentAdminView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = -9079431236226432769L;
@EJB
private TournamentBeanLocal tournamentBean;
public void initView()
{
super.requirePermissions(TournamentPermission.MANAGE_ALL);
}
public List<Tournament> getActiveTournaments() {
List<Tournament> tl = tournamentBean.getActiveTournaments();
return tl;
}
public String create() {
return "create";
}
......
package fi.codecrew.moya.web.cdiview.tournaments;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import org.primefaces.event.FlowEvent;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.enums.TournamentType;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import org.primefaces.event.FlowEvent;
@Named
@ConversationScoped
public class TournamentCreateView extends GenericCDIView {
......@@ -29,26 +26,28 @@ public class TournamentCreateView extends GenericCDIView {
private List<TournamentGame> tournamentGames;
private List<TournamentRule> tournamentRules;
private TournamentRule rules = null;
private TournamentGame game = null;
private Tournament tournament = null;
private String tournamentGameName;
private String tournamentGameDescription;
private String rulesetName;
private String rulesetDescription;
private String rulesetRules;
private Integer backupPlayers;
@EJB TournamentBeanLocal tournamentBean;
@EJB EventBeanLocal eventBean;
@EJB
TournamentBeanLocal tournamentBean;
@EJB
EventBeanLocal eventBean;
public void initView() {
if(tournament == null) {
this.beginConversation();
if (super.requirePermissions(TournamentPermission.MANAGE_ALL) && tournament == null) {
this.beginConversation();
tournament = new Tournament();
tournament.setPlayersPerMatch(0);
tournament.setMaxParticipants(0);
......@@ -57,66 +56,65 @@ public class TournamentCreateView extends GenericCDIView {
}
}
public String save() {
tournament.setPlayersPerTeam(tournament.getPlayersPerMatch() + backupPlayers);
tournament.setLanEvent(eventBean.getCurrentEvent());
tournament.setTournamentStatus(TournamentStatus.SETUP);
tournament.setTournamentGame(game);
tournament.setRules(rules);
try {
tournamentBean.createTournament(tournament);
this.endConversation();
return "success";
} catch(Exception e) {
} catch (Exception e) {
MessageHelper.err(e.getMessage());
return "";
}
}
public List<TournamentGame> getTournamentGames() {
return tournamentGames;
}
public List<TournamentRule> getTournamentRules() {
return tournamentRules;
}
public void uploadListener(org.primefaces.event.FileUploadEvent event) {
System.out.println("ZZ");
}
System.out.println("ZZ");
}
public TournamentType[] getTournamentTypes() {
TournamentType[] items = TournamentType.values();
return items;
}
}
public String onFlowProcess(FlowEvent event) {
switch(event.getOldStep()) {
switch (event.getOldStep()) {
case "selectGame":
if(tournamentGameName.length() > 0) {
if (tournamentGameName.length() > 0) {
// oh lurd, we want to create a new gamy now
TournamentGame tg = new TournamentGame();
tg.setName(tournamentGameName);
tg.setDescription(tournamentGameDescription);
tg.setLanEvent(eventBean.getCurrentEvent());
game = tournamentBean.createGame(tg);
}
tournamentRules = tournamentBean.getRulesByGame(game);
System.out.println(tournamentRules);
break;
case "selectRuleset":
if(rulesetName != null && rulesetName.length() > 0) {
if (rulesetName != null && rulesetName.length() > 0) {
TournamentRule tr = new TournamentRule();
tr.setName(rulesetName);
tr.setDescription(rulesetDescription);
tr.setRules(rulesetRules);
tr.setTournamentGame(game);
rules = tournamentBean.createRule(tr);
tournamentRules = tournamentBean.getRulesByGame(game);
}
break;
......
......@@ -2,11 +2,10 @@ package fi.codecrew.moya.web.cdiview.tournaments;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedProperty;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
......@@ -16,31 +15,37 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
public class TournamentDeleteView extends GenericCDIView {
private static final long serialVersionUID = 7283815262506163537L;
private Integer id = null;
@EJB private TournamentBeanLocal tournamentBean;
@EJB
private TournamentBeanLocal tournamentBean;
public void initView()
{
super.requirePermissions(TournamentPermission.MANAGE_ALL);
}
public String showConfirm(Integer id) {
this.beginConversation();
this.id = id;
return "/tournaments/admin/delete.xhtml";
}
public String delete() {
if(this.id != null) {
if (this.id != null) {
try {
tournamentBean.deleteTournament(tournamentBean.getTournamentById(this.id));
MessageHelper.info(I18n.get("tournament.admin.tournament_deleted_successfully"));
} catch(Exception e) {
} catch (Exception e) {
MessageHelper.err(I18n.get("tournament.admin.tournament_delete_failed"));
}
} else {
MessageHelper.err(I18n.get("tournament.admin.tournament_delete_failed"));
}
this.endConversation();
return "/tournaments/admin/index.xhtml";
}
public String cancel() {
this.endConversation();
return "/tournaments/admin/index.xhtml";
......
......@@ -2,10 +2,10 @@ package fi.codecrew.moya.web.cdiview.tournaments;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
......@@ -14,22 +14,32 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class TournamentEditView extends GenericCDIView {
@EJB private TournamentBeanLocal tournamentBean;
/**
*
*/
private static final long serialVersionUID = -2655058086651272660L;
@EJB
private TournamentBeanLocal tournamentBean;
private Tournament tournament = null;
public void initView()
{
super.requirePermissions(TournamentPermission.MANAGE_ALL);
}
public String showEdit(Integer tournamentId) {
this.beginConversation();
this.setTournament(tournamentBean.getTournamentById(tournamentId));
return "/tournaments/admin/edit.xhtml";
}
public String commit() {
if(this.tournament != null) {
if (this.tournament != null) {
try {
this.tournamentBean.editTournament(tournament);
MessageHelper.info(I18n.get("tournament.admin.tournament_edited_successfully"));
} catch(Exception e) {
} catch (Exception e) {
MessageHelper.err(I18n.get("tournament.admin.tournament_edit_failed"));
}
} else {
......@@ -38,7 +48,7 @@ public class TournamentEditView extends GenericCDIView {
this.endConversation();
return "/tournaments/admin/index.xhtml";
}
public String cancel() {
this.endConversation();
return "/tournaments/admin/index.xhtml";
......
......@@ -16,6 +16,10 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
@RequestScoped
public class TournamentListView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 5401481953726472887L;
@EJB
private TournamentBeanLocal tournamentBean;
......@@ -23,6 +27,10 @@ public class TournamentListView extends GenericCDIView {
super.requirePermissions(TournamentPermission.VIEW);
}
public boolean canParticipate() {
return super.hasPermission(TournamentPermission.PARTICIPATE);
}
public List<Tournament> getSetupPhaseTournaments() {
return tournamentBean.getTournamentsInStatus(TournamentStatus.SETUP, true);
}
......
......@@ -29,6 +29,10 @@ public class TournamentParticipateView extends GenericCDIView {
@EJB
private PermissionBeanLocal permissionBean;
public void initView() {
super.requirePermissions(TournamentPermission.PARTICIPATE);
}
private String selectedPlayerLogin;
private String selectedBackupPlayerLogin;
......@@ -66,6 +70,11 @@ public class TournamentParticipateView extends GenericCDIView {
}
public String participate(Integer tournamentId) {
if (!super.hasPermission(TournamentPermission.PARTICIPATE)) {
super.addFaceMessage("tournament.notRightsToParticipate");
return null;
}
tournament = tournamentBean.getTournamentById(tournamentId);
if (tournamentBean.hasParticipations(permissionBean.getCurrentUser(), tournament)) {
MessageHelper.err("tournament.already_participated_into_tournament");
......
package fi.codecrew.moya.web.cdiview.tournaments;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedProperty;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@RequestScoped
public class TournamentRulesView {
@EJB private TournamentBeanLocal tournamentBean;
public class TournamentRulesView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 590702851593367871L;
@EJB
private TournamentBeanLocal tournamentBean;
private Tournament tournament;
private Integer tournamentId;
public void init() {
tournament = tournamentBean.getTournamentById(tournamentId);
if (super.requirePermissions(TournamentPermission.VIEW))
{
tournament = tournamentBean.getTournamentById(tournamentId);
}
}
public Integer getTournamentId() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!