Exemplo n.º 1
0
 def resolve_involved_agents(self, args, context, info):
     involved = []
     if self.provider:
         involved.append(formatAgent(self.provider))
     events = self.fulfillment_events.all()
     for event in events:
         if event.provider:
             involved.append(formatAgent(event.provider))
     return list(set(involved))
Exemplo n.º 2
0
 def resolve_involved_agents(self, context, **args):  #args, context, info):
     involved = []
     if self.provider:
         involved.append(formatAgent(self.provider))
     events = self.fulfillment_events.all()
     for event in events:
         if event.provider:
             involved.append(formatAgent(event.provider))
     return list(set(involved))
Exemplo n.º 3
0
    def mutate(cls, root, args, context, info):
        id = args.get('id')
        name = args.get('name')
        image = args.get('image')
        note = args.get('note')
        primary_location_id = args.get('primary_location_id')
        email = args.get('email')

        agent = EconomicAgent.objects.get(pk=id)
        if agent:
            if note:
                agent.description = note
            if image:
                agent.photo_url = image
            if name:
                agent.name = name
            if primary_location_id:
                agent.primary_location = Location.objects.get(
                    pk=primary_location_id)
            if email:
                agent.email = email

            user_agent = AgentUser.objects.get(user=context.user).agent
            is_authorized = user_agent.is_authorized(object_to_mutate=agent)
            if is_authorized:
                agent.save()
            else:
                raise PermissionDenied(
                    'User not authorized to perform this action.')

        return UpdatePerson(person=formatAgent(agent))
Exemplo n.º 4
0
    def mutate(cls, root, args, context, info):
        id = args.get('id')
        name = args.get('name')
        image = args.get('image')
        note = args.get('note')
        primary_location_id = args.get('primary_location_id')
        email = args.get('email')

        agent = EconomicAgent.objects.get(pk=id)
        if agent:
            if note:
                agent.description = note
            if image:
                agent.photo_url = image
            if name:
                agent.name = name
            if primary_location_id:
                agent.primary_location = Location.objects.get(pk=primary_location_id)
            if email:
                agent.email = email

            user_agent = AgentUser.objects.get(user=context.user).agent
            is_authorized = user_agent.is_authorized(object_to_mutate=agent)
            if is_authorized:
                agent.save()
            else:
                raise PermissionDenied('User not authorized to perform this action.')

        return UpdateOrganization(organization=formatAgent(agent))
Exemplo n.º 5
0
 def resolve_agent(self, args, *rargs):
     id = args.get('id')
     if id is not None:
         agent = EconomicAgent.objects.get(pk=id)
         if agent:
             return formatAgent(agent)
     raise PermissionDenied("Cannot find requested agent")
Exemplo n.º 6
0
 def resolve_agent(self, args, *rargs):
     id = args.get('id')
     if id is not None:
         agent = EconomicAgent.objects.get(pk=id)
         if agent:
             return formatAgent(agent)
     raise PermissionDenied("Cannot find requested agent")
Exemplo n.º 7
0
 def resolve_person(self, args, context, info):
     id = args.get('id')
     if id is not None:
         person = EconomicAgent.objects.get(pk=id)
         if person:
             if person.agent_type.party_type == "individual":
                 return formatAgent(person)
     return None
Exemplo n.º 8
0
 def resolve_person(self, args, context, info):
     id = args.get('id')
     if id is not None:
         person = EconomicAgent.objects.get(pk=id)
         if person:
             if person.agent_type.party_type == "individual":
                 return formatAgent(person)
     return None
Exemplo n.º 9
0
 def resolve_organization(self, args, context, info):
     id = args.get('id')
     if id is not None:
         org = EconomicAgent.objects.get(pk=id)
         if org:
             if org.agent_type.party_type == "individual":
                 return None
             else:
                 return formatAgent(org)
     return None
Exemplo n.º 10
0
 def resolve_organization(self, args, context, info):
     id = args.get('id')
     if id is not None:
         org = EconomicAgent.objects.get(pk=id)
         if org:
             if org.agent_type.party_type == "individual":
                 return None
             else:
                 return formatAgent(org)
     return None
Exemplo n.º 11
0
 def resolve_fc_organizations(self, args, context, info):
     joining_style = args.get("joining_style")
     visibility = args.get("visibility")
     orgs = Project.objects.all()
     if visibility:
         orgs = orgs.filter(visibility=visibility)
     if joining_style:
         orgs = orgs.filter(joining_style=joining_style)
     org_agents = []
     for org in orgs:
         org_agents.append(formatAgent(org.agent))
     return org_agents
Exemplo n.º 12
0
 def resolve_fc_organizations(self, args, context, info):
     joining_style = args.get("joining_style")
     visibility = args.get("visibility")
     orgs = Project.objects.all()
     if visibility:
         orgs = orgs.filter(visibility=visibility)
     if joining_style:
         orgs = orgs.filter(joining_style=joining_style)
     org_agents = []
     for org in orgs:
         org_agents.append(formatAgent(org.agent))
     return org_agents
Exemplo n.º 13
0
    def mutate(cls, root, args, context, info):
        id = args.get('id')
        agent = EconomicAgent.objects.get(pk=id)
        if agent:
            if agent.is_deletable():
                user_agent = AgentUser.objects.get(user=context.user).agent
                #is_authorized = user_agent.is_authorized(context_agent_id=agent.id) TODO: what should be the rule?
                #if is_authorized:
                agent.delete()
                #else:
                #    raise PermissionDenied('User not authorized to perform this action.')
            else:
                raise PermissionDenied("Organization has activity or relationships and cannot be deleted.")

        return DeleteOrganization(organization=formatAgent(agent))
Exemplo n.º 14
0
    def mutate(cls, root, args, context, info):
        #import pdb; pdb.set_trace()
        name = args.get('name')
        image = args.get('image')
        note = args.get('note')
        primary_location_id = args.get('primary_location_id')
        primary_phone = args.get('primary_phone')
        email = args.get('email')
        type = args.get('type')

        if not note:
            note = ""
        if not image:
            image = ""
        if primary_location_id:
            location = Location.objects.get(pk=primary_location_id)
        else:
            location = None
        get_type = None
        if type:
            get_type = AgentType.objects.get(name=type)
        if not type:
            get_types = AgentType.objects.get(party_type="org")
            if get_types:
                get_type = get_types[0]

        agent = EconomicAgent(
            name=name,
            nick=name,
            agent_type=get_type,
            photo_url=image,
            description=note,
            primary_location=location,
            phone_primary=primary_phone,
            email=email,
            created_by=context.user,
        )

        user_agent = AgentUser.objects.get(user=context.user).agent
        is_authorized = user_agent.is_authorized(object_to_mutate=agent)
        if is_authorized:
            agent.save()
        else:
            raise PermissionDenied(
                'User not authorized to perform this action.')

        return CreateOrganization(organization=formatAgent(agent))
Exemplo n.º 15
0
    def mutate(cls, root, args, context, info):
        #import pdb; pdb.set_trace()
        name = args.get('name')
        image = args.get('image')
        note = args.get('note')
        primary_location_id = args.get('primary_location_id')
        primary_phone = args.get('primary_phone')
        email = args.get('email')
        type = args.get('type')

        if not note:
            note = ""
        if not image:
            image = ""
        if primary_location_id:
            location = Location.objects.get(pk=primary_location_id)
        else:
            location = None
        get_type = None
        if type:
            get_type = AgentType.objects.get(name=type)
        if not type:
            get_types = AgentType.objects.get(party_type="org")
            if get_types:
                get_type = get_types[0]

        agent = EconomicAgent(
            name = name,
            nick = name,
            agent_type = get_type,
            photo_url = image,
            description = note,
            primary_location = location,
            phone_primary = primary_phone,
            email = email,
            created_by=context.user,
        )

        user_agent = AgentUser.objects.get(user=context.user).agent
        is_authorized = user_agent.is_authorized(object_to_mutate=agent)
        if is_authorized:
            agent.save()
        else:
            raise PermissionDenied('User not authorized to perform this action.')

        return CreateOrganization(organization=formatAgent(agent))
Exemplo n.º 16
0
    def mutate(cls, root, args, context, info):
        id = args.get('id')
        agent = EconomicAgent.objects.get(pk=id)
        if agent:
            if agent.is_deletable():
                user_agent = AgentUser.objects.get(user=context.user).agent
                #is_authorized = user_agent.is_authorized(context_agent_id=agent.id) TODO: what should be the rule?
                #if is_authorized:
                agent.delete()
                #else:
                #    raise PermissionDenied('User not authorized to perform this action.')
            else:
                raise PermissionDenied(
                    "Organization has activity or relationships and cannot be deleted."
                )

        return DeleteOrganization(organization=formatAgent(agent))
Exemplo n.º 17
0
 def resolve_provider(self, args, *rargs):
     return formatAgent(self.provider)
Exemplo n.º 18
0
 def resolve_scope(self, args, *rargs):
     return formatAgent(self.scope)
Exemplo n.º 19
0
 def resolve_receiver(self, args, *rargs):
     return formatAgent(self.receiver)
Exemplo n.º 20
0
 def resolve_provider(self, args, *rargs):
     return formatAgent(self.provider)
Exemplo n.º 21
0
 def resolve_involved_agents(self, args, context, info):
     agents = self.related_agents()
     formatted_agents = []
     for agent in agents:
         formatted_agents.append(formatAgent(agent))
     return formatted_agents
Exemplo n.º 22
0
 def resolve_created_by(self, args, *rargs):
     return formatAgent(self.created_by_agent)
Exemplo n.º 23
0
 def resolve_agent(self, args, *rargs):
     return formatAgent(self.user.agent.agent)
Exemplo n.º 24
0
 def resolve_object(self, args, *rargs):
     return formatAgent(self.object)
Exemplo n.º 25
0
 def resolve_involved_agents(self, args, context, info):
     agents = self.related_agents()
     formatted_agents = []
     for agent in agents:
         formatted_agents.append(formatAgent(agent))
     return formatted_agents
Exemplo n.º 26
0
 def resolve_scope(self, context, **args):  #args, *rargs):
     return formatAgent(self.scope)
Exemplo n.º 27
0
 def resolve_validated_by(self, args, *rargs):
     return formatAgent(self.validated_by)
Exemplo n.º 28
0
 def resolve_created_by(self, context, **args):  #args, *rargs):
     return formatAgent(self.created_by_agent)
Exemplo n.º 29
0
 def resolve_my_agent(self, args, *rargs):
     agentUser = AgentUser.objects.filter(user=self.user).first()
     agent = agentUser.agent
     if agent:
         return formatAgent(agent)
     raise PermissionDenied("Cannot find requested agent")
Exemplo n.º 30
0
 def resolve_validated_by(self, args, *rargs):
     return formatAgent(self.validated_by)
Exemplo n.º 31
0
 def resolve_receiver(self, args, *rargs):
     return formatAgent(self.receiver)
Exemplo n.º 32
0
 def resolve_scope(self, args, *rargs):
     return formatAgent(self.scope)
Exemplo n.º 33
0
 def resolve_working_agents(self, args, context, info):
     agents = self.all_working_agents()
     formatted_agents = []
     for agent in agents:
         formatted_agents.append(formatAgent(agent))
     return formatted_agents
 def resolve_agent(self, args, *rargs):
     return formatAgent(self.agent)
Exemplo n.º 35
0
 def resolve_working_agents(self, args, context, info):
     agents = self.all_working_agents()
     formatted_agents = []
     for agent in agents:
         formatted_agents.append(formatAgent(agent))
     return formatted_agents
Exemplo n.º 36
0
 def resolve_receiver(self, context, **args):  #args, *rargs):
     return formatAgent(self.receiver)
Exemplo n.º 37
0
 def resolve_my_agent(self, args, *rargs):
     agentUser = AgentUser.objects.filter(user=self.user).first()
     agent = agentUser.agent
     if agent:
         return formatAgent(agent)
     raise PermissionDenied("Cannot find requested agent")
Exemplo n.º 38
0
 def resolve_provider(self, context, **args):  #args, *rargs):
     return formatAgent(self.provider)
Exemplo n.º 39
0
 def resolve_context_agent(self, args, *rargs):
     return formatAgent(self.context_agent)