예제 #1
0
    def get(org_id):
        """Retrieve the set of members for the given org."""
        try:

            status = request.args.get('status').upper() if request.args.get(
                'status') else None
            roles = request.args.get('roles').upper() if request.args.get(
                'roles') else None

            members = MembershipService.get_members_for_org(
                org_id,
                status=status,
                membership_roles=roles,
                token_info=g.jwt_oidc_token_info)
            if members:
                response, status = {'members': MembershipSchema(exclude=['org']).dump(members, many=True)}, \
                                   http_status.HTTP_200_OK
            else:
                response, status = {}, \
                                   http_status.HTTP_200_OK

        except BusinessException as exception:
            response, status = {
                'code': exception.code,
                'message': exception.message
            }, exception.status_code

        return response, status
예제 #2
0
def test_reset(session, auth_mock):  # pylint: disable=unused-argument
    """Assert that can be reset data by the provided token."""
    user_with_token = TestUserInfo.user_tester
    user_with_token['keycloak_guid'] = TestJwtClaims.tester_role['sub']
    user = factory_user_model(user_info=user_with_token)
    org = factory_org_model(user_id=user.id)
    factory_membership_model(user.id, org.id)
    entity = factory_entity_model(user_id=user.id)

    ResetDataService.reset(TestJwtClaims.tester_role)

    with pytest.raises(BusinessException) as exception:
        UserService.find_by_jwt_token(user_with_token)
    assert exception.value.code == Error.DATA_NOT_FOUND.name

    found_org = OrgService.find_by_org_id(org.id)
    assert found_org is None

    found_entity = EntityService.find_by_entity_id(entity.id)
    assert found_entity is not None
    dictionary = found_entity.as_dict()
    assert dictionary['business_identifier'] == TestEntityInfo.entity1[
        'businessIdentifier']
    assert not dictionary['pass_code_claimed']

    found_memeber = MembershipService.get_members_for_org(org.id)
    assert found_memeber is None
예제 #3
0
파일: org.py 프로젝트: jeznorth/sbc-auth
    def get(org_id):
        """Retrieve the set of members for the given org."""
        try:

            status = request.args.get('status')
            roles = request.args.get('roles')

            # Require ADMIN or higher for anything other than Active Members list
            if status == Status.ACTIVE.name:
                allowed_roles = CLIENT_AUTH_ROLES
            else:
                allowed_roles = CLIENT_ADMIN_ROLES

            members = MembershipService.get_members_for_org(
                org_id,
                status=status,
                membership_roles=roles,
                token_info=g.jwt_oidc_token_info,
                allowed_roles=(*allowed_roles, STAFF))
            if members:
                response, status = {'members': MembershipSchema(exclude=['org']).dump(members, many=True)}, \
                                   http_status.HTTP_200_OK
            else:
                response, status = {}, \
                                   http_status.HTTP_200_OK

        except BusinessException as exception:
            response, status = {
                'code': exception.code,
                'message': exception.message
            }, exception.status_code

        return response, status
예제 #4
0
def test_accept_invitation(session, auth_mock, keycloak_mock, monkeypatch):  # pylint:disable=unused-argument
    """Accept the invitation and add membership from the invitation to the org."""
    with patch.object(InvitationService, 'send_invitation', return_value=None):
        with patch.object(auth, 'check_auth', return_value=True):
            with patch.object(InvitationService,
                              'notify_admin',
                              return_value=None):
                user_with_token = TestUserInfo.user_test
                user_with_token[
                    'keycloak_guid'] = TestJwtClaims.public_user_role['sub']
                user = factory_user_model(user_with_token)
                patch_token_info({'sub': user.keycloak_guid}, monkeypatch)

                org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id)
                org_dictionary = org.as_dict()
                invitation_info = factory_invitation(org_dictionary['id'])
                user_with_token_invitee = TestUserInfo.user1
                user_with_token_invitee[
                    'keycloak_guid'] = TestJwtClaims.edit_role_2['sub']
                user_invitee = factory_user_model(user_with_token_invitee)
                new_invitation = InvitationService.create_invitation(
                    invitation_info, User(user_invitee), '')
                new_invitation_dict = new_invitation.as_dict()
                InvitationService.accept_invitation(new_invitation_dict['id'],
                                                    User(user_invitee), '')
                patch_token_info(TestJwtClaims.public_user_role, monkeypatch)
                members = MembershipService.get_members_for_org(
                    org_dictionary['id'], 'PENDING_APPROVAL')
                assert members
                assert len(members) == 1
예제 #5
0
def test_accept_invitation_for_govm(session, auth_mock, keycloak_mock):  # pylint:disable=unused-argument
    """Accept the invitation and add membership from the invitation to the org."""
    with patch.object(InvitationService, 'send_invitation', return_value=None):
        with patch.object(auth, 'check_auth', return_value=True):
            with patch.object(InvitationService,
                              'notify_admin',
                              return_value=None):
                user_with_token = TestUserInfo.user_staff_admin
                user_with_token[
                    'keycloak_guid'] = TestJwtClaims.public_user_role['sub']
                user = factory_user_model(user_with_token)
                org = OrgService.create_org(
                    TestOrgInfo.org_govm,
                    user_id=user.id,
                    token_info=TestJwtClaims.staff_admin_role)
                org_dictionary = org.as_dict()
                invitation_info = factory_invitation(org_dictionary['id'])
                user_with_token_invitee = TestUserInfo.user1
                user_with_token_invitee[
                    'keycloak_guid'] = TestJwtClaims.edit_role_2['sub']
                user_invitee = factory_user_model(user_with_token_invitee)
                new_invitation = InvitationService.create_invitation(
                    invitation_info, User(user_invitee), {}, '')
                new_invitation_dict = new_invitation.as_dict()
                InvitationService.accept_invitation(new_invitation_dict['id'],
                                                    User(user_invitee), '')
                members = MembershipService.get_members_for_org(
                    org_dictionary['id'],
                    'ACTIVE',
                    token_info=TestJwtClaims.staff_admin_role)
                assert members
                assert len(members) == 1, 'user gets active membership'
예제 #6
0
def test_get_members(session, keycloak_mock):  # pylint:disable=unused-argument
    """Assert that members for an org can be retrieved."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.public_user_role['sub']
    user = factory_user_model(user_info=user_with_token)
    org = OrgService.create_org(TestOrgInfo.org1, user.id)
    org_dictionary = org.as_dict()

    response = MembershipService.get_members_for_org(org_dictionary['id'],
                                                     status='ACTIVE',
                                                     token_info=TestJwtClaims.public_user_role)
    assert response
    assert len(response) == 1
    assert response[0].membership_type_code == 'OWNER'
예제 #7
0
def test_delete_org_with_members(session, auth_mock, keycloak_mock, monkeypatch):  # pylint:disable=unused-argument
    """Assert that an org can be deleted."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.public_user_role['sub']
    user = factory_user_model(user_info=user_with_token)

    patch_token_info({'sub': user.keycloak_guid}, monkeypatch)
    org = OrgService.create_org(TestOrgInfo.org1, user.id)
    user2 = factory_user_model(user_info=TestUserInfo.user2)
    factory_membership_model(user2.id, org._model.id, member_type='COORDINATOR')
    user3 = factory_user_model(user_info=TestUserInfo.user3)
    factory_membership_model(user3.id, org._model.id, member_type='ADMIN')

    patch_token_info(TestJwtClaims.public_user_role, monkeypatch)
    patch_pay_account_delete(monkeypatch)
    org_id = org.as_dict()['id']

    OrgService.delete_org(org_id)
    assert len(MembershipService.get_members_for_org(org_id)) == 0
예제 #8
0
def test_accept_invitation_for_govm(session, auth_mock, keycloak_mock,
                                    monkeypatch):  # pylint:disable=unused-argument
    """Accept the invitation and add membership from the invitation to the org."""
    with patch.object(InvitationService, 'send_invitation', return_value=None):
        with patch.object(auth, 'check_auth', return_value=True):
            with patch.object(InvitationService,
                              'notify_admin',
                              return_value=None):
                user_with_token = TestUserInfo.user_staff_admin
                user_with_token[
                    'keycloak_guid'] = TestJwtClaims.public_user_role['sub']
                user = factory_user_model(user_with_token)

                patch_token_info(TestJwtClaims.staff_admin_role, monkeypatch)

                org = OrgService.create_org(TestOrgInfo.org_govm,
                                            user_id=user.id)
                org_dictionary = org.as_dict()
                invitation_info = factory_invitation(org_dictionary['id'])
                user_with_token_invitee = TestUserInfo.user1
                user_with_token_invitee[
                    'keycloak_guid'] = TestJwtClaims.edit_role_2['sub']
                user_invitee = factory_user_model(user_with_token_invitee)
                new_invitation = InvitationService.create_invitation(
                    invitation_info, User(user_invitee), '')
                new_invitation_dict = new_invitation.as_dict()
                with patch.object(ActivityLogPublisher,
                                  'publish_activity',
                                  return_value=None) as mock_alp:
                    InvitationService.accept_invitation(
                        new_invitation_dict['id'], User(user_invitee), '')
                    mock_alp.assert_called_with(
                        Activity(
                            action=ActivityAction.APPROVE_TEAM_MEMBER.value,
                            org_id=ANY,
                            name=ANY,
                            id=ANY,
                            value=ANY))

                members = MembershipService.get_members_for_org(
                    org_dictionary['id'], 'ACTIVE')
                assert members
                assert len(members) == 1, 'user gets active membership'