Package com.sparc.knappsack.forms

Examples of com.sparc.knappsack.forms.InvitationForm


    private InvitationForm invitationForm;
    private User user;

    @Before
    public void setup() {
        invitationForm = new InvitationForm();
        errors = new BeanPropertyBindingResult(invitationForm, "invitationForm");
        ReflectionTestUtils.setField(validator, "emailPattern", EMAIL_PATTERN);
        user = new User("test", "originalPassword", "test@test.com", "test", "test", new ArrayList<Role>());
    }
View Full Code Here


        return InvitationForm.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        InvitationForm invitationForm = (InvitationForm) target;
        invitationForm.setEmail(trimWhitespace(invitationForm.getEmail()));

        User user = userService.getUserFromSecurityContext();
        if (user == null || user.getActiveOrganization() == null) {
            errors.reject("invitationValidator.error.generic");
            return;
        }

        // Check if email is valid
        validateEmail(invitationForm.getEmail(), errors);

        if (errors.hasErrors()) {
            // No need to continue validating since the email is incorrect
            return;
        }

        // Validate organization user limit
        Set<String> emails = new HashSet<String>();
        emails.add(invitationForm.getEmail());
        boolean isValid = validateOrganizationUserLimit(emails, user.getActiveOrganization(), errors);
        if (!isValid) {
            return;
        }

        // Check if User Roles are valid
        if ((invitationForm.getOrganizationUserRole() == null || UserRole.ROLE_ORG_GUEST.equals(invitationForm.getOrganizationUserRole())) && invitationForm.getGroupUserRole() == null) {
            if (user.isActiveOrganizationAdmin()) {
                errors.reject("invitationValidator.userRole.both.empty");
            } else {
                errors.rejectValue(GROUP_USER_ROLE_FIELD, "invitationValidator.userRole.group.empty");
            }
        }

        User invitedUser = userService.getByEmail(invitationForm.getEmail());

        validateInvitationForOrganization(invitationForm, user, invitedUser, errors);
        validateInvitationForGroups(invitationForm, user, invitedUser, errors);

//        Domain domain = domainService.get(invitationForm.getDomainId());
View Full Code Here

    public String inviteUser(Model model, @RequestParam(value = "grp", required = false) Long groupId) {

        User user = userService.getUserFromSecurityContext();

        if (!model.containsAttribute("invitationForm")) {
            InvitationForm invitationForm = new InvitationForm();
            if (groupId != null && groupId > 0) {
                invitationForm.getGroupIds().add(groupId);
                invitationForm.setOrganizationUserRole(UserRole.ROLE_ORG_GUEST);
                model.addAttribute("isGroupInvite", true);
            }
            model.addAttribute("invitationForm", invitationForm);
        }
View Full Code Here

    @Test
    public void inviteUsersTest() {
        User user = getUserWithSecurityContext();
        setActiveOrganizationOnUser(user, getOrganization());
        InvitationForm form = new InvitationForm();
        form.setEmail("invitee@sparcedge.com");
        form.setOrganizationUserRole(UserRole.ROLE_ORG_USER);

        assertTrue(invitationControllerService.inviteUser(form, true));
        List<Invitation> invitations = invitationService.getByEmail("invitee@sparcedge.com");
        assertTrue(invitations.size() == 1);
    }
View Full Code Here

TOP

Related Classes of com.sparc.knappsack.forms.InvitationForm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.