Commit 914b6601 authored by Lynn Foster's avatar Lynn Foster
Browse files

Merge branch 'master' of...

Merge branch 'master' of https://github.com/LearnDeepMilwaukee/valuenetwork.git into location-create
parents d151591c b3fa5c67
......@@ -13,6 +13,7 @@ import valuenetwork.api.schemas.Auth
import valuenetwork.api.schemas.Agent
import valuenetwork.api.schemas.AgentRelationship
import valuenetwork.api.schemas.AgentRelationshipRole
import valuenetwork.api.schemas.AgentResourceClassification
import valuenetwork.api.schemas.Organization
import valuenetwork.api.schemas.OrganizationClassification
import valuenetwork.api.schemas.Person
......@@ -36,6 +37,7 @@ class ViewerQuery(
valuenetwork.api.schemas.Agent.Query,
valuenetwork.api.schemas.AgentRelationship.Query,
valuenetwork.api.schemas.AgentRelationshipRole.Query,
valuenetwork.api.schemas.AgentResourceClassification.Query,
valuenetwork.api.schemas.Organization.Query,
valuenetwork.api.schemas.OrganizationClassification.Query,
valuenetwork.api.schemas.Person.Query,
......@@ -104,6 +106,8 @@ class Mutation(graphene.ObjectType):
update_agent_relationship = valuenetwork.api.schemas.AgentRelationship.UpdateAgentRelationship.Field()
#delete_agent_relationship = valuenetwork.api.schemas.AgentRelationship.DeleteAgentRelationship.Field()
create_place = valuenetwork.api.schemas.Place.CreatePlace.Field()
create_agent_resource_classification = valuenetwork.api.schemas.AgentResourceClassification.CreateAgentResourceClassification.Field()
delete_agent_resource_classification = valuenetwork.api.schemas.AgentResourceClassification.DeleteAgentResourceClassification.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
......@@ -8,6 +8,7 @@
import graphene
from valuenetwork.valueaccounting.models import EconomicAgent, AgentUser, Location, AgentType
from django.contrib.auth.models import User
from valuenetwork.api.models import formatAgent, formatAgentList, Person, Organization
from valuenetwork.api.types.Agent import Agent, Person, Organization
from six import with_metaclass
......@@ -50,6 +51,151 @@ class Query(graphene.AbstractType):
user_agent = AgentUser.objects.filter(user=self.user).first().agent
return user_agent.is_authorized(context_agent_id=context_agent_id)
################## shameless hack for user registration ######################
username_exists = graphene.Boolean(username=graphene.String())
email_exists = graphene.Boolean(email=graphene.String())
# the next 2 methods are for someone registering, sending an email, they click a link in the email to complete registration
create_inactive_user = graphene.String(username=graphene.String(),
email=graphene.String(),
pswd=graphene.String())
activate_user_create_person = graphene.String(username=graphene.String(),
name=graphene.String(),
image=graphene.String(),
phone=graphene.String(),
user_token=graphene.String())
# the next method is for using a captcha so everything is created at once
create_user_person = graphene.String(username=graphene.String(),
email=graphene.String(),
pswd=graphene.String(),
name=graphene.String(),
image=graphene.String(),
phone=graphene.String())
def resolve_username_exists(self, args, *rargs):
username = args.get('username')
usernames = User.objects.filter(username=username)
if usernames:
return True
else:
return False
def resolve_email_exists(self, args, *rargs):
email = args.get('email')
emails = User.objects.filter(email=email)
if emails:
return True
else:
# may want to check here for the agent.email?
return False
def resolve_create_inactive_user(self, args, *rargs):
username = args.get('username', None)
email = args.get('email', None)
pswd = args.get('pswd', None)
if username and email and pswd:
user = User.objects.create_user(username=username, email=email, password=pswd)
user.is_active = False
user.save()
from django.template.loader import render_to_string
from django.contrib.sites.models import Site
from django.utils.http import urlsafe_base64_encode
from django.utils.encoding import force_bytes
from valuenetwork.tokens import signup_confirmation_token
subject = 'Activate Your LearnDeep NRP Account'
token = signup_confirmation_token.make_token(user)
message = render_to_string('valueaccounting/signup/confirm_email.html', {
'user': user,
'domain': Site.objects.get_current().domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': token,
} )
user.email_user(subject, message) #comment out to test without email set up, use returned token
return token
return None
def resolve_activate_user_create_person(self, args, *rargs):
token = args.get('user_token', None)
username = args.get('username', None)
name = args.get('name', None)
image = args.get('image', None)
phone = args.get('phone', None)
if token is None:
raise ValidationError("Invalid token.")
if username is None:
raise ValidationError("Invalid username.")
if name is None:
raise ValidationError("Name is required.")
user = User.objects.get(username=username)
if user is None:
raise ValidationError("Invalid username.")
from valuenetwork.tokens import signup_confirmation_token
if signup_confirmation_token.check_token(user, token):
user.is_active = True
user.save()
else:
raise ValidationError("Invalid token.")
at_person = AgentType.objects.get(party_type="individual")
agent = EconomicAgent(
nick = name,
name = name,
photo_url = image,
phone_primary = phone,
agent_type = at_person,
email = user.email,
created_by = user,
)
agent.save()
au = AgentUser(
agent = agent,
user = user)
au.save()
return "User " + username + " activated, Agent and AgentUser created."
def resolve_create_user_person(self, args, *rargs):
username = args.get('username', None)
email = args.get('email', None)
pswd = args.get('pswd', None)
name = args.get('name', None)
image = args.get('image', None)
phone = args.get('phone', None)
if username is None:
raise ValidationError("Username is required.")
if name is None:
raise ValidationError("Name is required.")
if email is None:
raise ValidationError("Email is required.")
if pswd is None:
raise ValidationError("Password is required.")
user = User.objects.create_user(username=username, email=email, password=pswd)
user.is_active = True
user.save()
at_person = AgentType.objects.get(party_type="individual")
agent = EconomicAgent(
nick = name,
name = name,
photo_url = image,
phone_primary = phone,
agent_type = at_person,
email = user.email,
created_by = user,
)
agent.save()
au = AgentUser(
agent = agent,
user = user)
au.save()
return "User " + username + " created, Agent and AgentUser created."
##################################################################
class CreateOrganization(AuthedMutation):
class Input(with_metaclass(AuthedInputMeta)):
......@@ -299,3 +445,59 @@ class DeleteOrganization(AuthedMutation):
raise PermissionDenied("Organization has activity or relationships and cannot be deleted.")
return DeleteOrganization(organization=formatAgent(agent))
'''
class CreateInactiveUser(AuthedMutation):
class Input(with_metaclass(AuthedInputMeta)):
username = graphene.String(required=True)
email = graphene.String(required=True)
password = graphene.String(required=True)
user = graphene.Field(lambda: Person)
@classmethod
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
if type:
get_type = AgentType.objects.get(name=type)
if not type:
get_types = AgentType.objects.filter(party_type="individual")
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 CreatePerson(person=formatAgent(agent))
'''
#
# Agent resource classification entity schema def
# This is used for person's skills management. Also can be used in the future for sources for resources to be obtained for production inputs, but will need the action added for that.
#
import graphene
from graphene_django.types import DjangoObjectType
from valuenetwork.api.types.AgentResourceClassification import AgentResourceClassification
from valuenetwork.valueaccounting.models import EconomicAgent, AgentUser, AgentResourceType, EconomicResourceType, EventType
from six import with_metaclass
from django.contrib.auth.models import User
from .Auth import AuthedInputMeta, AuthedMutation
from django.core.exceptions import PermissionDenied, ValidationError
class Query(graphene.AbstractType):
agent_resource_classification = graphene.Field(AgentResourceClassification,
id=graphene.Int())
all_agent_resource_classifications = graphene.List(AgentResourceClassification)
def resolve_agent_resource_classification(self, args, *rargs):
id = args.get('id')
if id is not None:
ar = AgentResourceType.objects.get(pk=id)
if ar:
return ar
return None
def resolve_all_agent_resource_classifications(self, args, context, info):
return AgentResourceType.objects.all()
class CreateAgentResourceClassification(AuthedMutation):
class Input(with_metaclass(AuthedInputMeta)):
agent_id = graphene.Int(required=True)
resource_classification_id = graphene.Int(required=True)
agent_resource_classification = graphene.Field(lambda: AgentResourceClassification)
@classmethod
def mutate(cls, root, args, context, info):
agent_id = args.get('agent_id')
resource_classification_id = args.get('resource_classification_id')
agent = EconomicAgent.objects.get(pk=agent_id)
rc = EconomicResourceType.objects.get(pk=resource_classification_id)
et_work = EventType.objects.get(name="Time Contribution") #TODO: now just for skills
agent_resource_classification = AgentResourceType.objects.filter(agent=agent, resource_type=rc, event_type=et_work)
if agent_resource_classification:
raise ValidationError('Resource classification already exists for this agent and action.')
else:
agent_resource_classification = AgentResourceType(
agent=agent,
resource_type=rc,
event_type=et_work,
created_by=context.user,
)
user_agent = AgentUser.objects.get(user=context.user).agent
is_authorized = user_agent.is_authorized(object_to_mutate=agent_resource_classification)
if is_authorized:
agent_resource_classification.save()
else:
raise PermissionDenied('User not authorized to perform this action.')
return CreateAgentResourceClassification(agent_resource_classification=agent_resource_classification)
class DeleteAgentResourceClassification(AuthedMutation):
class Input(with_metaclass(AuthedInputMeta)):
id = graphene.Int(required=True)
agent_resource_classification = graphene.Field(lambda: AgentResourceClassification)
@classmethod
def mutate(cls, root, args, context, info):
id = args.get('id')
agent_resource_classification = AgentResourceType.objects.get(pk=id)
if agent_resource_classification:
user_agent = AgentUser.objects.get(user=context.user).agent
is_authorized = user_agent.is_authorized(object_to_mutate=agent_resource_classification)
if is_authorized:
agent_resource_classification.delete()
else:
raise PermissionDenied('User not authorized to perform this action.')
return DeleteAgentResourceClassification(agent_resource_classification=agent_resource_classification)
......@@ -77,9 +77,9 @@ class CreateCommitment(AuthedMutation):
#for_plan_deliverable_id = args.get('for_plan_deliverable_id')
url = args.get('url')
if output_of_id or input_of_id:
if not plan_id:
raise ValidationError("Process related commitments must be part of a plan.")
#if output_of_id or input_of_id:
# if not plan_id:
# raise ValidationError("Process related commitments must be part of a plan.")
event_type = EventType.objects.convert_action_to_event_type(action)
if not note:
note = ""
......@@ -212,7 +212,9 @@ class UpdateCommitment(AuthedMutation):
commitment.start_date = datetime.datetime.strptime(planned_start, '%Y-%m-%d').date()
if scope_id:
commitment.context_agent = EconomicAgent.objects.get(pk=scope_id)
if provider_id:
if provider_id == 0:
commitment.from_agent = None
elif provider_id:
commitment.from_agent = EconomicAgent.objects.get(pk=provider_id)
if receiver_id:
commitment.to_agent = EconomicAgent.objects.get(pk=receiver_id)
......
......@@ -13,14 +13,11 @@ from valuenetwork.api.models import formatAgent, formatAgentList
class Query(graphene.AbstractType):
# define input query params
person = graphene.Field(Person,
id=graphene.Int())
all_people = graphene.List(Person)
# load any person
def resolve_person(self, args, context, info):
id = args.get('id')
......
......@@ -47,7 +47,7 @@ class CreateProcess(AuthedMutation):
planned_finish = graphene.String(required=True)
scope_id = graphene.Int(required=True)
note = graphene.String(required=False)
plan_id = graphene.Int(required=True)
plan_id = graphene.Int(required=False)
process = graphene.Field(lambda: Process)
......@@ -66,7 +66,9 @@ class CreateProcess(AuthedMutation):
start_date = datetime.datetime.strptime(planned_start, '%Y-%m-%d').date()
end_date = datetime.datetime.strptime(planned_finish, '%Y-%m-%d').date()
scope = EconomicAgent.objects.get(pk=scope_id)
plan = Order.objects.get(pk=plan_id)
plan = None
if plan_id:
plan = Order.objects.get(pk=plan_id)
process = ProcessProxy(
name=name,
start_date=start_date,
......
......@@ -1112,6 +1112,20 @@ query($token: String) {
}
}
query ($token: String) {
viewer(token: $token) {
myAgent {
id
agentSkillRelationships {
id
resourceClassification {
name
}
}
}
}
}
query($token: String) {
viewer(token: $token) {
allPeople {
......@@ -1165,6 +1179,39 @@ query($token: String) {
}
}
query($token: String) {
viewer(token: $token) {
emailExists(email:"xxx@gmail.com")
}
}
query($token: String) {
viewer(token: $token) {
usernameExists(username:"lynn")
}
}
query($token: String) {
viewer(token: $token) {
createInactiveUser(username:"lynn-xfxzz", email:"qxaw@gmail.com", pswd:"xxdd")
}
}
query($token: String) {
viewer(token: $token) {
activateUserCreatePerson(username:"lynn-xfxzz",
userToken:"51s-10ed8117b79f4863e46b",
name:"Lynn F", image:"http://images.example.com/jdskdsf", phone:"555-3434")
}
}
query($token: String) {
viewer(token: $token) {
createUserPerson(username:"lynn-xfqxxzzs", email:"qxsxqaw@gmail.com", pswd:"xxdd",
name:"Lynn Test", image:"http://xxx.image.com", phone:"608-555-1212" )
}
}
query($token: String) {
viewer(token: $token) {
organizationClassification(id:8) {
......@@ -1185,6 +1232,21 @@ query($token: String) {
}
}
query($token: String) {
viewer(token: $token) {
person(id:6) {
name
commitmentsMatchingSkills(page:1) {
id
action
resourceClassifiedAs {
name
}
}
}
}
}
query ($token: String) {
viewer(token: $token) {
agent(id: 39) {
......@@ -1211,6 +1273,28 @@ query ($token: String) {
}
}
query($token: String) {
viewer(token: $token) {
agent(id:106) {
name
searchAgentCommitments(searchString:"Fruit") {
id
note
}
searchAgentPlans(searchString:"Fruit", isFinished: false) {
id
name
note
}
searchAgentProcesses(searchString:"fruit") {
id
name
note
}
}
}
}
query($token: String) {
viewer(token: $token) {
organizationTypes {
......@@ -1767,6 +1851,17 @@ query ($token: String) {
}
}
query ($token: String) {
viewer(token: $token) {
agent(id: 146) {
agentDefinedResourceClassifications(action: "work") {
id
name
}
}
}
}
query($token: String) {
viewer(token: $token) {
allRecipes {
......@@ -2557,7 +2652,7 @@ query ($token: String) {
}
note
}
agentCommitments(latestNumberOfDays: 30) {
agentCommitments(page:1) {
id
action
plannedStart
......@@ -3627,4 +3722,32 @@ mutation ($token: String!) {
}
}
createAgentResourceClassification(token: $token, agentId: 6, resourceClassificationId: 60) {
agentResourceClassification {
id
agent {
name
}
resourceClassification {
name
}
action
}
}
}
mutation ($token: String!) {
deleteAgentResourceClassification(token: $token, id: 42) {
agentResourceClassification {
agent {
name
}
resourceClassification {
name
}
action
}
}
}
'''
......@@ -5,7 +5,7 @@
import graphene
from graphene_django.types import DjangoObjectType
from django.db.models import Q
from valuenetwork.valueaccounting.models import EconomicAgent, EconomicResourceType, AgentType, EventTypeManager, EventType
from valuenetwork.valueaccounting.models import EconomicAgent, EconomicResourceType, AgentType, EventTypeManager, EventType, AgentResourceType, EconomicResourceType
import valuenetwork.api.types as types
from valuenetwork.api.types.AgentRelationship import AgentRelationship, AgentRelationshipCategory, AgentRelationshipRole
from valuenetwork.api.models import Organization as OrganizationModel, Person as PersonModel, formatAgentList
......@@ -43,14 +43,25 @@ class Agent(graphene.Interface):
search_owned_inventory_resources = graphene.List(lambda: types.EconomicResource,
search_string=graphene.String())
agent_defined_resource_classifications = graphene.List(lambda: types.ResourceClassification,
action=graphene.String())
agent_processes = graphene.List(lambda: types.Process,
is_finished=graphene.Boolean())
search_agent_processes = graphene.List(lambda: types.Process,
search_string=graphene.String(),
is_finished=graphene.Boolean())
agent_plans = graphene.List(lambda: types.Plan,
is_finished=graphene.Boolean(),
year=graphene.Int(),
month=graphene.Int())
search_agent_plans = graphene.List(lambda: types.Plan,
search_string=graphene.String(),
is_finished=graphene.Boolean())
agent_economic_events = graphene.List(lambda: types.EconomicEvent,
latest_number_of_days=graphene.Int(),
request_distribution=graphene.Boolean(),
......@@ -59,7 +70,12 @@ class Agent(graphene.Interface):
month=graphene.Int())
agent_commitments = graphene.List(lambda: types.Commitment,
latest_number_of_days=graphene.Int())
latest_number_of_days=graphene.Int(),
page=graphene.Int())
search_agent_commitments = graphene.List(lambda: types.Commitment,