Skip to content

Commit

Permalink
Merge pull request #446 from kids-first/full-name-events
Browse files Browse the repository at this point in the history
♻️ Replace usernames in events with full names
  • Loading branch information
XuTheBunny authored Aug 6, 2020
2 parents 2b02f77 + a146030 commit c9d459b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions creator/buckets/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def mutate(self, info, bucket, study):

# Log an event
message = (
f"{user.username} linked bucket {bucket.name} to "
f"{user.display_name} linked bucket {bucket.name} to "
f"study {study.kf_id}"
)
event = Event(
Expand Down Expand Up @@ -110,7 +110,7 @@ def mutate(self, info, bucket, study):

# Log an event
message = (
f"{user.username} unlinked bucket {bucket.name} from "
f"{user.display_name} unlinked bucket {bucket.name} from "
f"study {study.kf_id}"
)
event = Event(
Expand Down
6 changes: 3 additions & 3 deletions creator/events/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def new_file(signal, sender, instance, created, **kwargs):
# Don't do anything for updates
if not created:
return
username = getattr(instance.creator, "username", "Anonymous user")
username = getattr(instance.creator, "display_name", "Anonymous user")
message = f"{username} created file {instance.kf_id}"

event = Event(
Expand All @@ -30,7 +30,7 @@ def delete_file(signal, sender, instance, **kwargs):
"""
Handle deleted files
"""
username = getattr(instance.creator, "username", "Anonymous user")
username = getattr(instance.creator, "display_name", "Anonymous user")
message = f"{username} deleted file {instance.kf_id}"
event = Event(
study=instance.study,
Expand All @@ -46,7 +46,7 @@ def new_version(signal, sender, instance, created, **kwargs):
"""
Handle new versions and updates
"""
username = getattr(instance.creator, "username", "Anonymous user")
username = getattr(instance.creator, "display_name", "Anonymous user")
if created:
message = (
f"{username} created version {instance.kf_id}"
Expand Down
2 changes: 1 addition & 1 deletion creator/files/mutations/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def mutate(self, info, kf_id, **kwargs):

# Make an update event
message = (
f"{user.username} updated {', '.join(update_fields)} "
f"{user.display_name} updated {', '.join(update_fields)} "
f"{'of ' if len(update_fields)>0 else ''} file {file.kf_id}"
)
event = Event(
Expand Down
2 changes: 2 additions & 0 deletions creator/management/commands/setup_test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def handle(self, *args, **options):
logger.info("user already exists")
try:
user = User.objects.get(username="testuser")
user.first_name = "Bobby"
user.last_name = "Tables"
user.groups.add(Group.objects.get(name="Administrators"))
user.save()
except Exception as err:
Expand Down
2 changes: 1 addition & 1 deletion creator/projects/cavatica.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def create_project(study, project_type, workflow_type=None, user=None):

# Log an event
if user:
message = f"{user.username} created project {cavatica_project.id}"
message = f"{user.display_name} created project {cavatica_project.id}"
else:
message = f"A new project was created {cavatica_project.id}"
event = Event(
Expand Down
6 changes: 3 additions & 3 deletions creator/projects/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def mutate(self, info, id, input):
project.save()

# Log an event
message = f"{user.username} updated project {project.project_id}"
message = f"{user.display_name} updated project {project.project_id}"
event = Event(
study=project.study,
project=project,
Expand Down Expand Up @@ -202,7 +202,7 @@ def mutate(self, info, project, study):

# Log an event
message = (
f"{user.username} linked project {project.project_id} to "
f"{user.display_name} linked project {project.project_id} to "
f"study {study.kf_id}"
)
event = Event(
Expand Down Expand Up @@ -262,7 +262,7 @@ def mutate(self, info, project, study):

# Log an event
message = (
f"{user.username} unlinked project {project.project_id} from "
f"{user.display_name} unlinked project {project.project_id} from "
f"study {study.kf_id}"
)
event = Event(
Expand Down
2 changes: 1 addition & 1 deletion creator/referral_tokens/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def mutate(self, info, input):
# Log an event
if user:
message = (
f"{user.username} invited {referral_token.email} to"
f"{user.display_name} invited {referral_token.email} to"
f" {len(input['studies'])} studies"
)
else:
Expand Down
4 changes: 1 addition & 3 deletions creator/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ def make_study_message(studyObj):
picture = None

if user:
author = (
ev.user.username if ev.user.username else "Anonymous user"
)
author = ev.user.display_name
picture = ev.user.picture if ev.user.picture else anon_pic

else:
Expand Down
28 changes: 12 additions & 16 deletions creator/studies/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def mutate(self, info, input, workflows=None):
).save()

# Log an event
message = f"{user.username} created study {study.kf_id}"
message = f"{user.display_name} created study {study.kf_id}"
event = Event(study=study, description=message, event_type="SD_CRE")
# Only add the user if they are in the database (not a service user)
if not user._state.adding:
Expand Down Expand Up @@ -373,7 +373,7 @@ def mutate(self, info, id, input):
study.save()

# Log an event
message = f"{user.username} updated study {study.kf_id}"
message = f"{user.display_name} updated study {study.kf_id}"
event = Event(study=study, description=message, event_type="SD_UPD")
# Only add the user if they are in the database (not a service user)
if not user._state.adding:
Expand Down Expand Up @@ -425,25 +425,23 @@ def mutate(self, info, study, user, role):
raise GraphQLError(f"User {user_id} does not exist.")

membership, created = Membership.objects.update_or_create(
study=study,
collaborator=collaborator,
defaults={"role": role},
study=study, collaborator=collaborator, defaults={"role": role},
)

# Log an event
if created:
membership.invited_by = user
message = (
f"{user.username} added {collaborator.username} "
f"{user.display_name} added {collaborator.display_name} "
f"as collaborator to study {study.kf_id}"
)
event = Event(
study=study, description=message, event_type="CB_ADD"
)
else:
message = (
f"{user.username} changed {collaborator.username}'s role"
f" to {role} in study {study.kf_id}"
f"{user.display_name} changed {collaborator.display_name}'s "
f"role to {role} in study {study.kf_id}"
)
event = Event(
study=study, description=message, event_type="CB_UPD"
Expand Down Expand Up @@ -505,7 +503,7 @@ def mutate(self, info, study, user):

# Log an event
message = (
f"{user.username} removed {collaborator.username} "
f"{user.display_name} removed {collaborator.display_name} "
f"as collaborator from study {study.kf_id}"
)
event = Event(study=study, description=message, event_type="CB_REM")
Expand Down Expand Up @@ -572,7 +570,7 @@ def mutate(self, info, study, data):

# Log an event
message = (
f"{user.username} study {study.kf_id}'s sequencing status "
f"{user.display_name} study {study.kf_id}'s sequencing status "
f"to {study.sequencing_status}"
)
event = Event(study=study, description=message, event_type="ST_UPD")
Expand All @@ -593,8 +591,7 @@ class Arguments:
description="The ID of the study to remove the collaborator from",
)
data = UpdateIngestionStatusInput(
required=True,
description="Input for the study's ingestion status"
required=True, description="Input for the study's ingestion status"
)

study = graphene.Field(StudyNode)
Expand All @@ -621,7 +618,7 @@ def mutate(self, info, study, data):

# Log an event
message = (
f"{user.username} study {study.kf_id}'s ingestion status "
f"{user.display_name} study {study.kf_id}'s ingestion status "
f"to {study.ingestion_status}"
)
event = Event(study=study, description=message, event_type="IN_UPD")
Expand All @@ -642,8 +639,7 @@ class Arguments:
description="The ID of the study to remove the collaborator from",
)
data = UpdatePhenotypeStatusInput(
required=True,
description="Input for the study's phenotype status"
required=True, description="Input for the study's phenotype status"
)

study = graphene.Field(StudyNode)
Expand All @@ -670,7 +666,7 @@ def mutate(self, info, study, data):

# Log an event
message = (
f"{user.username} study {study.kf_id}'s phenotype status "
f"{user.display_name} study {study.kf_id}'s phenotype status "
f"to {study.phenotype_status}"
)
event = Event(study=study, description=message, event_type="PH_UPD")
Expand Down
1 change: 1 addition & 0 deletions creator/users/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def _get_study_id(self, info):


class UserNode(DjangoObjectType):
display_name = graphene.String(source="display_name")
roles = graphene.List(
graphene.String, description="Roles that the user has"
)
Expand Down

0 comments on commit c9d459b

Please sign in to comment.