Search in sources :

Example 1 with UserExistsException

use of org.activityinfo.legacy.shared.command.result.UserExistsException in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandler method execute.

@Override
public CommandResult execute(UpdateUserPermissions cmd, User executingUser) {
    LOGGER.info("UpdateUserPermissions: " + cmd);
    Database database = databaseDAO.findById(cmd.getDatabaseId());
    UserPermissionDTO dto = cmd.getModel();
    /*
         * First check that the current user has permission to add users to to
         * the queries
         */
    boolean isOwner = executingUser.getId() == database.getOwner().getId();
    UserPermission executingUserPermission = queryUserPermission(executingUser, database);
    LOGGER.info("executingUserPermission: isOwner: " + isOwner + ", executingUserPermissions: " + cmd);
    if (!isOwner) {
        verifyAuthority(cmd, executingUserPermission);
    }
    /* Database owner cannot be added */
    if (database.getOwner().getEmail().equalsIgnoreCase(cmd.getModel().getEmail())) {
        throw new UserExistsException();
    }
    User user = null;
    if (userDAO.doesUserExist(dto.getEmail())) {
        user = userDAO.findUserByEmail(dto.getEmail());
    }
    if (user == null) {
        user = createNewUser(executingUser, dto);
    }
    /*
         * Does the permission record exist ?
         */
    UserPermission perm = queryUserPermission(user, database);
    if (perm == null) {
        perm = new UserPermission(database, user);
        doUpdate(perm, dto, isOwner, executingUserPermission);
        permDAO.persist(perm);
    } else {
        // If the user is intending to add a new user, verify that this user doesn't already exist
        if (cmd.isNewUser() && perm.isAllowView()) {
            throw new UserExistsException();
        }
        doUpdate(perm, dto, isOwner, executingUserPermission);
    }
    return null;
}
Also used : UserExistsException(org.activityinfo.legacy.shared.command.result.UserExistsException) User(org.activityinfo.server.database.hibernate.entity.User) Database(org.activityinfo.server.database.hibernate.entity.Database) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 2 with UserExistsException

use of org.activityinfo.legacy.shared.command.result.UserExistsException in project activityinfo by bedatadriven.

the class DbUserEditorActions method showDialog.

private void showDialog(final UserForm form, final boolean newUser) {
    final FormDialogImpl dlg = new FormDialogImpl(form);
    dlg.setHeadingText(newUser ? I18N.CONSTANTS.newUser() : I18N.CONSTANTS.editUser());
    dlg.setWidth(400);
    dlg.setHeight(300);
    dlg.getCancelButton().addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent buttonEvent) {
            panel.setModified(false);
        }
    });
    final String host = Window.Location.getHostName();
    dlg.show(new FormDialogCallback() {

        @Override
        public void onValidated() {
            try {
                UpdateUserPermissions command = new UpdateUserPermissions(db, form.getUser(), host);
                command.setNewUser(newUser);
                dispatcher.execute(command, new AsyncCallback<VoidResult>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        if (caught instanceof UserExistsException) {
                            MessageBox.alert(I18N.CONSTANTS.userExistsTitle(), I18N.CONSTANTS.userExistsMessage(), null);
                        } else {
                            MessageBox.alert(I18N.CONSTANTS.serverError(), I18N.CONSTANTS.errorUnexpectedOccured(), null);
                        }
                    }

                    @Override
                    public void onSuccess(VoidResult result) {
                        loader.load();
                        panel.setModified(false);
                        dlg.hide();
                    }
                });
            } catch (FolderAssignmentException excp) {
                MessageBox.alert(I18N.CONSTANTS.noFolderAssignmentTitle(), excp.getMessage(), null);
            } catch (PermissionAssignmentException excp) {
                MessageBox.alert(I18N.CONSTANTS.permissionAssignmentErrorTitle(), excp.getMessage(), null);
            }
        }
    });
}
Also used : FormDialogImpl(org.activityinfo.ui.client.page.common.dialog.FormDialogImpl) FormDialogCallback(org.activityinfo.ui.client.page.common.dialog.FormDialogCallback) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) PermissionAssignmentException(org.activityinfo.ui.client.page.config.form.PermissionAssignmentException) UserExistsException(org.activityinfo.legacy.shared.command.result.UserExistsException) FolderAssignmentException(org.activityinfo.ui.client.page.config.form.FolderAssignmentException) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent)

Aggregations

UserExistsException (org.activityinfo.legacy.shared.command.result.UserExistsException)2 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)1 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)1 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)1 Database (org.activityinfo.server.database.hibernate.entity.Database)1 User (org.activityinfo.server.database.hibernate.entity.User)1 UserPermission (org.activityinfo.server.database.hibernate.entity.UserPermission)1 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)1 FormDialogImpl (org.activityinfo.ui.client.page.common.dialog.FormDialogImpl)1 FolderAssignmentException (org.activityinfo.ui.client.page.config.form.FolderAssignmentException)1 PermissionAssignmentException (org.activityinfo.ui.client.page.config.form.PermissionAssignmentException)1