Commit 7c9e1ccf by Tuukka Kivilahti

now tournament admin can decide roles for tournament

1 parent 2759f2b5
...@@ -32,6 +32,8 @@ import fi.codecrew.moya.model.TournamentRule; ...@@ -32,6 +32,8 @@ import fi.codecrew.moya.model.TournamentRule;
@Local @Local
public interface TournamentBeanLocal { public interface TournamentBeanLocal {
boolean canUserParticipate(Tournament tournament);
List<TournamentGame> getGames(); List<TournamentGame> getGames();
List<TournamentRule> getRulesByGame(TournamentGame tg); List<TournamentRule> getRulesByGame(TournamentGame tg);
TournamentGame createGame(TournamentGame tg); TournamentGame createGame(TournamentGame tg);
......
...@@ -401,6 +401,11 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -401,6 +401,11 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE places RENAME release_time TO reserve_time;" "ALTER TABLE places RENAME release_time TO reserve_time;"
}); });
dbUpdates.add(new String[] {
"CREATE TABLE tournament_roles (role_id INTEGER NOT NULL, tournament_id INTEGER NOT NULL, PRIMARY KEY (role_id, tournament_id))",
"ALTER TABLE tournament_roles ADD CONSTRAINT FK_tournament_roles_tournament_id FOREIGN KEY (tournament_id) REFERENCES tournaments (id)",
"ALTER TABLE tournament_roles ADD CONSTRAINT FK_tournament_roles_role_id FOREIGN KEY (role_id) REFERENCES roles (id)",
});
} }
......
...@@ -52,6 +52,11 @@ public class BotBean implements BotBeanLocal { ...@@ -52,6 +52,11 @@ public class BotBean implements BotBeanLocal {
public void message(Message message) { public void message(Message message) {
// on development places, it's possibly that there is no bot
if(bot == null) {
return;
}
try { try {
MoyaEventMessage msg = message.getBody(MoyaEventMessage.class); MoyaEventMessage msg = message.getBody(MoyaEventMessage.class);
......
...@@ -18,29 +18,18 @@ ...@@ -18,29 +18,18 @@
*/ */
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.util.Date; import fi.codecrew.moya.enums.TournamentStatus;
import java.util.List; import fi.codecrew.moya.enums.TournamentTeamMemberRole;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.facade.*;
import fi.codecrew.moya.model.*;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import java.util.Date;
import fi.codecrew.moya.enums.TournamentStatus; import java.util.List;
import fi.codecrew.moya.enums.TournamentTeamMemberRole;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.TournamentFacade;
import fi.codecrew.moya.facade.TournamentGameFacade;
import fi.codecrew.moya.facade.TournamentParticipantFacade;
import fi.codecrew.moya.facade.TournamentRuleFacade;
import fi.codecrew.moya.facade.TournamentTeamMemberFacade;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentParticipant;
import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.model.TournamentTeamMember;
/** /**
* Session Bean implementation class TournamentBean * Session Bean implementation class TournamentBean
...@@ -80,6 +69,30 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -80,6 +69,30 @@ public class TournamentBean implements TournamentBeanLocal {
} }
@Override @Override
public boolean canUserParticipate(Tournament tournament) {
if(!permissionBean.hasPermission(TournamentPermission.PARTICIPATE))
return false;
if(tournament == null) {
return false;
}
// no roles specified, open for everyone
if(tournament.getOpenForRoles() == null || tournament.getOpenForRoles().size() == 0) {
return true;
}
for (Role r : tournament.getOpenForRoles()) {
if (permissionBean.getCurrentUser().getRoles().contains(r)) {
return true;
}
}
return false;
}
@Override
@RolesAllowed(TournamentPermission.S_VIEW) @RolesAllowed(TournamentPermission.S_VIEW)
public List<TournamentGame> getGames() { public List<TournamentGame> getGames() {
return tournamentGameFacade.getGames(); return tournamentGameFacade.getGames();
......
...@@ -21,7 +21,9 @@ package fi.codecrew.moya.model; ...@@ -21,7 +21,9 @@ package fi.codecrew.moya.model;
import fi.codecrew.moya.enums.TournamentStatus; import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.enums.TournamentType; import fi.codecrew.moya.enums.TournamentType;
import fi.codecrew.moya.model.GenericEntity; import fi.codecrew.moya.model.GenericEntity;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -30,75 +32,81 @@ import javax.persistence.*; ...@@ -30,75 +32,81 @@ import javax.persistence.*;
/** /**
* Entity implementation class for Entity: Tournament * Entity implementation class for Entity: Tournament
*
*/ */
@Entity @Entity
@Table(name="tournaments") @Table(name = "tournaments")
public class Tournament extends GenericEntity implements Serializable { public class Tournament extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Column(name="talyn_tournament_id", nullable=true)
@ManyToMany()
@JoinTable(name = "tournament_roles", joinColumns = {@JoinColumn(name = "tournament_id", referencedColumnName = Lecture.ID_COLUMN)}, inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = Role.ID_COLUMN)})
private List<Role> openForRoles;
@Column(name = "talyn_tournament_id", nullable = true)
private Integer talynTournamentId; private Integer talynTournamentId;
@JoinColumn(name = "event_id", nullable = false) @JoinColumn(name = "event_id", nullable = false)
private LanEvent lanEvent; private LanEvent lanEvent;
@Column(name="tournament_name") @Column(name = "tournament_name")
private String tournamentName; private String tournamentName;
@Column(name="registration_opens_at") @Column(name = "registration_opens_at")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date registrationOpensAt; private Date registrationOpensAt;
@Column(name="registration_closes_at") @Column(name = "registration_closes_at")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date registrationClosesAt; private Date registrationClosesAt;
@Column(name="begins_at") @Column(name = "begins_at")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date beginsAt; private Date beginsAt;
@Column(name="tournament_type") @Column(name = "tournament_type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private TournamentType tournamentType; private TournamentType tournamentType;
@Column(name="tournament_status") @Column(name = "tournament_status")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private TournamentStatus tournamentStatus; private TournamentStatus tournamentStatus;
@OneToOne @OneToOne
@JoinColumn(name="tournament_root") @JoinColumn(name = "tournament_root")
private TournamentMatch tournamentRoot; private TournamentMatch tournamentRoot;
@Column(name="players_per_match") @Column(name = "players_per_match")
private Integer playersPerMatch; private Integer playersPerMatch;
@Column(name="players_per_team") @Column(name = "players_per_team")
private Integer playersPerTeam; private Integer playersPerTeam;
@Column(name="max_participants") @Column(name = "max_participants")
private Integer maxParticipants; private Integer maxParticipants;
@ManyToOne @ManyToOne
@JoinColumn(name="game", nullable=false) @JoinColumn(name = "game", nullable = false)
private TournamentGame tournamentGame; private TournamentGame tournamentGame;
@ManyToOne @ManyToOne
@JoinColumn(name="rules", nullable=false) @JoinColumn(name = "rules", nullable = false)
private TournamentRule rules; private TournamentRule rules;
@ManyToOne @ManyToOne
@JoinColumn(name="parent_tournament") @JoinColumn(name = "parent_tournament")
private Tournament parentTournament; private Tournament parentTournament;
@OneToMany(mappedBy="parentTournament") @OneToMany(mappedBy = "parentTournament")
@OrderBy("id ASC") @OrderBy("id ASC")
private List<Tournament> subTournaments; private List<Tournament> subTournaments;
@OneToMany(mappedBy="tournament") @OneToMany(mappedBy = "tournament")
private List<TournamentParticipant> participants; private List<TournamentParticipant> participants;
public Tournament() { super(); } public Tournament() {
super();
}
public Integer getTalynTournamentId() { public Integer getTalynTournamentId() {
return talynTournamentId; return talynTournamentId;
...@@ -203,6 +211,7 @@ public class Tournament extends GenericEntity implements Serializable { ...@@ -203,6 +211,7 @@ public class Tournament extends GenericEntity implements Serializable {
public void setSubTournaments(List<Tournament> subTournaments) { public void setSubTournaments(List<Tournament> subTournaments) {
this.subTournaments = subTournaments; this.subTournaments = subTournaments;
} }
public TournamentRule getRules() { public TournamentRule getRules() {
return rules; return rules;
} }
...@@ -226,4 +235,16 @@ public class Tournament extends GenericEntity implements Serializable { ...@@ -226,4 +235,16 @@ public class Tournament extends GenericEntity implements Serializable {
public void setTournamentParticipants(List<TournamentParticipant> participants) { public void setTournamentParticipants(List<TournamentParticipant> participants) {
this.participants = participants; this.participants = participants;
} }
public List<Role> getOpenForRoles() {
if (openForRoles == null)
openForRoles = new ArrayList<>();
return openForRoles;
}
public void setOpenForRoles(List<Role> openForRoles) {
this.openForRoles = openForRoles;
}
} }
...@@ -99,7 +99,6 @@ ...@@ -99,7 +99,6 @@
<p:slider for="playerBackupSlider" /> <p:slider for="playerBackupSlider" />
</h:panelGrid> </h:panelGrid>
<h2>#{i18n['tournaments.admin.registration_time_constraints']}</h2> <h2>#{i18n['tournaments.admin.registration_time_constraints']}</h2>
<h:panelGrid columns="2"> <h:panelGrid columns="2">
...@@ -114,6 +113,12 @@ ...@@ -114,6 +113,12 @@
<h:outputText value="Start time" /> <h:outputText value="Start time" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy HH:mm" value="#{tournamentCreateView.tournament.beginsAt}"/> <p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy HH:mm" value="#{tournamentCreateView.tournament.beginsAt}"/>
</h:panelGrid> </h:panelGrid>
<h2>#{i18n['tournaments.admin.open_for_roles']}</h2>
<h:selectManyCheckbox converter="#{roleConverter}" layout="pageDirection" id="roles" value="#{tournamentCreateView.tournament.openForRoles}">
<f:selectItems var="roleitem" itemLabel="#{roleitem.name}" value="#{roleDataView.roles}" />
</h:selectManyCheckbox>
<br /> <br />
</p:panel> </p:panel>
<div style="float: right;"> <div style="float: right;">
......
...@@ -51,6 +51,11 @@ ...@@ -51,6 +51,11 @@
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy HH:mm" value="#{tournamentEditView.tournament.beginsAt}"/> <p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy HH:mm" value="#{tournamentEditView.tournament.beginsAt}"/>
</h:panelGrid> </h:panelGrid>
<h2>#{i18n['tournaments.admin.open_for_roles']}</h2>
<h:selectManyCheckbox converter="#{roleConverter}" layout="pageDirection" id="roles" value="#{tournamentEditView.tournament.openForRoles}">
<f:selectItems var="roleitem" itemLabel="#{roleitem.name}" value="#{roleDataView.roles}" />
</h:selectManyCheckbox>
<p:commandButton value="#{i18n['tournaments.admin.cancel_edits']}" action="#{tournamentEditView.cancel}" ajax="false" onerror="location.reload(true);"/> <p:commandButton value="#{i18n['tournaments.admin.cancel_edits']}" action="#{tournamentEditView.cancel}" ajax="false" onerror="location.reload(true);"/>
<p:commandButton value="#{i18n['tournaments.admin.edit_tournament']}" action="#{tournamentEditView.commit}" ajax="false" onerror="location.reload(true);"/> <p:commandButton value="#{i18n['tournaments.admin.edit_tournament']}" action="#{tournamentEditView.commit}" ajax="false" onerror="location.reload(true);"/>
</h:form> </h:form>
......
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
</f:facet> </f:facet>
<h:panelGroup> <h:panelGroup>
<p:commandButton value="#{i18n['tournament.participate']}" action="#{tournamentParticipateView.participate(tournament.id)}" <p:commandButton value="#{i18n['tournament.participate']}" action="#{tournamentParticipateView.participate(tournament.id)}"
rendered="#{tournament.participants.size() lt tournament.maxParticipants}" ajax="false" onerror="location.reload(true);"/> rendered="#{tournamentParticipateView.canParticipate(tournament.id) and (tournament.participants.size() lt tournament.maxParticipants)}" ajax="false" onerror="location.reload(true);"/>
<h:outputText value="#{i18n['tournament.full']}" rendered="#{tournament.participants.size() ge tournament.maxParticipants}" /> <h:outputText value="#{i18n['tournament.full']}" rendered="#{tournament.participants.size() ge tournament.maxParticipants}" />
</h:panelGroup> </h:panelGroup>
</p:column> </p:column>
...@@ -95,6 +95,8 @@ ...@@ -95,6 +95,8 @@
</h:panelGrid> </h:panelGrid>
</p:rowExpansion> </p:rowExpansion>
</p:dataTable> </p:dataTable>
<p></p> <p></p>
<h2>#{i18n['tournaments.setup_closed_tournaments']}</h2> <h2>#{i18n['tournaments.setup_closed_tournaments']}</h2>
<p:dataTable value="#{tournamentListView.setupClosedPhaseTournaments}" var="tournament" styleClass="moya_datatable2">> <p:dataTable value="#{tournamentListView.setupClosedPhaseTournaments}" var="tournament" styleClass="moya_datatable2">>
......
...@@ -87,13 +87,23 @@ public class TournamentParticipateView extends GenericCDIView { ...@@ -87,13 +87,23 @@ public class TournamentParticipateView extends GenericCDIView {
} }
} }
public boolean canParticipate(Integer tournamentId) {
Tournament t = tournamentBean.getTournamentById(tournamentId);
return tournamentBean.canUserParticipate(t);
}
public String participate(Integer tournamentId) { public String participate(Integer tournamentId) {
if (!super.hasPermission(TournamentPermission.PARTICIPATE)) {
tournament = tournamentBean.getTournamentById(tournamentId);
if (!tournamentBean.canUserParticipate(tournament)) {
super.addFaceMessage("tournament.notRightsToParticipate"); super.addFaceMessage("tournament.notRightsToParticipate");
return null; return null;
} }
tournament = tournamentBean.getTournamentById(tournamentId);
if (tournamentBean.hasParticipations(permissionBean.getCurrentUser(), tournament)) { if (tournamentBean.hasParticipations(permissionBean.getCurrentUser(), tournament)) {
MessageHelper.err("tournament.already_participated_into_tournament"); MessageHelper.err("tournament.already_participated_into_tournament");
return "/tournaments/index.xhtml"; return "/tournaments/index.xhtml";
...@@ -212,9 +222,6 @@ public class TournamentParticipateView extends GenericCDIView { ...@@ -212,9 +222,6 @@ public class TournamentParticipateView extends GenericCDIView {
return "/tournaments/index.xhtml"; return "/tournaments/index.xhtml";
} }
public boolean canParticipate() {
return super.hasPermission(TournamentPermission.PARTICIPATE);
}
public Tournament getTournament() { public Tournament getTournament() {
return tournament; return tournament;
......
...@@ -53,7 +53,7 @@ public class RoleDataView extends GenericCDIView { ...@@ -53,7 +53,7 @@ public class RoleDataView extends GenericCDIView {
public ListDataModel<Role> getRoles() { public ListDataModel<Role> getRoles() {
if (roles == null) { if (roles == null) {
roles = new ListDataModel<Role>(rolebean.listRoles()); roles = new ListDataModel<>(rolebean.listRoles());
} }
return roles; return roles;
} }
......
...@@ -1560,3 +1560,4 @@ voting.create.voteEnd = Voting close ...@@ -1560,3 +1560,4 @@ voting.create.voteEnd = Voting close
voting.create.voteStart = Voting start voting.create.voteStart = Voting start
yes = Yes yes = Yes
tournaments.admin.open_for_roles=Roles allowing registeration
...@@ -1836,3 +1836,4 @@ voting.create.voteEnd = Voting close ...@@ -1836,3 +1836,4 @@ voting.create.voteEnd = Voting close
voting.create.voteStart = Voting start voting.create.voteStart = Voting start
yes = Yes yes = Yes
tournaments.admin.open_for_roles=Roles allowing registeration
...@@ -1823,3 +1823,4 @@ voting.create.voteEnd = \u00C4\u00E4nestys kiinni ...@@ -1823,3 +1823,4 @@ voting.create.voteEnd = \u00C4\u00E4nestys kiinni
voting.create.voteStart = \u00C4\u00E4nestys auki voting.create.voteStart = \u00C4\u00E4nestys auki
yes = Kyll\u00E4 yes = Kyll\u00E4
tournaments.admin.open_for_roles=Rekister\u00F6itymiseen oikeuttavat ryhm\u00E4t
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!