Esempio n. 1
0
    def _valid_request(self, user, prefix, group_id):
        group_repo = GroupRepository()
        group = group_repo.fetch(group_id)
        group_repo.close()

        if not group:
            print "Group doesn't exist."
            return False

        user_repo = UserRepository()
        member_list = user_repo.get_members_of_group(group_id)
        user_repo.close()

        if not any(member.id == user.id for member in member_list):
            print "User is not a member of the associated group."
            return False

        group_repo = GroupRepository()
        parent_group = group_repo.get_supergroup_of_group(group_id)
        group_repo.close()
        if not group_repo:
            print "Attempting to add membrer to the root."
            return False

        user_repo = UserRepository()
        parent_member_list = user_repo.get_members_of_group(parent_group.id)
        user_repo.close()
        if not any(member.id == user.id for member in parent_member_list):
            print "New user is not a member of the supergroup."
            return False

        return True
Esempio n. 2
0
    def _perform_request(self, user, prefix, group_id):
        group_repo = GroupRepository()
        parent = group_repo.get_supergroup_of_group(group_id)
        group_repo.close()

        user_repo = UserRepository()
        user_list = user_repo.find_users_with_email_prefix(user.id, parent.id, prefix)
        user_repo.close()

        formatted_names = [{"value": u.email} for u in user_list]

        return json.dumps(formatted_names)
Esempio n. 3
0
    def _valid_request(self, curr_user, name, values):
        # Malformed request
        if u"group_id" not in values or u"user_email" not in values:
            print "Malformed request detected."
            return False

        # Malformed request
        group_id = values[u"group_id"]
        new_user_email = values[u"user_email"]
        if not group_id or not new_user_email:
            print "Required data is missing."
            return False

        user_repo = UserRepository()
        member_list = user_repo.get_members_of_group(group_id)
        user_repo.close()
        if not any(member.id == curr_user.id for member in member_list):
            print "User is not a member of the associated group."
            return False

        group_repo = GroupRepository()
        parent_group = group_repo.get_supergroup_of_group(group_id)
        group_repo.close()
        if not group_repo:
            print "Cannot add member to the root group."
            return False

        user_repo = UserRepository()
        parent_member_list = user_repo.get_members_of_group(parent_group.id)
        user_repo.close()
        if not any(member.id == curr_user.id for member in parent_member_list):
            print "New user is not a member of the supergroup."
            return False

        # New user is already a member of the group
        new_user_repo = UserRepository()
        new_user = new_user_repo.get_user_by_email(new_user_email)
        new_user_repo.close()
        if not new_user:
            print "New user doesn't exist."
            return False

        if not new_user.groups:
            print "New user isn't a member of any groups."
            return False

        if group_id in new_user.groups:
            print "New user is already already a member of the group."
            return False

        group_repo = GroupRepository()
        group = group_repo.fetch(group_id)
        group_repo.close()
        if not group:
            print "Group doesn't exist"
            return False

        # 1 => Public
        if group.type == 1:
            print "Cannot add members to public groups"
            return False

        return True