Exemple #1
0
 def send_connection_email(self):
     user = self.request.user
     connection_name = self.app.verbose_name
     activity_url = full_url(
         reverse('activity-management',
                 kwargs={'source': source_to_url_slug(self.source)}))
     send_connection_email(user, connection_name, activity_url)
Exemple #2
0
def access_token_post_save_cb(sender, instance, created, raw, update_fields,
                              **kwargs):
    """
    Email a user to notify them of any new incoming connections.

    This signal is only used for projects using our deprecated OAuth2 method:
    American Gut, Harvard Personal Genome Project, and Wild Life of Our Homes.
    """
    if raw or not created:
        return

    # This separates our custom OAuth2 apps from direct sharing projects.
    try:
        app_label, _ = [
            x for x in get_source_labels_and_configs()
            if x[1].verbose_name == instance.application.name
        ][0]
    except IndexError:
        return

    # only notify the user the first time they connect
    if AccessToken.objects.filter(application=instance.application,
                                  user=instance.user).count() > 1:
        return

    url_slug = source_to_url_slug(app_label)
    activity_url = full_url(
        reverse('activity-management', kwargs={'source': url_slug}))

    send_connection_email(user=instance.user,
                          connection_name=instance.application.name,
                          activity_url=activity_url)
Exemple #3
0
def user_social_auth_post_save_cb(sender, instance, created, raw,
                                  update_fields, **kwargs):
    """
    Email a user to notify them of any new outgoing connections.
    """
    if raw or not created:
        return

    # only notify the user the first time they connect
    if UserSocialAuth.objects.filter(provider=instance.provider,
                                     user=instance.user).count() > 1:
        return

    # Look up the related name and URL. Note, we've used app names that match
    # the UserSocialAuth 'provider' field in Python Social Auth.
    app_config = dict(get_source_labels_and_configs())[instance.provider]
    url_slug = source_to_url_slug(app_config.label)
    activity_url = full_url(
        reverse('activity-management', kwargs={'source': url_slug}))
    send_connection_email(user=instance.user,
                          connection_name=app_config.verbose_name,
                          activity_url=activity_url)
Exemple #4
0
    def get(self, request, *args, **kwargs):
        """
        If user started on OH, go to research data. Otherwise offer choice.

        If an origin parameter exists and indicates the user started on the
        connection process on Open Humans, then send them to their research
        data page.

        Otherwise, assume the user started on the study site. Offer the option
        to return, or to continue to Open Humans.
        """
        redirect_url = reverse('my-member-data')
        origin = request.GET.get('origin', '')

        # Search apps to find the study app specified by the URL 'name' slug.
        study_name = kwargs.pop('name').replace('-', '_')
        app_configs = apps.get_app_configs()

        for app_config in app_configs:
            if app_config.name.endswith(study_name):
                self.study_verbose_name = app_config.verbose_name
                self.badge_url = '{}/images/badge.png'.format(study_name)
                self.return_url = app_config.href_connect
                redirect_url = reverse(
                    'activity-management',
                    kwargs={'source': source_to_url_slug(app_config.label)})

        if origin == 'open-humans':
            return HttpResponseRedirect(redirect_url)

        if self.study_verbose_name:
            return super(StudyConnectionReturnView,
                         self).get(request, *args, **kwargs)
        else:
            # TODO: Unexpected! Report error, URL should match study app.
            return HttpResponseRedirect(redirect_url)
Exemple #5
0
 def get_success_url(self):
     """
     Direct to relevant activity page.
     """
     url_slug = source_to_url_slug(self.source)
     return reverse('activity-management', kwargs={'source': url_slug})
 def get_success_url(self):
     """
     Direct to relevant activity page.
     """
     url_slug = source_to_url_slug(self.source)
     return reverse("activity-management", kwargs={"source": url_slug})