use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.
the class WorkspaceForumRESTService method updateArea.
@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateArea(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId, ForumAreaRESTModel restModel) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
}
ForumArea forumArea = forumController.getForumArea(areaId);
if (forumArea != null) {
if (!(forumArea instanceof WorkspaceForumArea)) {
logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
return Response.status(Status.NOT_FOUND).build();
}
if (!workspaceEntity.getId().equals(((WorkspaceForumArea) forumArea).getWorkspace())) {
return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceForumArea %d does not belong to workspace entity %d", forumArea.getId(), workspaceEntity.getId())).build();
}
if (sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_UPDATEWORKSPACEFORUM, workspaceEntity)) {
forumController.updateForumAreaName(forumArea, restModel.getName());
forumController.updateForumAreaDescription(forumArea, restModel.getDescription());
return Response.noContent().build();
} else {
return Response.status(Status.FORBIDDEN).build();
}
} else {
return Response.status(Status.NOT_FOUND).build();
}
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.
the class ForumController method listLatestForumThreadsFromWorkspace.
public List<ForumThread> listLatestForumThreadsFromWorkspace(WorkspaceEntity workspaceEntity, Integer firstResult, Integer maxResults) {
List<WorkspaceForumArea> workspaceForums = listWorkspaceForumAreas(workspaceEntity);
List<ForumArea> forumAreas = new ArrayList<ForumArea>();
// TODO: This could use some optimization
for (WorkspaceForumArea wf : workspaceForums) {
forumAreas.add(wf);
}
List<ForumThread> threads;
if (!forumAreas.isEmpty())
threads = forumThreadDAO.listLatestOrdered(forumAreas, firstResult, maxResults);
else
threads = new ArrayList<ForumThread>();
return threads;
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.
the class ForumPermissionResolver method hasPermission.
@Override
public boolean hasPermission(String permission, ContextReference contextReference, User user) {
ForumArea forumArea = getForumArea(contextReference);
Permission perm = permissionDAO.findByName(permission);
UserEntity userEntity = getUserEntity(user);
if (forumArea == null) {
return false;
}
RoleEntity userRole;
// TODO: typecasts
if (forumArea instanceof WorkspaceForumArea) {
WorkspaceForumArea workspaceForum = (WorkspaceForumArea) forumArea;
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceForum.getWorkspace());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
if (workspaceUserEntity != null) {
userRole = workspaceUserEntity.getWorkspaceUserRole();
if (resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm) || hasEveryonePermission(permission, forumArea) || userEntity.getId().equals(forumArea.getOwner()))
return true;
}
}
EnvironmentUser environmentUser = environmentUserDAO.findByUserAndArchived(userEntity, Boolean.FALSE);
userRole = environmentUser.getRole();
boolean isOwner = userEntity != null ? userEntity.getId().equals(forumArea.getOwner()) : false;
return resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm) || hasEveryonePermission(permission, forumArea) || isOwner;
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.
the class ForumRESTService method updateThread.
@PUT
@Path("/areas/{AREAID}/threads/{THREADID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateThread(@PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId, ForumThreadRESTModel updThread) {
ForumThread forumThread = forumController.getForumThread(threadId);
if (forumThread == null) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found").build();
}
ForumArea forumArea = forumController.getForumArea(areaId);
if (forumArea == null) {
return Response.status(Status.NOT_FOUND).entity("Forum area not found").build();
}
if (!(forumArea instanceof EnvironmentForumArea)) {
logger.severe(String.format("Trying to update non environment forum thread (%d) from environment endpoint", forumThread.getId()));
return Response.status(Status.BAD_REQUEST).build();
}
if (!forumArea.getId().equals(forumThread.getForumArea().getId())) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found from the specified area").build();
}
if (!forumThread.getId().equals(threadId)) {
return Response.status(Status.BAD_REQUEST).build();
}
if (sessionController.hasPermission(MuikkuPermissions.OWNER, forumThread) || sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_EDIT_ENVIRONMENT_MESSAGES)) {
// User needs permission to change the value of these parameters
if (!forumThread.getSticky().equals(updThread.getSticky()) || !forumThread.getLocked().equals(updThread.getLocked())) {
if (!sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_LOCK_OR_STICKIFY_MESSAGES))
return Response.status(Status.BAD_REQUEST).build();
}
forumController.updateForumThread(forumThread, updThread.getTitle(), updThread.getMessage(), updThread.getSticky(), updThread.getLocked());
long numReplies = forumController.getThreadReplyCount(forumThread);
ForumThreadRESTModel result = new ForumThreadRESTModel(forumThread.getId(), forumThread.getTitle(), forumThread.getMessage(), forumThread.getCreator(), forumThread.getCreated(), forumThread.getForumArea().getId(), forumThread.getSticky(), forumThread.getLocked(), forumThread.getUpdated(), numReplies, forumThread.getLastModified());
return Response.ok(result).build();
} else {
return Response.status(Status.FORBIDDEN).build();
}
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.
the class ForumRESTService method listReplies.
@GET
@Path("/areas/{AREAID}/threads/{THREADID}/replies")
@RESTPermit(handling = Handling.INLINE)
public Response listReplies(@PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
try {
ForumArea forumArea = forumController.getForumArea(areaId);
if (forumArea == null) {
return Response.status(Status.NOT_FOUND).entity("Forum area not found").build();
}
ForumThread forumThread = forumController.getForumThread(threadId);
if (forumThread == null) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found").build();
}
if (!(forumArea instanceof EnvironmentForumArea)) {
logger.severe(String.format("Trying to create new thread to non environment area (%d) from environment endpoint", forumArea.getId()));
return Response.status(Status.BAD_REQUEST).build();
}
if (sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_READ_ENVIRONMENT_MESSAGES)) {
if (!forumArea.getId().equals(forumThread.getForumArea().getId())) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found from the specified area").build();
}
List<ForumThreadReply> replies = forumController.listForumThreadReplies(forumThread, firstResult, maxResults);
return Response.ok(createRestModel(replies.toArray(new ForumThreadReply[0]))).build();
} else
return Response.status(Status.FORBIDDEN).build();
} catch (Exception e) {
logger.log(Level.SEVERE, "Listing forum thread replies failed", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
Aggregations