Re: [PATCH 4/5] views: Provide a way to view, (re)generate tokens

2017-06-14 Thread Stephen Finucane
On Wed, 2017-06-14 at 17:57 +1000, Daniel Axtens wrote:
> Daniel Axtens  writes:
> 
> > Hi Stephen and Andrew,
> > 
> > I've installed this on py[23].patchwork.dja.id.au
> > 
> > > diff --git a/htdocs/css/style.css b/htdocs/css/style.css
> > > index 5218f6d..af2f073 100644
> > > --- a/htdocs/css/style.css
> > > +++ b/htdocs/css/style.css
> > > @@ -369,7 +369,6 @@ table.form th.headerrow {
> > >  }
> > >  
> > >  table.form th {
> > > - font-weight: normal;
> > 
> > What does this change?

It changes the 'API Token:' label on '/user'. I wasn't able to see any other 
side-effects.

> > 
> > >   text-align: left;
> > >   vertical-align: top;
> > >   padding-top: 0.6em;
> > > diff --git a/patchwork/templates/patchwork/profile.html
> > > b/patchwork/templates/patchwork/profile.html
> > > index f976195..2005687 100644
> > > --- a/patchwork/templates/patchwork/profile.html
> > > +++ b/patchwork/templates/patchwork/profile.html
> > > @@ -134,7 +134,35 @@ address.
> > >  
> > >  
> > >  Authentication
> > > -Change password
> > > +
> > > +
> > > + 
> > > +  Password:
> > > +  Change password
> > > + 
> > > + 
> > > +  API Token:
> > > +  
> > > +   {% if api_token %}
> > > +   
> > > +    > > +data-clipboard-target="#token">Copy
> > 
> > This doesn't work for me in Chrome:
> > 
> > Uncaught ReferenceError: Clipboard is not defined
> > at HTMLDocument. (py3.patchwork.dja.id.au/:26)
> > at c (jquery-1.10.1.min.js:4)
> > at Object.fireWith [as resolveWith] (jquery-1.10.1.min.js:4)
> > at Function.ready (jquery-1.10.1.min.js:4)
> > at HTMLDocument.q (jquery-1.10.1.min.js:4)
> 
> Ah, this would be due to me forgetting to run collectstatic.
>
> But even when I do that, I still get errors from a broken
> 
> clipboard.min.js:
> Uncaught SyntaxError: Unexpected end of input
> 
> Any thoughts?

I copied and pasted [1] to [2] and it looks like that file isn't complete. I 
suspect this was
because it exceeded the 998 character SMTP limit (I ignored that error for 
git-send-email :)) Can
you either (a) download clipboard.min.js from the original site [3], (b) clone 
the version I have
pushed to my working repo [4], or (c) wait for the next rc which I'll be 
pushing imminently. 
Any of these should resolve the issue.

> Regards,
> Daniel
> > 
> > The rest seems to work fine, I can create and use tokens (as far as I
> > can tell - I haven't tried to do anything with the permissions they
> > grant.)
> > 
> > > +   {% endif %}
> > > +  
> > > + 
> > > +  
> > > +  
> > > +   
> > 
> > That should probably be "{% url" -- a space between % and url.

I don't think it matters, but I've fixed it in the pushed version.

Thanks for the reviews, folks,

Stephen

[1] view-source:https://py3.patchwork.dja.id.au/static/js/clipboard.min.js
[2] http://jshint.com/
[3] https://github.com/zenorocha/clipboard.js/archive/v1.7.1.zip
[4] https://github.com/stephenfin/patchwork/tree/token
___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


Re: [PATCH 4/5] views: Provide a way to view, (re)generate tokens

2017-06-14 Thread Daniel Axtens
Daniel Axtens  writes:

> Hi Stephen and Andrew,
>
> I've installed this on py[23].patchwork.dja.id.au
>
>> diff --git a/htdocs/css/style.css b/htdocs/css/style.css
>> index 5218f6d..af2f073 100644
>> --- a/htdocs/css/style.css
>> +++ b/htdocs/css/style.css
>> @@ -369,7 +369,6 @@ table.form th.headerrow {
>>  }
>>  
>>  table.form th {
>> -font-weight: normal;
> What does this change?
>
>>  text-align: left;
>>  vertical-align: top;
>>  padding-top: 0.6em;
>> diff --git a/patchwork/templates/patchwork/profile.html 
>> b/patchwork/templates/patchwork/profile.html
>> index f976195..2005687 100644
>> --- a/patchwork/templates/patchwork/profile.html
>> +++ b/patchwork/templates/patchwork/profile.html
>> @@ -134,7 +134,35 @@ address.
>>  
>>  
>>  Authentication
>> -Change password
>> +
>> +
>> + 
>> +  Password:
>> +  Change password
>> + 
>> + 
>> +  API Token:
>> +  
>> +   {% if api_token %}
>> +   
>> +   > +data-clipboard-target="#token">Copy
>
> This doesn't work for me in Chrome:
>
> Uncaught ReferenceError: Clipboard is not defined
> at HTMLDocument. (py3.patchwork.dja.id.au/:26)
> at c (jquery-1.10.1.min.js:4)
> at Object.fireWith [as resolveWith] (jquery-1.10.1.min.js:4)
> at Function.ready (jquery-1.10.1.min.js:4)
> at HTMLDocument.q (jquery-1.10.1.min.js:4)
Ah, this would be due to me forgetting to run collectstatic.

But even when I do that, I still get errors from a broken

clipboard.min.js:
Uncaught SyntaxError: Unexpected end of input

Any thoughts?

Regards,
Daniel
>
> The rest seems to work fine, I can create and use tokens (as far as I
> can tell - I haven't tried to do anything with the permissions they
> grant.)
>
>> +   {% endif %}
>> +  
>> + 
>> +  
>> +  
>> +   
> That should probably be "{% url" -- a space between % and url.
>
> Regards,
> Daniel
>
>> +{% csrf_token %}
>> +{% if api_token %}
>> +
>> +{% else %}
>> +
>> +{% endif %}
>> +   
>> +  
>> + 
>> +
>>  
>>  
>>  
>> diff --git a/patchwork/urls.py b/patchwork/urls.py
>> index be996c0..285d565 100644
>> --- a/patchwork/urls.py
>> +++ b/patchwork/urls.py
>> @@ -235,6 +235,10 @@ if settings.ENABLE_REST_API:
>>  
>>  urlpatterns += [
>>  url(r'^api/(?:(?P(1.0))/)?', include(api_patterns)),
>> +
>> +# token change
>> +url(r'^user/generate-token/$', user_views.generate_token,
>> +name='generate_token'),
>>  ]
>>  
>>  
>> diff --git a/patchwork/views/user.py b/patchwork/views/user.py
>> index 375d3d9..d99fedf 100644
>> --- a/patchwork/views/user.py
>> +++ b/patchwork/views/user.py
>> @@ -41,6 +41,7 @@ from patchwork.models import Person
>>  from patchwork.models import Project
>>  from patchwork.models import State
>>  from patchwork.views import generic_list
>> +from patchwork.views import utils
>>  
>>  
>>  def register(request):
>> @@ -126,6 +127,7 @@ def profile(request):
>>  .extra(select={'is_optout': optout_query})
>>  context['linked_emails'] = people
>>  context['linkform'] = EmailForm()
>> +context['api_token'] = request.user.profile.token
>>  
>>  return render(request, 'patchwork/profile.html', context)
>>  
>> @@ -232,3 +234,9 @@ def todo_list(request, project_id):
>>  context['action_required_states'] = \
>>  State.objects.filter(action_required=True).all()
>>  return render(request, 'patchwork/todo-list.html', context)
>> +
>> +
>> +@login_required
>> +def generate_token(request):
>> +utils.regenerate_token(request.user)
>> +return HttpResponseRedirect(reverse('user-profile'))
>> -- 
>> 2.9.4
>>
>> ___
>> Patchwork mailing list
>> Patchwork@lists.ozlabs.org
>> https://lists.ozlabs.org/listinfo/patchwork
___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


Re: [PATCH 4/5] views: Provide a way to view, (re)generate tokens

2017-06-14 Thread Daniel Axtens
Hi Stephen and Andrew,

I've installed this on py[23].patchwork.dja.id.au

> diff --git a/htdocs/css/style.css b/htdocs/css/style.css
> index 5218f6d..af2f073 100644
> --- a/htdocs/css/style.css
> +++ b/htdocs/css/style.css
> @@ -369,7 +369,6 @@ table.form th.headerrow {
>  }
>  
>  table.form th {
> - font-weight: normal;
What does this change?

>   text-align: left;
>   vertical-align: top;
>   padding-top: 0.6em;
> diff --git a/patchwork/templates/patchwork/profile.html 
> b/patchwork/templates/patchwork/profile.html
> index f976195..2005687 100644
> --- a/patchwork/templates/patchwork/profile.html
> +++ b/patchwork/templates/patchwork/profile.html
> @@ -134,7 +134,35 @@ address.
>  
>  
>  Authentication
> -Change password
> +
> +
> + 
> +  Password:
> +  Change password
> + 
> + 
> +  API Token:
> +  
> +   {% if api_token %}
> +   
> ++data-clipboard-target="#token">Copy

This doesn't work for me in Chrome:

Uncaught ReferenceError: Clipboard is not defined
at HTMLDocument. (py3.patchwork.dja.id.au/:26)
at c (jquery-1.10.1.min.js:4)
at Object.fireWith [as resolveWith] (jquery-1.10.1.min.js:4)
at Function.ready (jquery-1.10.1.min.js:4)
at HTMLDocument.q (jquery-1.10.1.min.js:4)

The rest seems to work fine, I can create and use tokens (as far as I
can tell - I haven't tried to do anything with the permissions they
grant.)

> +   {% endif %}
> +  
> + 
> +  
> +  
> +   
That should probably be "{% url" -- a space between % and url.

Regards,
Daniel

> +{% csrf_token %}
> +{% if api_token %}
> +
> +{% else %}
> +
> +{% endif %}
> +   
> +  
> + 
> +
>  
>  
>  
> diff --git a/patchwork/urls.py b/patchwork/urls.py
> index be996c0..285d565 100644
> --- a/patchwork/urls.py
> +++ b/patchwork/urls.py
> @@ -235,6 +235,10 @@ if settings.ENABLE_REST_API:
>  
>  urlpatterns += [
>  url(r'^api/(?:(?P(1.0))/)?', include(api_patterns)),
> +
> +# token change
> +url(r'^user/generate-token/$', user_views.generate_token,
> +name='generate_token'),
>  ]
>  
>  
> diff --git a/patchwork/views/user.py b/patchwork/views/user.py
> index 375d3d9..d99fedf 100644
> --- a/patchwork/views/user.py
> +++ b/patchwork/views/user.py
> @@ -41,6 +41,7 @@ from patchwork.models import Person
>  from patchwork.models import Project
>  from patchwork.models import State
>  from patchwork.views import generic_list
> +from patchwork.views import utils
>  
>  
>  def register(request):
> @@ -126,6 +127,7 @@ def profile(request):
>  .extra(select={'is_optout': optout_query})
>  context['linked_emails'] = people
>  context['linkform'] = EmailForm()
> +context['api_token'] = request.user.profile.token
>  
>  return render(request, 'patchwork/profile.html', context)
>  
> @@ -232,3 +234,9 @@ def todo_list(request, project_id):
>  context['action_required_states'] = \
>  State.objects.filter(action_required=True).all()
>  return render(request, 'patchwork/todo-list.html', context)
> +
> +
> +@login_required
> +def generate_token(request):
> +utils.regenerate_token(request.user)
> +return HttpResponseRedirect(reverse('user-profile'))
> -- 
> 2.9.4
>
> ___
> Patchwork mailing list
> Patchwork@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork