Commit 90200b00 by Tuomas Riihimäki

Random fixes...

1 parent 90bf9f43
...@@ -292,4 +292,17 @@ public class BillBean implements BillBeanLocal { ...@@ -292,4 +292,17 @@ public class BillBean implements BillBeanLocal {
return billFacade.find(user); return billFacade.find(user);
} }
@Override
@RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL })
public Bill expireBill(Bill bill) {
if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to expire a bill for user ");
throw new EJBAccessException("Could not list bills for another user");
}
bill = billFacade.reload(bill);
bill.markExpired();
return bill;
}
} }
...@@ -464,7 +464,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -464,7 +464,7 @@ public class PlaceBean implements PlaceBeanLocal {
* @return true when successfull, on any erroro false. * @return true when successfull, on any erroro false.
*/ */
@Override @Override
@RolesAllowed({ MapPermission.S_RELEASE_PLACE, MapPermission.S_MANAGE_OTHERS }) @RolesAllowed({ MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS })
public boolean releasePlace(Place place) { public boolean releasePlace(Place place) {
place = placeFacade.find(place.getId()); place = placeFacade.find(place.getId());
EventUser user = permbean.getCurrentUser(); EventUser user = permbean.getCurrentUser();
......
...@@ -36,4 +36,6 @@ public interface BillBeanLocal { ...@@ -36,4 +36,6 @@ public interface BillBeanLocal {
List<Bill> find(EventUser user); List<Bill> find(EventUser user);
Bill expireBill(Bill bill);
} }
...@@ -6,12 +6,13 @@ public enum MapPermission implements IAppPermission { ...@@ -6,12 +6,13 @@ public enum MapPermission implements IAppPermission {
MANAGE_OTHERS, // ("Manage other users reservations in map"), MANAGE_OTHERS, // ("Manage other users reservations in map"),
BUY_PLACES, // ("Reserve and buy places from map"), BUY_PLACES, // ("Reserve and buy places from map"),
VIEW, // ("View maps"), VIEW, // ("View maps"),
MANAGE_MAPS, RELEASE_PLACE, // ("Create and modify maps") MANAGE_MAPS,
//RELEASE_PLACE, // ("Create and modify maps")
; ;
public static final String S_MANAGE_OTHERS = "MAP/MANAGE_OTHERS"; public static final String S_MANAGE_OTHERS = "MAP/MANAGE_OTHERS";
public static final String S_BUY_PLACES = "MAP/BUY_PLACES"; //public static final String S_BUY_PLACES = "MAP/BUY_PLACES";
public static final String S_VIEW = "MAP/VIEW"; public static final String S_VIEW = "MAP/VIEW";
public static final String S_MANAGE_MAPS = "MAP/MANAGE_MAPS"; public static final String S_MANAGE_MAPS = "MAP/MANAGE_MAPS";
public static final String S_RELEASE_PLACE = "MAP/RELEASE_PLACE"; public static final String S_RELEASE_PLACE = "MAP/RELEASE_PLACE";
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "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" <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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core">
xmlns:c="http://java.sun.com/jsp/jstl/core"
>
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
...@@ -30,13 +28,18 @@ ...@@ -30,13 +28,18 @@
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['httpsession.creationTime']}" /> <h:outputText value="#{i18n['httpsession.creationTime']}" />
</f:facet> </f:facet>
<h:outputText value="#{sess.creationTime}" /> <h:outputText value="#{sess.creationDateTime}">
<f:convertDateTime pattern="#{sessionHandler.shortDatetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['httpsession.lastAccessedTime']}" /> <h:outputText value="#{i18n['httpsession.lastAccessedTime']}" />
</f:facet> </f:facet>
<h:outputText value="#{sess.lastAccessedTime}" /> <h:outputText value="#{sess.lastAccessedDateTime}">
<f:convertDateTime pattern="#{sessionHandler.shortDatetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
......
...@@ -54,11 +54,6 @@ ...@@ -54,11 +54,6 @@
<version>0.2.0</version> <version>0.2.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0-20130828.122054-5</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId> <groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId> <artifactId>sshd-core</artifactId>
<version>0.8.0</version> <version>0.8.0</version>
...@@ -83,5 +78,10 @@ ...@@ -83,5 +78,10 @@
<artifactId>commons-fileupload</artifactId> <artifactId>commons-fileupload</artifactId>
<version>1.3</version> <version>1.3</version>
</dependency> </dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -165,6 +165,11 @@ public class SessionHandler { ...@@ -165,6 +165,11 @@ public class SessionHandler {
return "dd.MM.yyyy HH:mm"; return "dd.MM.yyyy HH:mm";
} }
public String getShortDatetimeFormat()
{
return "dd.MM HH:MM:ss";
}
public boolean hasPermission(IAppPermission permission) { public boolean hasPermission(IAppPermission permission) {
if (permission == null) { if (permission == null) {
logger.warn("permission is null"); logger.warn("permission is null");
......
...@@ -248,7 +248,9 @@ public class PlaceMap extends HttpServlet { ...@@ -248,7 +248,9 @@ public class PlaceMap extends HttpServlet {
if (!p.isBuyable()) { if (!p.isBuyable()) {
color = LOCKED_COLOR; color = LOCKED_COLOR;
} }
if (p.isReservedFor(user)) { if (p.isReservedFor(user)) {
logger.info("Setting place selected {}", p);
color = SELECTED_COLOR; color = SELECTED_COLOR;
} else if (user.equals(p.getCurrentUser()) } else if (user.equals(p.getCurrentUser())
|| (p.getGroup() != null && user.equals(p.getGroup() || (p.getGroup() != null && user.equals(p.getGroup()
...@@ -256,8 +258,12 @@ public class PlaceMap extends HttpServlet { ...@@ -256,8 +258,12 @@ public class PlaceMap extends HttpServlet {
|| (p.getPlaceReserver() != null && user.equals(p || (p.getPlaceReserver() != null && user.equals(p
.getPlaceReserver().getUser()))) { .getPlaceReserver().getUser()))) {
color = OWNED_COLOR; color = OWNED_COLOR;
logger.info("Setting place owned {}", p);
} else if (p.isTaken()) { } else if (p.isTaken()) {
color = RESERVED_COLOR; color = RESERVED_COLOR;
logger.info("Setting place Reserved {}", p);
} else if (p.getProduct().getColor() != null && !p.getProduct().getColor().isEmpty()) { } else if (p.getProduct().getColor() != null && !p.getProduct().getColor().isEmpty()) {
try { try {
...@@ -272,6 +278,7 @@ public class PlaceMap extends HttpServlet { ...@@ -272,6 +278,7 @@ public class PlaceMap extends HttpServlet {
.getHeight())); .getHeight()));
if (color != null) { if (color != null) {
logger.info("Setting fill color: {} for p", color, p);
g.setColor(color); g.setColor(color);
g.fill(new Rectangle(p.getMapX() + BORDER_WIDTH, p.getMapY() g.fill(new Rectangle(p.getMapX() + BORDER_WIDTH, p.getMapY()
+ BORDER_WIDTH, p.getWidth() - BORDER_WIDTH, p.getHeight() + BORDER_WIDTH, p.getWidth() - BORDER_WIDTH, p.getHeight()
......
...@@ -118,22 +118,7 @@ public class BillEditView extends GenericCDIView { ...@@ -118,22 +118,7 @@ public class BillEditView extends GenericCDIView {
} }
public void expireBill() { public void expireBill() {
System.out.println("EXPIRE BILL; WE ARE THERE"); bill = billbean.expireBill(bill);
bill.markExpired();
System.out.println(""+ bill.getExpires().getTime());
this.save();
} }
} }
package fi.codecrew.moya.web.cdiview.user; package fi.codecrew.moya.web.cdiview.user;
import java.util.ArrayList;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
...@@ -14,6 +12,7 @@ import org.slf4j.LoggerFactory; ...@@ -14,6 +12,7 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.SessionMgmtBeanLocal; import fi.codecrew.moya.beans.SessionMgmtBeanLocal;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.helper.HttpSessionWrapper;
@Named @Named
@ConversationScoped @ConversationScoped
...@@ -22,7 +21,7 @@ public class UserSessionView extends GenericCDIView { ...@@ -22,7 +21,7 @@ public class UserSessionView extends GenericCDIView {
private static final long serialVersionUID = -5305969666679378884L; private static final long serialVersionUID = -5305969666679378884L;
@EJB @EJB
private transient SessionMgmtBeanLocal sessionMgmt; private transient SessionMgmtBeanLocal sessionMgmt;
private transient ListDataModel<HttpSession> sessions; private transient ListDataModel<HttpSessionWrapper> sessions;
private transient HttpSession session; private transient HttpSession session;
...@@ -33,16 +32,16 @@ public class UserSessionView extends GenericCDIView { ...@@ -33,16 +32,16 @@ public class UserSessionView extends GenericCDIView {
{ {
if (super.requirePermissions(UserPermission.MANAGE_HTTP_SESSION) && sessions == null) if (super.requirePermissions(UserPermission.MANAGE_HTTP_SESSION) && sessions == null)
{ {
sessions = new ListDataModel<HttpSession>(new ArrayList<HttpSession>(sessionMgmt.getSessions())); sessions = new ListDataModel<>(HttpSessionWrapper.wrap(sessionMgmt.getSessions()));
super.beginConversation(); super.beginConversation();
} }
} }
public ListDataModel<HttpSession> getSessions() { public ListDataModel<HttpSessionWrapper> getSessions() {
return sessions; return sessions;
} }
public void setSessions(ListDataModel<HttpSession> sessions) { public void setSessions(ListDataModel<HttpSessionWrapper> sessions) {
this.sessions = sessions; this.sessions = sessions;
} }
......
package fi.codecrew.moya.web.helper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;
public class HttpSessionWrapper implements HttpSession
{
private final HttpSession session;
public HttpSessionWrapper(HttpSession session)
{
this.session = session;
}
@Override
public Object getAttribute(String attr) {
return session.getAttribute(attr);
}
@Override
public Enumeration<String> getAttributeNames() {
return session.getAttributeNames();
}
@Override
public long getCreationTime() {
return session.getCreationTime();
}
public Date getCreationDateTime() {
Date ret = null;
try {
ret = new Date(session.getCreationTime());
} catch (Throwable t) {
ret = null;
}
return ret;
}
@Override
public String getId() {
return session.getId();
}
@Override
public long getLastAccessedTime() {
return session.getLastAccessedTime();
}
public Date getLastAccessedDateTime() {
Date ret = null;
try {
ret = new Date(session.getLastAccessedTime());
} catch (Throwable t) {
ret = null;
}
return ret;
}
@Override
public int getMaxInactiveInterval() {
return session.getMaxInactiveInterval();
}
@Override
public ServletContext getServletContext() {
return session.getServletContext();
}
@Override
public HttpSessionContext getSessionContext() {
return session.getSessionContext();
}
@Override
public Object getValue(String arg0) {
return session.getValue(arg0);
}
@Override
public String[] getValueNames() {
return session.getValueNames();
}
@Override
public void invalidate() {
session.invalidate();
}
@Override
public boolean isNew() {
return session.isNew();
}
@Override
public void putValue(String arg0, Object arg1) {
session.putValue(arg0, arg1);
}
@Override
public void removeAttribute(String arg0) {
session.removeAttribute(arg0);
}
@Override
public void removeValue(String arg0) {
session.removeValue(arg0);
}
@Override
public void setAttribute(String arg0, Object arg1) {
session.setAttribute(arg0, arg1);
}
@Override
public void setMaxInactiveInterval(int arg0) {
session.setMaxInactiveInterval(arg0);
}
public static List<HttpSessionWrapper> wrap(Set<HttpSession> sessions) {
ArrayList<HttpSessionWrapper> ret = new ArrayList<>();
for (HttpSession s : sessions) {
ret.add(new HttpSessionWrapper(s));
}
Collections.sort(ret, new LastSeenComparator());
return ret;
}
private static class LastSeenComparator implements Comparator<HttpSessionWrapper>
{
@Override
public int compare(HttpSessionWrapper o1, HttpSessionWrapper o2) {
return Long.compare(o1.getLastAccessedTime(), o2.getLastAccessedTime());
}
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!