use of com.willshex.blogwt.shared.api.datatype.Permission in project blogwt by billy1380.
the class DeletePostActionHandler method handle.
/* (non-Javadoc)
*
* @see
* com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
* gson.web.service.shared.Request,
* com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(DeletePostRequest input, DeletePostResponse output) throws Exception {
ApiValidator.request(input, DeletePostRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
List<Permission> permissions = new ArrayList<Permission>();
Permission postPermission = PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_POSTS);
permissions.add(postPermission);
UserValidator.authorisation(input.session.user, permissions, "input.session.user");
input.post = PostValidator.lookup(input.post, "input.post");
PostServiceProvider.provide().deletePost(input.post);
}
use of com.willshex.blogwt.shared.api.datatype.Permission in project blogwt by billy1380.
the class HeaderPart method addAdminNav.
private void addAdminNav(boolean login) {
boolean addAdmin = false, isAdmin = false;
if (login) {
Permission managePosts = PermissionHelper.create(PermissionHelper.MANAGE_POSTS);
Permission managePages = PermissionHelper.create(PermissionHelper.MANAGE_PAGES);
Permission managePermissions = PermissionHelper.create(PermissionHelper.MANAGE_PERMISSIONS);
Permission manageRoles = PermissionHelper.create(PermissionHelper.MANAGE_ROLES);
Permission manageUsers = PermissionHelper.create(PermissionHelper.MANAGE_USERS);
Permission manageResources = PermissionHelper.create(PermissionHelper.MANAGE_RESOURCES);
Permission manageMetaNotifications = PermissionHelper.create(PermissionHelper.MANAGE_NOTIFICATIONS);
if (SessionController.get().isAdmin()) {
addAdmin = true;
isAdmin = true;
elAdminDropdown.appendChild(elProperties);
} else {
elAdminDropdown.removeAllChildren();
}
if (isAdmin || SessionController.get().isAuthorised(managePosts)) {
addAdmin = true;
elAdminDropdown.appendChild(elPosts);
} else {
elPosts.removeFromParent();
}
if (isAdmin || SessionController.get().isAuthorised(managePages)) {
addAdmin = true;
elAdminDropdown.appendChild(elPages);
} else {
elPages.removeFromParent();
}
if (isAdmin || SessionController.get().isAuthorised(manageUsers)) {
addAdmin = true;
elAdminDropdown.appendChild(elUsers);
} else {
elUsers.removeFromParent();
}
if (isAdmin || SessionController.get().isAuthorised(manageRoles)) {
addAdmin = true;
elAdminDropdown.appendChild(elRoles);
} else {
elRoles.removeFromParent();
}
if (isAdmin || SessionController.get().isAuthorised(managePermissions)) {
addAdmin = true;
elAdminDropdown.appendChild(elPermissions);
} else {
elPermissions.removeFromParent();
}
if (isAdmin || SessionController.get().isAuthorised(manageResources)) {
addAdmin = true;
elAdminDropdown.appendChild(elResources);
} else {
elResources.removeFromParent();
}
if (isAdmin || SessionController.get().isAuthorised(manageMetaNotifications)) {
addAdmin = true;
elAdminDropdown.appendChild(elMetaNotifications);
} else {
elMetaNotifications.removeFromParent();
}
}
if (addAdmin) {
elNavLeft.appendChild(elAdmin);
ensureOpenables().put("blogwt_administration_menu_reserved_slug", elAdmin);
} else {
elAdmin.removeFromParent();
ensureOpenables().remove("blogwt_administration_menu_reserved_slug");
}
}
use of com.willshex.blogwt.shared.api.datatype.Permission in project blogwt by billy1380.
the class PermissionService method addPermission.
@Override
public Permission addPermission(Permission permission) {
if (permission.created == null) {
permission.created = new Date();
}
Key<Permission> key = provide().save().entity(permission).now();
permission.id = keyToId(key);
return permission;
}
use of com.willshex.blogwt.shared.api.datatype.Permission in project blogwt by billy1380.
the class UserService method addUser.
/* (non-Javadoc)
*
* @see com.willshex.blogwt.server.services.user.IUserService#addUser
* (com.willshex.blogwt.shared.api.datatypes.User) */
@Override
public User addUser(User user) {
if (user.created == null) {
user.added = user.created = new Date();
}
user.password = generatePassword(user.password);
if (user.roles != null) {
user.roleKeys = new ArrayList<Key<Role>>();
for (Role role : user.roles) {
user.roleKeys.add(Key.create(role));
}
}
if (user.permissions != null) {
user.permissionKeys = new ArrayList<Key<Permission>>();
for (Permission permission : user.permissions) {
user.permissionKeys.add(Key.create(permission));
}
}
Key<User> key = provide().save().entity(user).now();
user.id = keyToId(key);
SearchHelper.queueToIndex(getName(), user.id);
return user;
}
use of com.willshex.blogwt.shared.api.datatype.Permission in project blogwt by billy1380.
the class IsAuthorisedRequest method fromJson.
@Override
public void fromJson(JsonObject jsonObject) {
super.fromJson(jsonObject);
if (jsonObject.has("roles")) {
JsonElement jsonRoles = jsonObject.get("roles");
if (jsonRoles != null) {
roles = new ArrayList<Role>();
Role item = null;
for (int i = 0; i < jsonRoles.getAsJsonArray().size(); i++) {
if (jsonRoles.getAsJsonArray().get(i) != null) {
(item = new Role()).fromJson(jsonRoles.getAsJsonArray().get(i).getAsJsonObject());
roles.add(item);
}
}
}
}
if (jsonObject.has("permissions")) {
JsonElement jsonPermissions = jsonObject.get("permissions");
if (jsonPermissions != null) {
permissions = new ArrayList<Permission>();
Permission item = null;
for (int i = 0; i < jsonPermissions.getAsJsonArray().size(); i++) {
if (jsonPermissions.getAsJsonArray().get(i) != null) {
(item = new Permission()).fromJson(jsonPermissions.getAsJsonArray().get(i).getAsJsonObject());
permissions.add(item);
}
}
}
}
}
Aggregations