Skip to content

Commit

Permalink
Add referrer to export endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed May 20, 2020
1 parent 424592a commit dd63128
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion backend/atlas/mutations/import_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"date_of_birth",
"title",
"reports_to",
"referred_by",
"department",
"office",
"employee_type",
Expand Down Expand Up @@ -60,6 +61,7 @@ class CsvChange(graphene.ObjectType):
department = graphene.Field(StringChange, required=False)
office = graphene.Field(StringChange, required=False)
reports_to = graphene.Field(StringChange, required=False)
referred_by = graphene.Field(StringChange, required=False)
date_started = graphene.Field(DateChange, required=False)
date_of_birth = graphene.Field(DateChange, required=False)
employee_type = graphene.Field(EmployeeTypeChange, required=False)
Expand Down Expand Up @@ -175,7 +177,7 @@ def apply_changes(changes: List[Dict], current_user: User = None):
value, _ = Office.objects.get_or_create_by_natural_key(
*value.split("-")
)
if field == "reports_to" and value:
if field in ("reports_to", "referred_by") and value:
value, _ = User.objects.get_or_create_by_natural_key(
*value.split("-")
)
Expand Down
8 changes: 6 additions & 2 deletions backend/atlas/mutations/test_import_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
department { previous, new }
office { previous, new }
reportsTo { previous, new }
referredBy { previous, new }
employeeType { previous, new }
isHuman { previous, new }
dateStarted { previous, new }
Expand Down Expand Up @@ -124,8 +125,8 @@ def test_basic_updates(gql_client, default_superuser):

def test_updates_all_attributes(gql_client, default_superuser):
csv_file = io.BytesIO(
f"""id,name,email,employee_type,reports_to,department,title,office,is_human,date_started
{str(default_superuser.id)},{default_superuser.name},{default_superuser.email},CONTRACT,blah@example.com,500-Cool,Bruhah,HQ,false,1/1/20
f"""id,name,email,employee_type,reports_to,referred_by,department,title,office,is_human,date_started
{str(default_superuser.id)},{default_superuser.name},{default_superuser.email},CONTRACT,blah@example.com,blah@example.com,500-Cool,Bruhah,HQ,false,1/1/20
""".strip().encode(
"utf-8"
)
Expand All @@ -143,6 +144,7 @@ def test_updates_all_attributes(gql_client, default_superuser):
assert change["user"]["id"] == str(default_superuser.id)
assert change["employeeType"]
assert change["reportsTo"]
assert change["referredBy"]
assert change["office"]
assert change["title"]
assert change["department"]
Expand All @@ -169,5 +171,7 @@ def test_updates_all_attributes(gql_client, default_superuser):
assert user.profile.office.name == "HQ"
assert user.profile.reports_to.name == "blah"
assert user.profile.reports_to.email == "blah@example.com"
assert user.profile.referred_by.name == "blah"
assert user.profile.referred_by.email == "blah@example.com"
assert user.profile.is_human is False
assert user.profile.date_started == date(2020, 1, 1)
2 changes: 2 additions & 0 deletions frontend/src/pages/AdminImportExportPeople.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ExportCard extends Component {
"date_of_birth",
"title",
"reports_to",
"referred_by",
"department",
"office",
"employee_type",
Expand All @@ -70,6 +71,7 @@ class ExportCard extends Component {
u.dateOfBirth,
u.title,
u.reportsTo ? u.reportsTo.email : "",
u.referredBy ? u.referredBy.email : "",
formatDepartment(u.department),
formatOffice(u.office),
u.employeeType ? u.employeeType.id : "",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ export const EXPORT_PEOPLE_QUERY = gql`
reportsTo {
email
}
referredBy {
email
}
}
}
}
Expand Down

0 comments on commit dd63128

Please sign in to comment.