Search in sources :

Example 1 with Role

use of com.willshex.blogwt.shared.api.datatype.Role 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;
}
Also used : Role(com.willshex.blogwt.shared.api.datatype.Role) User(com.willshex.blogwt.shared.api.datatype.User) Permission(com.willshex.blogwt.shared.api.datatype.Permission) Date(java.util.Date) Key(com.googlecode.objectify.Key)

Example 2 with Role

use of com.willshex.blogwt.shared.api.datatype.Role 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);
                }
            }
        }
    }
}
Also used : Role(com.willshex.blogwt.shared.api.datatype.Role) JsonElement(com.google.gson.JsonElement) Permission(com.willshex.blogwt.shared.api.datatype.Permission)

Example 3 with Role

use of com.willshex.blogwt.shared.api.datatype.Role in project blogwt by billy1380.

the class UsersPage method createColumns.

/**
 * create columns
 */
private void createColumns() {
    Column<User, String> avatar = new Column<User, String>(UiHelper.IMAGE_PROTOTYPE) {

        @Override
        public String getValue(User object) {
            return object.avatar + "?s=" + UserHelper.AVATAR_HEADER_SIZE + "&default=retro";
        }
    };
    tblUsers.setColumnWidth(avatar, 20.0, Unit.PX);
    TextColumn<User> username = new TextColumn<User>() {

        @Override
        public String getValue(User object) {
            return object.username;
        }
    };
    TextColumn<User> name = new TextColumn<User>() {

        @Override
        public String getValue(User object) {
            return UserHelper.name(object);
        }
    };
    Column<User, SafeHtml> email = new Column<User, SafeHtml>(UiHelper.SAFE_HTML_PROTOTYPE) {

        @Override
        public SafeHtml getValue(User object) {
            return UsersPageTemplates.INSTANCE.emailLink(object.email, UserHelper.emailDescription(object));
        }
    };
    TextColumn<User> lastLoggedIn = new TextColumn<User>() {

        @Override
        public String getValue(User object) {
            return DateTimeHelper.ago(object.lastLoggedIn);
        }
    };
    Column<User, SafeHtml> edit = new Column<User, SafeHtml>(UiHelper.SAFE_HTML_PROTOTYPE) {

        @Override
        public SafeHtml getValue(User object) {
            return UiHelper.TEMPLATES.xsEdit(PageTypeHelper.asHref(PageType.ChangeDetailsPageType, "id", object.id.toString()));
        }
    };
    tblUsers.setColumnWidth(edit, 1.0, Unit.PX);
    Column<User, String> suspend = new Column<User, String>(UiHelper.ACTION_PROTOTYPE) {

        @Override
        public String getValue(User object) {
            return UserHelper.isSuspended(object) ? "unsuspend" : "suspend";
        }
    };
    suspend.setFieldUpdater(new FieldUpdater<User, String>() {

        @Override
        public void update(int index, User object, String value) {
            boolean suspended = UserHelper.isSuspended(object);
            if (suspended) {
                UserController.get().unsuspendUser(object);
            } else {
                if (Window.confirm("Are you sure you want to suspend " + object.username + "'s account indefinitely?")) {
                    UserController.get().suspendUser(object);
                }
            }
        }
    });
    tblUsers.setColumnWidth(suspend, 1.0, Unit.PX);
    Column<User, String> admin = new Column<User, String>(UiHelper.ACTION_PROTOTYPE) {

        @Override
        public String getValue(User object) {
            return "admin";
        }
    };
    final Role adminRole = RoleHelper.createFullAdmin();
    admin.setFieldUpdater(new FieldUpdater<User, String>() {

        @Override
        public void update(int index, User object, String value) {
            if (Window.confirm("Are you sure you want to make " + object.username + " a " + adminRole.name + "?")) {
                UserController.get().assignUserRoles(object, adminRole);
            }
        }
    });
    tblUsers.setColumnWidth(admin, 1.0, Unit.PX);
    tblUsers.addColumn(avatar);
    tblUsers.addColumn(username, "Username");
    tblUsers.addColumn(name, "Name");
    tblUsers.addColumn(email, "E-mail");
    tblUsers.addColumn(lastLoggedIn, "Last seen");
    tblUsers.addColumn(edit);
    tblUsers.addColumn(admin);
    tblUsers.addColumn(suspend);
}
Also used : Role(com.willshex.blogwt.shared.api.datatype.Role) User(com.willshex.blogwt.shared.api.datatype.User) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 4 with Role

use of com.willshex.blogwt.shared.api.datatype.Role in project blogwt by billy1380.

the class ChangeUserAccessRequest method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("user")) {
        JsonElement jsonUser = jsonObject.get("user");
        if (jsonUser != null) {
            user = new User();
            user.fromJson(jsonUser.getAsJsonObject());
        }
    }
    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);
                }
            }
        }
    }
    if (jsonObject.has("revoke")) {
        JsonElement jsonRevoke = jsonObject.get("revoke");
        if (jsonRevoke != null) {
            revoke = Boolean.valueOf(jsonRevoke.getAsBoolean());
        }
    }
    if (jsonObject.has("suspend")) {
        JsonElement jsonSuspend = jsonObject.get("suspend");
        if (jsonSuspend != null) {
            suspend = Boolean.valueOf(jsonSuspend.getAsBoolean());
        }
    }
    if (jsonObject.has("suspendUntil")) {
        JsonElement jsonSuspendUntil = jsonObject.get("suspendUntil");
        if (jsonSuspendUntil != null) {
            suspendUntil = new Date(jsonSuspendUntil.getAsLong());
        }
    }
}
Also used : Role(com.willshex.blogwt.shared.api.datatype.Role) User(com.willshex.blogwt.shared.api.datatype.User) JsonElement(com.google.gson.JsonElement) Permission(com.willshex.blogwt.shared.api.datatype.Permission) Date(java.util.Date)

Example 5 with Role

use of com.willshex.blogwt.shared.api.datatype.Role in project blogwt by billy1380.

the class GetRolesAndPermissionsResponse 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);
                }
            }
        }
    }
}
Also used : Role(com.willshex.blogwt.shared.api.datatype.Role) JsonElement(com.google.gson.JsonElement) Permission(com.willshex.blogwt.shared.api.datatype.Permission)

Aggregations

Role (com.willshex.blogwt.shared.api.datatype.Role)12 Permission (com.willshex.blogwt.shared.api.datatype.Permission)8 JsonElement (com.google.gson.JsonElement)4 User (com.willshex.blogwt.shared.api.datatype.User)4 Date (java.util.Date)3 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 Document (com.google.appengine.api.search.Document)1 ScoredDocument (com.google.appengine.api.search.ScoredDocument)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 Column (com.google.gwt.user.cellview.client.Column)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1 Key (com.googlecode.objectify.Key)1 GetPostsActionHandler (com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler)1 ISearch (com.willshex.blogwt.server.service.search.ISearch)1 Pager (com.willshex.blogwt.shared.api.Pager)1 SortDirectionType (com.willshex.blogwt.shared.api.SortDirectionType)1 GetPostsRequest (com.willshex.blogwt.shared.api.blog.call.GetPostsRequest)1