Пример #1
0
    def create_mozillians_profile(self, user_id, idp):
        # A new mozillians.org profile will be provisioned if there is not one,
        # we need the self-view of profile which mean a private scope
        # Because we are using OIDC proxy, we assume always ldap. This functionality
        # will be deprecated with the launch of DinoPark

        profile = idp.profile
        v2_profile_data = _dino_park_get_profile_by_userid(user_id)
        data = json.loads(v2_profile_data)
        # Escape the middleware
        first_name = data.get('first_name', {}).get('value')
        last_name = data.get('last_name', {}).get('value')
        full_name = ''
        if first_name and last_name:
            full_name = first_name + ' ' + last_name
        profile.full_name = full_name or 'Anonymous Mozillian'
        location = data.get('location_preference', {}).get('value')
        # TODO: Update this. It's wrong to create entries like this. We need to populate
        # the Country table and match the incoming location. It's only for M1 beta.
        if location:
            country, _ = Country.objects.get_or_create(name=location)
            profile.country = country
        timezone = data.get('timezone', {}).get('value')
        if timezone:
            profile.timezone = timezone
        profile.title = data.get('fun_title', {}).get('value', '')
        worker_type = data.get('worker_type', {}).get('value')
        if worker_type:
            profile.is_staff = True
        profile.auth0_user_id = user_id
        profile.save()
        if profile.is_staff:
            profile.auto_vouch()
Пример #2
0
    def test_bad_status_code(self, request_mock):
        mock_response = Mock()
        exception_error = requests.exceptions.HTTPError()
        mock_response.raise_for_status.side_effect = exception_error

        request_mock.return_value = mock_response
        request_mock.return_value.status_code = 503
        ok_(not _dino_park_get_profile_by_userid(user_id='dinos'))
    def test_bad_status_code(self, request_mock):
        mock_response = Mock()
        exception_error = requests.exceptions.HTTPError()
        mock_response.raise_for_status.side_effect = exception_error

        request_mock.return_value = mock_response
        request_mock.return_value.status_code = 503
        ok_(not _dino_park_get_profile_by_userid(user_id='dinos'))
Пример #4
0
 def test_return_username(self, request_mock):
     mock_response = Mock()
     mock_response.json.return_value = {
         "usernames": {
             "values":
             {
                 "mozilliansorg": 'DinoPark'
             }
         },
         "foo": "bar"
     }
     request_mock.return_value = mock_response
     eq_(_dino_park_get_profile_by_userid(user_id='dinos', return_username=True), 'DinoPark')
 def test_get_profile(self, request_mock):
     mock_response = Mock()
     profile = {
         "usernames": {
             "values": {
                 "mozilliansorg": 'DinoPark'
             }
         },
         "foo": "bar"
     }
     mock_response.json.return_value = profile
     request_mock.return_value = mock_response
     eq_(_dino_park_get_profile_by_userid(user_id='dinos'), profile)
Пример #6
0
    def get_username(self, claims):
        """This method is mostly useful when it is used in DinoPark.

        If we are creating a user and the Search Service already has a username,
        we will use that. Otherwise, we will get the username derived from username_algo.
        """
        username = super(MozilliansAuthBackend, self).get_username(claims)

        if switch_is_active('dino-park-autologin'):
            auth0_user_id = claims.get('user_id') or claims.get('sub')
            v2_username = _dino_park_get_profile_by_userid(auth0_user_id, return_username=True)
            if v2_username and username != v2_username:
                return v2_username
        return username
Пример #7
0
    def get_username(self, claims):
        """This method is mostly useful when it is used in DinoPark.

        If we are creating a user and the Search Service already has a username,
        we will use that. Otherwise, we will get the username derived from username_algo.
        """
        username = super(MozilliansAuthBackend, self).get_username(claims)

        if switch_is_active('dino-park-autologin'):
            auth0_user_id = claims.get('user_id') or claims.get('sub')
            v2_username = _dino_park_get_profile_by_userid(auth0_user_id, return_username=True)
            if v2_username and username != v2_username:
                return v2_username
        return username
Пример #8
0
    def create_mozillians_profile(self, user_id, idp):
        # A new mozillians.org profile will be provisioned if there is not one,
        # we need the self-view of profile which mean a private scope
        # Because we are using OIDC proxy, we assume always ldap. This functionality
        # will be deprecated with the launch of DinoPark

        profile = idp.profile
        v2_profile_data = _dino_park_get_profile_by_userid(user_id)
        if not v2_profile_data:
            full_name = 'Anonymous Mozillian'
        else:
            try:
                data = json.loads(v2_profile_data)
            except (TypeError, ValueError):
                data = v2_profile_data
            # Escape the middleware
            first_name = data.get('first_name', {}).get('value')
            last_name = data.get('last_name', {}).get('value')
            full_name = first_name + ' ' + last_name
            # TODO: Update this. It's wrong to create entries like this. We need to populate
            # the Country table and match the incoming location. It's only for M1 beta.
            location = data.get('location_preference', {}).get('value')
            if location:
                country, _ = Country.objects.get_or_create(name=location)
                profile.country = country
            timezone = data.get('timezone', {}).get('value')
            if timezone:
                profile.timezone = timezone
            profile.title = data.get('fun_title', {}).get('value', '')
            is_staff = data.get('staff_information', {}).get('staff', {}).get('value')
            if is_staff:
                profile.is_staff = is_staff
        profile.full_name = full_name
        profile.auth0_user_id = user_id
        profile.save()
        if profile.is_staff:
            profile.auto_vouch()
Пример #9
0
 def test_no_user_id(self):
     ok_(not _dino_park_get_profile_by_userid(user_id=''))
 def test_no_user_id(self):
     ok_(not _dino_park_get_profile_by_userid(user_id=''))