use of fi.otavanopisto.muikku.plugins.announcer.dao.AnnouncementEnvironmentRestriction in project muikku by otavanopisto.
the class AnnouncerRESTService method listAnnouncements.
@GET
@Path("/announcements")
@RESTPermit(handling = Handling.INLINE)
public Response listAnnouncements(@QueryParam("hideEnvironmentAnnouncements") @DefaultValue("false") boolean hideEnvironmentAnnouncements, @QueryParam("hideWorkspaceAnnouncements") @DefaultValue("false") boolean hideWorkspaceAnnouncements, @QueryParam("hideGroupAnnouncements") @DefaultValue("false") boolean hideGroupAnnouncements, @QueryParam("workspaceEntityId") Long workspaceEntityId, @QueryParam("onlyMine") @DefaultValue("false") boolean onlyMine, @QueryParam("onlyEditable") @DefaultValue("false") boolean onlyEditable, @QueryParam("onlyArchived") @DefaultValue("false") boolean onlyArchived, @QueryParam("timeFrame") @DefaultValue("CURRENT") AnnouncementTimeFrame timeFrame) {
UserEntity currentUserEntity = sessionController.getLoggedUserEntity();
if (currentUserEntity == null) {
return Response.noContent().build();
}
List<Announcement> announcements = null;
AnnouncementEnvironmentRestriction environment = hideEnvironmentAnnouncements ? AnnouncementEnvironmentRestriction.NONE : sessionController.hasEnvironmentPermission(AnnouncerPermissions.LIST_ENVIRONMENT_GROUP_ANNOUNCEMENTS) ? AnnouncementEnvironmentRestriction.PUBLICANDGROUP : AnnouncementEnvironmentRestriction.PUBLIC;
if (workspaceEntityId == null) {
boolean includeGroups = !hideGroupAnnouncements;
boolean includeWorkspaces = !hideWorkspaceAnnouncements;
announcements = announcementController.listAnnouncements(includeGroups, includeWorkspaces, environment, timeFrame, currentUserEntity, onlyMine, onlyArchived);
} else {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Workspace entity with given ID not found").build();
}
if (!sessionController.hasWorkspacePermission(AnnouncerPermissions.LIST_WORKSPACE_ANNOUNCEMENTS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to list workspace announcements").build();
}
announcements = announcementController.listWorkspaceAnnouncements(Arrays.asList(workspaceEntity), environment, timeFrame, currentUserEntity, onlyMine, onlyArchived);
}
List<AnnouncementRESTModel> restModels = new ArrayList<>();
for (Announcement announcement : announcements) {
if (onlyEditable && !canEdit(announcement, currentUserEntity)) {
continue;
}
List<AnnouncementUserGroup> announcementUserGroups = announcementController.listAnnouncementUserGroups(announcement);
List<AnnouncementWorkspace> announcementWorkspaces = announcementController.listAnnouncementWorkspacesSortByUserFirst(announcement, currentUserEntity);
AnnouncementRESTModel restModel = createRESTModel(announcement, announcementUserGroups, announcementWorkspaces);
restModels.add(restModel);
}
return Response.ok(restModels).build();
}
use of fi.otavanopisto.muikku.plugins.announcer.dao.AnnouncementEnvironmentRestriction in project muikku by otavanopisto.
the class AnnouncementsViewBackingBean method init.
@RequestAction
public String init() {
UserEntity loggedUserEntity = sessionController.getLoggedUserEntity();
if (announcementId != null) {
currentAnnouncement = announcementController.findById(announcementId);
if (currentAnnouncement != null) {
List<AnnouncementWorkspace> announcementWorkspaces = announcementController.listAnnouncementWorkspacesSortByUserFirst(currentAnnouncement, loggedUserEntity);
currentAnnouncementWorkspaces = new ArrayList<WorkspaceBasicInfo>();
for (AnnouncementWorkspace aw : announcementWorkspaces) {
currentAnnouncementWorkspaces.add(workspaceRESTModelController.workspaceBasicInfo(aw.getWorkspaceEntityId()));
}
}
}
AnnouncementEnvironmentRestriction environment = sessionController.hasEnvironmentPermission(AnnouncerPermissions.LIST_ENVIRONMENT_GROUP_ANNOUNCEMENTS) ? AnnouncementEnvironmentRestriction.PUBLICANDGROUP : AnnouncementEnvironmentRestriction.PUBLIC;
AnnouncementTimeFrame timeFrame = AnnouncementTimeFrame.CURRENT;
activeAnnouncements = announcementController.listAnnouncements(true, true, environment, timeFrame, loggedUserEntity, false, false);
return null;
}
Aggregations