use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.
the class DiscussionBackingBean method init.
@RequestAction
public String init() {
if (!sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_ACCESSENVIRONMENTFORUM) || !sessionController.isActiveUser()) {
return NavigationRules.ACCESS_DENIED;
}
List<EnvironmentForumArea> forumAreas = forumController.listEnvironmentForums();
lockStickyPermission = sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_LOCK_OR_STICKIFY_MESSAGES);
showFullNamePermission = sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_SHOW_FULL_NAMES);
Map<Long, AreaPermission> areaPermissions = new HashMap<>();
for (EnvironmentForumArea forumArea : forumAreas) {
AreaPermission areaPermission = new AreaPermission(sessionController.hasPermission(ForumResourcePermissionCollection.FORUM_EDIT_ENVIRONMENT_MESSAGES, forumArea), sessionController.hasPermission(ForumResourcePermissionCollection.FORUM_DELETE_ENVIRONMENT_MESSAGES, forumArea));
areaPermissions.put(forumArea.getId(), areaPermission);
}
try {
this.areaPermissions = new ObjectMapper().writeValueAsString(areaPermissions);
} catch (JsonProcessingException e) {
return NavigationRules.INTERNAL_ERROR;
}
return null;
}
use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.
the class EvaluationMainViewBackingBean method init.
@RequestAction
public String init() {
UserEntity userEntity = sessionController.getLoggedUserEntity();
if (userEntity == null) {
return NavigationRules.ACCESS_DENIED;
}
WorkspaceEntity workspaceEntity = null;
if (workspaceEntityId != null) {
workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace == null) {
return NavigationRules.NOT_FOUND;
}
setWorkspaceName(workspace.getName());
if (!StringUtils.isEmpty(workspace.getNameExtension())) {
setWorkspaceName(getWorkspaceName() + String.format(" (%s)", workspace.getNameExtension()));
}
}
if (workspaceEntity == null) {
if (!sessionController.hasEnvironmentPermission(EvaluationResourcePermissionCollection.EVALUATION_VIEW_INDEX)) {
return NavigationRules.ACCESS_DENIED;
}
} else {
if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_VIEW_INDEX, workspaceEntity)) {
return NavigationRules.ACCESS_DENIED;
}
}
return null;
}
use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.
the class AbstractWorkspaceBackingBean method checkAccess.
@RequestAction
public String checkAccess() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
switch(workspaceEntity.getAccess()) {
case ANYONE:
break;
case LOGGED_IN:
if (!sessionController.isLoggedIn()) {
return navigationController.requireLogin();
}
break;
case MEMBERS_ONLY:
if (!sessionController.isLoggedIn()) {
return navigationController.requireLogin();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
if (workspaceUserEntity == null) {
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_MEMBERS_ONLY_WORKSPACE, workspaceEntity)) {
return NavigationRules.ACCESS_DENIED;
}
}
break;
}
return null;
}
use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.
the class WorkspaceFrontPageManagementBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_FRONTPAGE, workspaceEntity)) {
return NavigationRules.ACCESS_DENIED;
}
rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
workspaceEntityId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
try {
WorkspaceMaterial frontPage = workspaceMaterialController.ensureWorkspaceFrontPageExists(workspaceEntity);
contentNodes = Arrays.asList(workspaceMaterialController.createContentNode(frontPage));
} catch (WorkspaceMaterialException e) {
logger.log(Level.SEVERE, "Error loading materials", e);
return NavigationRules.INTERNAL_ERROR;
}
materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
return null;
}
use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.
the class ProfileBackingBean method init.
@RequestAction
@LoggedIn
public String init() {
UserEntity userEntity = sessionController.getLoggedUserEntity();
User user = userController.findUserByDataSourceAndIdentifier(sessionController.getLoggedUserSchoolDataSource(), sessionController.getLoggedUserIdentifier());
List<UserAddress> userAddresses = userController.listUserAddresses(user);
List<UserPhoneNumber> userPhoneNumbers = userController.listUserPhoneNumbers(user);
displayName = user.getNickName() == null ? user.getDisplayName() : String.format("%s %s (%s)", user.getNickName(), user.getLastName(), user.getStudyProgrammeName());
studyStartDate = user.getStudyStartDate();
studyTimeEnd = user.getStudyTimeEnd();
studyTimeLeftStr = "";
if (studyTimeEnd != null) {
OffsetDateTime now = OffsetDateTime.now();
Locale locale = sessionController.getLocale();
if (now.isBefore(studyTimeEnd)) {
long studyTimeLeftYears = now.until(studyTimeEnd, ChronoUnit.YEARS);
now = now.plusYears(studyTimeLeftYears);
if (studyTimeLeftYears > 0) {
studyTimeLeftStr += studyTimeLeftYears + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.y");
}
long studyTimeLeftMonths = now.until(studyTimeEnd, ChronoUnit.MONTHS);
now = now.plusMonths(studyTimeLeftMonths);
if (studyTimeLeftMonths > 0) {
if (studyTimeLeftStr.length() > 0)
studyTimeLeftStr += " ";
studyTimeLeftStr += studyTimeLeftMonths + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.m");
}
long studyTimeLeftDays = now.until(studyTimeEnd, ChronoUnit.DAYS);
now = now.plusDays(studyTimeLeftDays);
if (studyTimeLeftDays > 0) {
if (studyTimeLeftStr.length() > 0)
studyTimeLeftStr += " ";
studyTimeLeftStr += studyTimeLeftDays + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.d");
}
}
}
addresses = new ArrayList<>();
for (UserAddress userAddress : userAddresses) {
addresses.add(String.format("%s %s %s %s", userAddress.getStreet(), userAddress.getPostalCode(), userAddress.getCity(), userAddress.getCountry()));
}
phoneNumbers = new ArrayList<>();
for (UserPhoneNumber userPhoneNumber : userPhoneNumbers) {
phoneNumbers.add(userPhoneNumber.getNumber());
}
SchoolDataIdentifier identifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
emails = userEmailEntityController.getUserEmailAddresses(identifier);
return null;
}
Aggregations