Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URN schemes to variable completions #1067

Merged
merged 18 commits into from Feb 1, 2017

Conversation

norkans7
Copy link

No description provided.

Copy link
Member

@ericnewcomer ericnewcomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case here?

# a Twitter channel
Channel.create(self.org, self.user, None, 'TT')
completions.insert(-2, dict(name="contact.%s" % 'twitter', display="Contact %s" % "Twitter handle"))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the substitution here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completions is a list and I want to keep the order right so I inserted before the 2 dict representing the contact fields above

@norkans7
Copy link
Author

This is to allow @contact.twitter to be auto completed currently it was not while their values are included in the contact message_context

@norkans7 norkans7 self-assigned this Jan 31, 2017

if not urn and scheme is not None:
return ''

if org.is_anon:
return self.anon_identifier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this doing here? This is returning a function pointer isn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that it would make sense for us to return a generic masked version of the URN here. (IE, just ******** for anon orgs). Though empty string if the contact doesn't have an URN of that scheme.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were are return "000173823" for anon orgs not *******

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, that seems wrong to return for @contact.tel don't you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I can change this to make sure it is ******** only in the message context(scheme is not None) and leave the other place be 00000173823 for the contacts views

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ya the contact views should maybe be switching higher up on anon orgs.. (ie deciding to show the ID before calling get_urn_display)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use a template tag that calls get_urn_display

@@ -789,7 +790,12 @@ def render_to_response(self, context, **response_kwargs):
dict(name='contact.uuid', display=six.text_type(_("Contact UUID"))),
dict(name='new_contact', display=six.text_type(_('New Contact')))
]
contact_variables += [dict(name="contact.%s" % field.key, display=field.label) for field in ContactField.objects.filter(org=org, is_active=True)]

contact_variables += [dict(name="contact.%s" % scheme, display="Contact %s" % label) for scheme, label in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localize?

@rowanseymour
Copy link
Member

General thought: Contact.get_display and Contact.get_urn_display need to clear up who does what. Currently...

  • get_display returns the name if its set, otherwise the pk if org is anon, or a URN.
  • get_urn_display returns a URN of the requested type, or nothing if there isn't one... except if the org is anon if returns the pk regardless of the contact's URNs.

I'm thinking get_urn_display should always return a URN or empty or a masked URN. For any place we want this to sometimes be the pk, that logic should be elsewhere.

if org.is_anon:
if scheme is not None:
return Contact.HIDDEN_URN_MASK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already have ContactURN.ANON_MASK for this

@@ -1736,8 +1736,13 @@ def get_urn_display(self, org=None, scheme=None, formatted=True, international=F
if not org:
org = self.org

urn = self.get_urn(scheme)

if not urn and scheme is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if get_urn_display is called with no scheme on an anon org on a contact which has no URNs. Won't it return the ANON_MASK instead of ''?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is what is expected, we want to have '' only in the contact message context which is where we call the method with the scheme

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that should be as expected.. get_urn_display should only return the ANON_MASK if there is an URN that exists for the contact. You are saying if there is no URN on a contact we'll still get the ANON_MASK instead of ''?

@@ -66,7 +66,8 @@ def format_urn(urn_or_contact, org):
return urn_val if urn_val != ContactURN.ANON_MASK else '\u2022' * 8 # replace *'s with prettier HTML entity
elif isinstance(urn_or_contact, Contact):
# will render contact's highest priority URN
return urn_or_contact.get_urn_display(org=org, international=True)
urn_val = urn_or_contact.get_display(org=org)
return urn_val if urn_val != ContactURN.ANON_MASK else '\u2022' * 8 # replace *'s with prettier HTML entity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should be calling this method something different. format_urn sure sounds like it should return a URN.

This should only accept an URN as an argument, and we should have a filter for format_contact for that case that shows the anon id for anon orgs, otherwise the highest priority URN.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@@ -789,7 +790,13 @@ def render_to_response(self, context, **response_kwargs):
dict(name='contact.uuid', display=six.text_type(_("Contact UUID"))),
dict(name='new_contact', display=six.text_type(_('New Contact')))
]
contact_variables += [dict(name="contact.%s" % field.key, display=field.label) for field in ContactField.objects.filter(org=org, is_active=True)]

contact_variables += [dict(name="contact.%s" % scheme, display=six.text_type(_("Contact %s" % label)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will read "Contact Facebook" or "Contact Twitter" ya? Seems we might want something more like "Contact Facebook URN" and "Contact Twitter URN" instead.. Though from a naming perspective that is slightly problematic since these won't be full URNs but just the paths right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we'll get "Contact Facebook identifier" or "Contact Twitter handle"

as seen on
https://github.com/nyaruka/rapidpro/blob/master/temba/contacts/models.py#L61

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok great.

@norkans7
Copy link
Author

norkans7 commented Feb 1, 2017

@nicpottier this is updated please review

if org.is_anon:
return self.anon_identifier
return ContactURN.ANON_MASK

urn = self.get_urn(scheme)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to call this again..

raise ValueError('Must be a URN or contact')
def format_urn(urn, org):
urn_val = urn.get_display(org=org, international=True)
return urn_val if urn_val != ContactURN.ANON_MASK else '\u2022' * 8 # replace *'s with prettier HTML entity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not use this kind of operator when we want to comment things, just use a normal if block here.

@@ -789,7 +790,13 @@ def render_to_response(self, context, **response_kwargs):
dict(name='contact.uuid', display=six.text_type(_("Contact UUID"))),
dict(name='new_contact', display=six.text_type(_('New Contact')))
]
contact_variables += [dict(name="contact.%s" % field.key, display=field.label) for field in ContactField.objects.filter(org=org, is_active=True)]

contact_variables += [dict(name="contact.%s" % scheme, display=six.text_type(_("Contact %s" % label)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok great.

@nicpottier
Copy link
Collaborator

Doh, coverage!

@norkans7
Copy link
Author

norkans7 commented Feb 1, 2017

that line can never be reached, coverage should be good now

Copy link
Collaborator

@nicpottier nicpottier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:feelsgood:

@nicpottier nicpottier merged commit fb53fd2 into master Feb 1, 2017
@nicpottier nicpottier removed the review label Feb 1, 2017
@nicpottier nicpottier deleted the add-urn-schemes-to-completions branch February 1, 2017 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants