[ckan-dev] Disqus comments plugin SSO enhancement

Koebrick, Andrew (MNIT) andrew.koebrick at state.mn.us
Wed Dec 3 17:01:40 UTC 2014


I have what appears to be a functional fork of the ckanext-disqus extension that integrates the Disqus Single Sign On.  This allows CKAN users to comment without having to establish a separate username/password with Disqus.  If anyone would like to try installing it, it is at:

https://github.com/exlibris/ckanext-disqus

To use SSO you need to jump through various hoops with Disqus (i.e. register your application, get keys...) and them put the keys in your CKAN .ini file.  See my documentation for more info.  The extension should also still work in the prior fashion if the required keys are not in the .ini file.

I read through the documentation on contributing to CKAN and making pull requests (http://docs.ckan.org/en/latest/contributing/pull-requests.html) and unfortunately was not able to follow the steps exactly: I was unable to create a branch on the main repo prior to forking.  So I just forked and made my changes to the master.  If the maintainers of the main repo would like to integrate these changes into the main extension, and I can do anything at my end to make this easier just let me know.  This is my first attempt at both writing python and contributing to a github project, so suggestions on how to improve my coding  and git skills are welcome.

Andrew Koebrick



-----Original Message-----
From: ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org] On Behalf Of Adrià Mercader
Sent: Friday, November 14, 2014 5:03 AM
To: CKAN Development Discussions
Subject: Re: [ckan-dev] Disqus comments plugin SSO enhancement

Hi Andrew,

To access properties in c you need to access them like `c.user`. This gives you the user name.

Passing data in c to the templates is not the recommended method any more. Passing variables as in here is recommended:

https://github.com/ckan/ckanext-disqus/blob/master/ckanext/disqus/plugin.py#L92:L96

These can be later accessed from the templates directly:

https://github.com/ckan/ckanext-disqus/blob/master/ckanext/disqus/templates/disqus_comments.html#L5:L6

In your case you need to call `user_show` to get all the extra details you need, something like this should get you started:


    user_dict = p.toolkit.get_action('user_show')({'keep_email':
True}, {'id': c.name})

    data = {
        ...
       'user_id: user_dict['id'],
       'user_name': user_dict['name'],
       'user_email': user_dict['email'],
    }
return p.toolkit.render_snippet('disqus_comments.html', data)


Hope this helps,

Adrià


On 13 November 2014 19:02, Koebrick, Andrew (MNIT) <andrew.koebrick at state.mn.us> wrote:
> I am trying to create a fork of the ckanext-disqus extension that 
> makes use of the Single Sign On (SSO) which Disqus offers.  Rather 
> than have users have to sign into the Disqus service, local user data is sent to Disqus.
> For more info see:
> https://help.disqus.com/customer/portal/articles/236206-integrating-si
> ngle-sign-on
>
>
>
> However, I have having a difficult time accessing the ckan user model 
> from the extension.  Could somebody with a better knowledge of CKAN 
> and python give me  a pointer or two?  I seem to be unable to access to context object.
> I have been trying things like the below with no luck;
>
>
>
>     def disqus_comments(cls):
> #Original code
>
>         ''' Adds Disqus Comments to the page.'''
> #Original code
>
>         # we need to create an identifier #Original code
>
>         c = p.toolkit.c
> #Original code
>
>
>
>        user_name = c['user']
> #My addition … It fails.
>
>        user_name = context['user']
> #Another try. as seen in the extension tutorial… It fails.
>
>
>
>
>
> I need to access to user’s name, email, and Id.
>
>
>
> Thanks in advance for any pointers anyone can provide.  If I get SSO 
> hooked up in my fork, I will happily share my code back to the main extension.
>
>
>
> Andrew Koebrick
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org
https://lists.okfn.org/mailman/listinfo/ckan-dev
Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev


More information about the ckan-dev mailing list