Commit 04b71352 by Tuomas Riihimäki

Add some permissions to rest and fix accounteventcreation while reserving places

1 parent 345952f5
...@@ -200,15 +200,15 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -200,15 +200,15 @@ public class PlaceBean implements PlaceBeanLocal {
place = placeFacade.find(place.getId()); place = placeFacade.find(place.getId());
user = eventUserFacade.find(user.getId()); user = eventUserFacade.find(user.getId());
boolean ret = false; boolean ret = false;
// when admin click's place, he reserves it -> just ignore it // when admin click's place, he reserves it -> just ignore it
if (!place.isTaken() || (permbean.hasPermission(MapPermission.MANAGE_OTHERS) && permbean.getCurrentUser().equals(place.getCurrentUser()) )) { if (!place.isTaken() || (permbean.hasPermission(MapPermission.MANAGE_OTHERS) && permbean.getCurrentUser().equals(place.getCurrentUser()))) {
if (place.isBuyable() || permbean.hasPermission(MapPermission.MANAGE_OTHERS)) { if (place.isBuyable() || permbean.hasPermission(MapPermission.MANAGE_OTHERS)) {
if(!place.isBuyable()) { if (!place.isBuyable()) {
place.setBuyable(true); place.setBuyable(true);
} }
place.setCurrentUser(user); place.setCurrentUser(user);
place.setReleaseTime(Calendar.getInstance()); place.setReleaseTime(Calendar.getInstance());
place.getReleaseTime().add(Calendar.MINUTE, RESERVE_MINUTES); place.getReleaseTime().add(Calendar.MINUTE, RESERVE_MINUTES);
...@@ -249,7 +249,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -249,7 +249,7 @@ public class PlaceBean implements PlaceBeanLocal {
// } // }
// logger.debug("timeouting places"); // logger.debug("timeouting places");
// placeFacade.releasePlaces(permbean.getCurrentUser()); // placeFacade.releasePlaces(permbean.getCurrentUser());
// } // }
@Override @Override
@RolesAllowed({ MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS }) @RolesAllowed({ MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS })
public PlaceGroup buySelectedPlaces(EventUser user) throws BortalCatchableException { public PlaceGroup buySelectedPlaces(EventUser user) throws BortalCatchableException {
...@@ -283,7 +283,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -283,7 +283,7 @@ public class PlaceBean implements PlaceBeanLocal {
} }
// PlaceGroup pg = pgbean.createPlaceGroup(user); // PlaceGroup pg = pgbean.createPlaceGroup(user);
if (!createAccountevents) if (createAccountevents)
{ {
BigDecimal totalprice = addAndCalcPrice(user, null); BigDecimal totalprice = addAndCalcPrice(user, null);
BigDecimal balance = user.getAccountBalance(); BigDecimal balance = user.getAccountBalance();
...@@ -553,7 +553,8 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -553,7 +553,8 @@ public class PlaceBean implements PlaceBeanLocal {
PDF pdf = new PDF(outputStream); PDF pdf = new PDF(outputStream);
pdf.setTitle("Place"); pdf.setTitle("Place");
float pointInMillim = (25.4f / 72.0f); // 1 point is 1/72 inches. 1 inch = 25.4mm float pointInMillim = (25.4f / 72.0f); // 1 point is 1/72 inches. 1 inch
// = 25.4mm
float pagex = width / pointInMillim; float pagex = width / pointInMillim;
float pagey = height / pointInMillim; float pagey = height / pointInMillim;
...@@ -572,7 +573,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -572,7 +573,7 @@ public class PlaceBean implements PlaceBeanLocal {
double currentX = 42; double currentX = 42;
// nick // nick
if (place.getPlaceReserver() != null && place.getPlaceReserver().getUser() != null) { if (place.getPlaceReserver() != null && place.getPlaceReserver().getUser() != null) {
font = new com.pdfjet.Font(pdf, CoreFont.HELVETICA); font = new com.pdfjet.Font(pdf, CoreFont.HELVETICA);
font.setSize(font2); font.setSize(font2);
...@@ -584,7 +585,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -584,7 +585,7 @@ public class PlaceBean implements PlaceBeanLocal {
textLine.drawOn(page); textLine.drawOn(page);
} }
// place hex code // place hex code
font = new com.pdfjet.Font(pdf, CoreFont.HELVETICA); font = new com.pdfjet.Font(pdf, CoreFont.HELVETICA);
font.setSize(font2); font.setSize(font2);
......
...@@ -77,7 +77,8 @@ public class UserBean implements UserBeanLocal { ...@@ -77,7 +77,8 @@ public class UserBean implements UserBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(UserBean.class); private static final Logger logger = LoggerFactory.getLogger(UserBean.class);
/** /**
* Java EE container injektoi tämän luokkamuuttujan luokan luonnin yhteydessä. * Java EE container injektoi tämän luokkamuuttujan luokan luonnin
* yhteydessä.
*/ */
@EJB @EJB
private UserFacade userFacade; private UserFacade userFacade;
...@@ -167,8 +168,9 @@ public class UserBean implements UserBeanLocal { ...@@ -167,8 +168,9 @@ public class UserBean implements UserBeanLocal {
// private EventUser currentEventuser; // private EventUser currentEventuser;
// private ArrayList<Role> currentEventuserRoles; // private ArrayList<Role> currentEventuserRoles;
// HUOMHUOM! Älä määrittele tätä UserBeanLocal interfacelle. // HUOMHUOM! Älä määrittele tätä UserBeanLocal interfacelle.
// Käytä Viewien puolelta findUsersRoles joka tarkistaa käyttäjän oikeudet ensin. // Käytä Viewien puolelta findUsersRoles joka tarkistaa käyttäjän oikeudet
// ensin.
public Set<Role> localFindUsersRoles(EventUser u) { public Set<Role> localFindUsersRoles(EventUser u) {
// if (currentEventuser != null && u.equals(currentEventuser)) { // if (currentEventuser != null && u.equals(currentEventuser)) {
// logger.debug("Returnin cached eventuserroles for user {}: {}", // logger.debug("Returnin cached eventuserroles for user {}: {}",
...@@ -275,7 +277,7 @@ public class UserBean implements UserBeanLocal { ...@@ -275,7 +277,7 @@ public class UserBean implements UserBeanLocal {
bimage = resized; bimage = resized;
} }
bimage = forceCrop(bimage); bimage = forceCrop(bimage);
ByteArrayOutputStream naamaout = new ByteArrayOutputStream(); ByteArrayOutputStream naamaout = new ByteArrayOutputStream();
...@@ -300,42 +302,42 @@ public class UserBean implements UserBeanLocal { ...@@ -300,42 +302,42 @@ public class UserBean implements UserBeanLocal {
return userimage; return userimage;
} }
private BufferedImage forceCrop(BufferedImage source) { private BufferedImage forceCrop(BufferedImage source) {
int x,y,xl,yl,xh,yh,xc,yc,x0,y0,x1,y1; int x, y, xl, yl, xh, yh, xc, yc, x0, y0, x1, y1;
double ar = CardPrintBean.ASPECT_RATIO; // x/y double ar = CardPrintBean.ASPECT_RATIO; // x/y
x=source.getWidth(); x = source.getWidth();
y=source.getHeight(); y = source.getHeight();
xc = x/2; xc = x / 2;
yc = y/2; yc = y / 2;
if(y >= x) { if (y >= x) {
xl = x; xl = x;
yl = (int)(y*((double)x/(double)y)); yl = (int) (y * ((double) x / (double) y));
} else { } else {
xl = (int)(x*((double)y/(double)x)); xl = (int) (x * ((double) y / (double) x));
yl = y; yl = y;
} }
xh = (int)((xl/2)*ar); xh = (int) ((xl / 2) * ar);
yh = yl/2; yh = yl / 2;
x0 = xc-xh; x0 = xc - xh;
x1 = xc+xh; x1 = xc + xh;
y0 = yc-yh; y0 = yc - yh;
y1 = yc+yh; y1 = yc + yh;
int cix = (int)(((double)xl)*ar); int cix = (int) (((double) xl) * ar);
int ciy = yl; int ciy = yl;
BufferedImage cropped = new BufferedImage(cix, ciy, source.getType()); BufferedImage cropped = new BufferedImage(cix, ciy, source.getType());
Graphics2D g = cropped.createGraphics(); Graphics2D g = cropped.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(source, 0, 0, cix, ciy, x0, y0, x1, y1, null); g.drawImage(source, 0, 0, cix, ciy, x0, y0, x1, y1, null);
g.dispose(); g.dispose();
return cropped; return cropped;
} }
...@@ -582,8 +584,10 @@ public class UserBean implements UserBeanLocal { ...@@ -582,8 +584,10 @@ public class UserBean implements UserBeanLocal {
public void removeGameIdById(Integer gameIdId) { public void removeGameIdById(Integer gameIdId) {
GameID gi = gameIDFacade.find(gameIdId); GameID gi = gameIDFacade.find(gameIdId);
// In the future we may edit other peoples' gameids, leave this as a placeholder for now // In the future we may edit other peoples' gameids, leave this as a
// At the very least it safeguards the situation if user gets another users gameid in somehow.. // placeholder for now
// At the very least it safeguards the situation if user gets another
// users gameid in somehow..
if (!permbean.isCurrentUser(gi.getEventUser())) { if (!permbean.isCurrentUser(gi.getEventUser())) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to remove GameID from another user: " + gi.getEventUser()); loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to remove GameID from another user: " + gi.getEventUser());
throw new EJBAccessException("Not enough rights to remove another users' GameIDs"); throw new EJBAccessException("Not enough rights to remove another users' GameIDs");
...@@ -684,19 +688,22 @@ public class UserBean implements UserBeanLocal { ...@@ -684,19 +688,22 @@ public class UserBean implements UserBeanLocal {
return userFacade.searchAllUsers(search); return userFacade.searchAllUsers(search);
} }
// @Override // @Override
// public SearchResult<User> getEventUsers(SearchQuery search) { // public SearchResult<User> getEventUsers(SearchQuery search) {
// if (search.getSearch() == null || search.getSearch().isEmpty()) // if (search.getSearch() == null || search.getSearch().isEmpty())
// { // {
// throw new RuntimeException("You should be using getThisEventsUsers if not searching globally..."); // throw new
// // return userFacade.searchEventUsers(search); // RuntimeException("You should be using getThisEventsUsers if not searching globally...");
// } else { // // return userFacade.searchEventUsers(search);
// return userFacade.searchAllUsers(search); // } else {
// } // return userFacade.searchAllUsers(search);
// }
// //
// } // }
// //
@Override @Override
@RolesAllowed(UserPermission.S_VIEW_ALL)
public SearchResult<EventUser> getThisEventsUsers(UserSearchQuery searchQuery) { public SearchResult<EventUser> getThisEventsUsers(UserSearchQuery searchQuery) {
SearchResult<EventUser> returnUsers = eventUserFacade.searchEventUsers(searchQuery); SearchResult<EventUser> returnUsers = eventUserFacade.searchEventUsers(searchQuery);
...@@ -748,6 +755,9 @@ public class UserBean implements UserBeanLocal { ...@@ -748,6 +755,9 @@ public class UserBean implements UserBeanLocal {
@Override @Override
public UserApproval setUserApproval(EventUser user, String approvalName, boolean approvalValue, String notes) { public UserApproval setUserApproval(EventUser user, String approvalName, boolean approvalValue, String notes) {
if (!permbean.getCurrentUser().equals(user) && permbean.hasPermission(UserPermission.MODIFY))
throw new EJBAccessException("Tried to set approval without permissions: " + approvalName + " to " + approvalValue + " with notes " + notes);
Approval approval = approvalFacade.findOrCreate(approvalName); Approval approval = approvalFacade.findOrCreate(approvalName);
UserApproval ret = userApprovalFacade.findOrCreateApproval(user, approval); UserApproval ret = userApprovalFacade.findOrCreateApproval(user, approval);
ret.setApprovalValue(approvalValue); ret.setApprovalValue(approvalValue);
...@@ -773,7 +783,12 @@ public class UserBean implements UserBeanLocal { ...@@ -773,7 +783,12 @@ public class UserBean implements UserBeanLocal {
@Override @Override
public User getUser(Integer id) { public User getUser(Integer id) {
return userFacade.find(id);
}
User ret = userFacade.find(id);
if (!permbean.getCurrentUser().getUser().equals(ret) && permbean.hasPermission(UserPermission.VIEW_ALL)) {
throw new EJBAccessException("Tried to fetch user with id " + id + " from database without sufficient permissions");
}
return ret;
}
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</ui:define> </ui:define>
<ui:define name="content"> <ui:define name="content">
<ui:fragment rendered="#{!inviteAcceptView.done}"> <ui:fragment rendered="#{!inviteAcceptView.done}">
<users:edit creating="true" commitaction="#{inviteAcceptView.createUser()}" commitvalue="#{i18n['user.create']}" /> <users:create creating="true" commitaction="#{inviteAcceptView.createUser()}" commitvalue="#{i18n['user.create']}" />
</ui:fragment> </ui:fragment>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!