Ejemplo n.º 1
0
    def kwargs_from_temba(cls, org, temba_contact):
        name = temba_contact.name or ""

        org_region_uuids = [r.uuid for r in Region.get_all(org)]
        region_uuids = intersection(org_region_uuids, temba_contact.groups)
        region = Region.objects.get(org=org, uuid=region_uuids[0]) if region_uuids else None

        if not region:  # pragma: no cover
            raise ValueError("No region with UUID in %s" %
                             ", ".join(temba_contact.groups))

        org_group_uuids = [g.uuid for g in Group.get_all(org)]
        group_uuids = intersection(org_group_uuids, temba_contact.groups)
        group = Group.objects.get(org=org, uuid=group_uuids[0]) if group_uuids else None

        facility_code = temba_contact.fields.get(org.facility_code_field, None)

        return {
            'org': org,
            'name': name,
            'urn': temba_contact.urns[0],
            'region': region,
            'group': group,
            'language': temba_contact.language,
            'facility_code': facility_code,
            'uuid': temba_contact.uuid,
        }
Ejemplo n.º 2
0
    def kwargs_from_temba(cls, org, temba_contact):
        name = temba_contact.name if temba_contact.name is not None else ""

        org_region_uuids = [r.uuid for r in Region.get_all(org)]
        region_uuids = intersection(org_region_uuids, temba_contact.groups)
        region = Region.objects.get(org=org, uuid=region_uuids[0]) if region_uuids else None

        if not region:  # pragma: no cover
            raise ValueError("No region with UUID in %s" % ", ".join(temba_contact.groups))

        org_group_uuids = [g.uuid for g in Group.get_all(org)]
        group_uuids = intersection(org_group_uuids, temba_contact.groups)
        group = Group.objects.get(org=org, uuid=group_uuids[0]) if group_uuids else None

        facility_code = temba_contact.fields.get(org.get_facility_code_field(), None)

        return dict(org=org, name=name, urn=temba_contact.urns[0],
                    region=region, group=group, language=temba_contact.language, facility_code=facility_code,
                    uuid=temba_contact.uuid)
Ejemplo n.º 3
0
    def kwargs_from_temba(cls, org, temba_contact):
        org_room_uuids = [r.uuid for r in Room.get_all(org)]
        room_uuids = intersection(org_room_uuids, temba_contact.groups)
        room = Room.objects.get(org=org, uuid=room_uuids[0]) if room_uuids else None

        if not room:
            raise ValueError("No room with uuid in %s" % ", ".join(temba_contact.groups))

        return dict(org=org,
                    full_name=temba_contact.name,
                    chat_name=temba_contact.fields.get(org.get_chat_name_field(), None),
                    urn=temba_contact.urns[0],
                    room=room,
                    uuid=temba_contact.uuid)
Ejemplo n.º 4
0
    def access_level(self, user):
        """
        A user can view a case if one of these conditions is met:
            1) they are an administrator for the case org
            2) their partner org is assigned to the case
            3) their partner org can view a label assigned to the case

        They can additionally update the case if 1) or 2) is true
        """
        if user.can_administer(self.org) or user.profile.partner == self.assignee:
            return AccessLevel.update
        elif user.profile.partner and intersection(self.get_labels(), user.profile.partner.get_labels()):
            return AccessLevel.read
        else:
            return AccessLevel.none
Ejemplo n.º 5
0
    def access_level(self, user):
        """
        A user can view a case if one of these conditions is met:
            1) they are an administrator for the case org
            2) their partner org is assigned to the case
            3) their partner org can view a label assigned to the case

        They can additionally update the case if 1) or 2) is true
        """
        if user.can_administer(
                self.org) or user.profile.partner == self.assignee:
            return AccessLevel.update
        elif user.profile.partner and intersection(
                self.get_labels(), user.profile.partner.get_labels()):
            return AccessLevel.read
        else:
            return AccessLevel.none
Ejemplo n.º 6
0
    def access_level(self, user):
        """
        A user can view a case if one of these conditions is met:
            1) they're a superuser
            2) they're a non-partner user from same org
            3) they're a partner user in partner which is not restricted
            4) their partner org is assigned to the case
            5) their partner org can view a label assigned to the case

        They can additionally update the case if one of 1-4 is true
        """
        if not user.is_superuser and not self.org.get_user_org_group(user):
            return AccessLevel.none

        user_partner = user.get_partner(self.org)

        if user.is_superuser or not user_partner or not user_partner.is_restricted or user_partner == self.assignee:
            return AccessLevel.update
        elif user_partner and intersection(self.labels.filter(is_active=True), user_partner.get_labels()):
            return AccessLevel.read
        else:
            return AccessLevel.none
Ejemplo n.º 7
0
    def access_level(self, user):
        """
        A user can view a case if one of these conditions is met:
            1) they're a superuser
            2) they're a non-partner user from same org
            3) they're a partner user in partner which is not restricted
            4) their partner org is assigned to the case
            5) their partner org can view a label assigned to the case

        They can additionally update the case if one of 1-4 is true
        """
        if not user.is_superuser and not self.org.get_user_org_group(user):
            return AccessLevel.none

        user_partner = user.get_partner(self.org)

        if user.is_superuser or not user_partner or not user_partner.is_restricted or user_partner == self.assignee:
            return AccessLevel.update
        elif user_partner and intersection(self.labels.filter(is_active=True), user_partner.get_labels()):
            return AccessLevel.read
        else:
            return AccessLevel.none