class InviteOrganisationPermissionRules extends BasePermissionRules {

    @PermissionRule(value = "CREATE_APPLICATION_INVITES", description = "Lead applicant or collaborator can create invites for the specified application if the application is still editable")
    public boolean leadApplicantCanCreateApplicationInvitesIfApplicationEditable(InviteOrganisationResource inviteOrganisation, UserResource user) {
        // This would never happen, unless someone calls REST directly. The Web layer ensures that at least one invite is present.
        if (inviteOrganisation.getInviteResources().isEmpty()) {
            throw new ForbiddenActionException("Missing Invite Resource");
        }

        if (!allInviteApplicationIdsMatch(inviteOrganisation)) {
            throw new ForbiddenActionException("Not all invite application ids match");
        }

        if (isApplicationCollaboratorOrIsLeadApplicant(inviteOrganisation, user)) {
            // Get the application id from the first invite, as application id is same for all invites.
            long applicationId = inviteOrganisation.getInviteResources().get(0).getApplication();

            Application application = getApplication(applicationId);

            return checkCollaborationLevel(inviteOrganisation, applicationId) && applicationIsEditable(application);
        }
        return false;
    }

}