def _sync_users(self, consultant_role_group, consultant_roles):
     for consultant_role in consultant_roles:
         exo_hub_code = dict(settings.CERTIFICATION_CH_HUB_NAME, ).get(
             consultant_role_group._type, '')
         if exo_hub_code:
             add_user_exo_hub.send(
                 sender=consultant_role.consultant.user.__class__,
                 user=consultant_role.consultant.user,
                 exo_hub_code=exo_hub_code)
         user_certified.send(
             sender=consultant_role.consultant.user.__class__,
             user=consultant_role.consultant.user,
             consultant_role=consultant_role)
    def test_adding_consultant_permissions(self):
        # PREPARE DATA
        consultant = FakeConsultantFactory.create(user__is_active=True)
        permissions_before = consultant.user.user_permissions.all().count()

        # DO ACTION
        add_user_exo_hub.send(
            sender=self.__class__,
            user=consultant.user,
            exo_hub_code=settings.EXO_HUB_CH_CONSULTANT,
        )

        # ASSERTS
        permissions_after = consultant.user.user_permissions.all().count()
        self.assertLess(permissions_before, permissions_after)
    def release_group_credential(self, user_from, project):
        ct = ContentType.objects.get_for_model(project)
        certification_group = CertificationGroup.objects.filter(
            content_type=ct, object_id=project.pk).first()

        users_roles = project.users_roles.filter(certifications__isnull=True)

        if certification_group:
            CertificationGroup.objects.release_group_credential(
                certification_group=certification_group,
                user_from=user_from,
                objects_list=users_roles)

        for user_role in users_roles:
            add_user_exo_hub.send(sender=user_role.__class__,
                                  user=user_role.user,
                                  exo_hub_code=settings.EXO_HUB_CH_ALUMNI)

        return certification_group
    def release_simple_credential(self, user_from, user_role):
        ct = ContentType.objects.get_for_model(user_role.project)
        certification_group = CertificationGroup.objects.filter(
            content_type=ct, object_id=user_role.project.pk).first()
        if certification_group:
            ct = ContentType.objects.get_for_model(user_role)
            credential, created = certification_group.credentials.get_or_create(
                user=user_role.user, content_type=ct, object_id=user_role.pk)
            if created:
                create_certification_credential.send(
                    sender=user_role.__class__,
                    certification_group=certification_group,
                    certification_credential=credential,
                    user_from=user_from)

        add_user_exo_hub.send(sender=user_role.__class__,
                              user=user_role.user,
                              exo_hub_code=settings.EXO_HUB_CH_ALUMNI)
        return credential
Example #5
0
    def create_certification_group(self, consultant_role_group, certifications,
                                   course_name, instructor_name):
        data = {
            'name': consultant_role_group.name,
            'description': consultant_role_group.description,
            'content_object': consultant_role_group,
            '_type': consultant_role_group._type,
            'created_by': consultant_role_group.created_by,
            'instructor_name': instructor_name,
        }
        data['issued_on'] = consultant_role_group.issued_on
        data['course_name'] = course_name
        certification_group = CertificationGroup.objects.create_group_and_credentials(
            user_from=consultant_role_group.created_by,
            related_objects_list=consultant_role_group.consultant_roles.all(),
            **data)

        for certification in certifications:
            certification_group.credentials.filter(
                user=certification.get('consultant').user).update(
                    accredible_id=certification.get('accredible_id'),
                    accredible_url=certification.get('accredible_url'),
                    status=settings.CERTIFICATION_CH_STATUS_GENERATED)

        for consultant_role in consultant_role_group.consultant_roles.all():
            exo_hub_code = dict(settings.CERTIFICATION_CH_HUB_NAME).get(
                consultant_role_group._type, '')

            if exo_hub_code:
                add_user_exo_hub.send(
                    sender=consultant_role.consultant.user.__class__,
                    user=consultant_role.consultant.user,
                    exo_hub_code=exo_hub_code)

            user_certified.send(
                sender=consultant_role.consultant.user.__class__,
                user=consultant_role.consultant.user,
                consultant_role=consultant_role)