Beispiel #1
0
    def map(user):
        # The map() function must be static, so we manually create a "cls"
        # variable instead of changing the function into a classmethod.
        cls = PopulateFirebaseAccountsOneOffJob

        if user.deleted:
            return

        gae_auth_id = gae_auth_services.get_auth_id_from_user_id(user.id)
        # NOTE: This committer ID is a legacy ACL-bypass that we no longer
        # depend on. Because it is obsolete, we do not want it to have a
        # Firebase account associated with it.
        if gae_auth_id == feconf.SYSTEM_COMMITTER_ID:
            yield (cls.SYSTEM_COMMITTER_ACK, user.id)
            return

        auth_id = firebase_auth_services.get_auth_id_from_user_id(user.id)
        if auth_id is not None:
            yield (cls.POPULATED_KEY, 1)
        else:
            user_is_super_admin = (user.email == feconf.ADMIN_EMAIL_ADDRESS)
            if user_is_super_admin:
                yield (cls.SUPER_ADMIN_ACK, user.id)

            # Split up users into different shards to help speed up the job.
            sharding_key = ID_HASHING_FUNCTION(user.id) % cls.NUM_SHARDS
            yield (sharding_key, (cls.strip_uid_prefix(user.id), user.id,
                                  user.email, user_is_super_admin))
    def test_associate_without_collision(self):
        firebase_auth_services.associate_auth_id_with_user_id(
            auth_domain.AuthIdUserIdPair('aid', 'uid'))

        self.assertEqual(
            firebase_auth_services.get_user_id_from_auth_id('aid'), 'uid')
        self.assertEqual(
            firebase_auth_services.get_auth_id_from_user_id('uid'), 'aid')
    def test_get_association_that_is_present(self):
        firebase_auth_services.associate_auth_id_with_user_id(
            auth_domain.AuthIdUserIdPair('aid', 'uid'))

        self.assertEqual(
            firebase_auth_services.get_user_id_from_auth_id('aid'), 'uid')
        self.assertEqual(
            firebase_auth_services.get_auth_id_from_user_id('uid'), 'aid')
    def assert_auth_mapping_does_not_exist(self, auth_assoc):
        """Asserts that the given auth association does not exist.

        Args:
            auth_assoc: AuthIdUserIdPair. The association to check.
        """
        auth_id, user_id = auth_assoc
        self.assertIsNone(
            firebase_auth_services.get_auth_id_from_user_id(user_id))
        self.assertIsNone(
            firebase_auth_services.get_user_id_from_auth_id(auth_id))
    def assert_auth_mapping_exists(self, auth_assoc):
        """Asserts that the given auth association exists.

        Args:
            auth_assoc: AuthIdUserIdPair. The association to check.
        """
        auth_id, user_id = auth_assoc
        self.assertEqual(
            firebase_auth_services.get_auth_id_from_user_id(user_id), auth_id)
        self.assertEqual(
            firebase_auth_services.get_user_id_from_auth_id(auth_id), user_id)
Beispiel #6
0
    def assert_firebase_assoc_does_not_exist(self, firebase_auth_id, user_id):
        """Asserts that the given user's Firebase association doesn't exist.

        Args:
            firebase_auth_id: str. The Firebase account ID of the user.
            user_id: str. The Oppia ID of the user.
        """
        self.assertIsNone(
            firebase_auth_services.get_auth_id_from_user_id(user_id))
        self.assertIsNone(
            firebase_auth_services.get_user_id_from_auth_id(firebase_auth_id))
Beispiel #7
0
    def assert_firebase_assoc_exists(self, firebase_auth_id, user_id):
        """Asserts that the given user's Firebase association exists.

        Args:
            user_id: str. The Oppia ID of the user.
            firebase_auth_id: str. The Firebase account ID of the user.
        """
        self.assertEqual(
            firebase_auth_services.get_auth_id_from_user_id(user_id),
            firebase_auth_id)
        self.assertEqual(
            firebase_auth_services.get_user_id_from_auth_id(firebase_auth_id),
            user_id)
Beispiel #8
0
    def map(user):
        if user.deleted:
            return

        gae_auth_id = gae_auth_services.get_auth_id_from_user_id(user.id)
        # NOTE: This committer ID is a legacy ACL-bypass that we no longer
        # depend on. Because it is obsolete, we do not want it to have a
        # Firebase account associated with it.
        if gae_auth_id == feconf.SYSTEM_COMMITTER_ID:
            yield (SYSTEM_COMMITTER_ACK, user.id)
            return

        auth_id = firebase_auth_services.get_auth_id_from_user_id(user.id)
        if auth_id is not None:
            yield (POPULATED_KEY, 1)
        else:
            # Split up users into different shards to help speed up the job.
            sharding_key = (ID_HASHING_FUNCTION(user.id) %
                            PopulateFirebaseAccountsOneOffJob.NUM_SHARDS)
            yield (sharding_key, (_strip_uid_prefix(user.id), user.id,
                                  user.email))
 def test_get_association_that_is_missing(self):
     self.assertIsNone(
         firebase_auth_services.get_user_id_from_auth_id('does_not_exist'))
     self.assertIsNone(
         firebase_auth_services.get_auth_id_from_user_id('does_not_exist'))