Skip to content

Commit

Permalink
better handle Anonymous users when login is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
armish committed Sep 3, 2015
1 parent d5bac7d commit e6e5609
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions cycledash/api/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def get(self, run_id):
@marshal_with(CommentFields)
def post(self, run_id):
"""Create a comment."""
print current_user
with tables(db.engine, 'user_comments') as (con, comments):
q = comments.insert().values(
vcf_id=run_id,
Expand Down
18 changes: 18 additions & 0 deletions cycledash/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ def is_anonymous(self):
def get_id(self):
return unicode(self['id'])

class AnonymousUser(dict):
def __init__(self):
self['id'] = None
self['username'] = u'Anonymous'

def is_authenticated(self):
return False

def is_active(self):
return False

def is_anonymous(self):
return True

def get_id(self):
return self['id']

login_manager.anonymous_user = AnonymousUser

def wrap_user(user):
"""Wraps user record returned from the database in a class providing methods
Expand Down
5 changes: 2 additions & 3 deletions tests/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ SELECT pg_catalog.setval('task_states_id_seq', 2, true);
-- Data for Name: user_comments; Type: TABLE DATA; Schema: public; Owner: tavi
--

COPY user_comments (id, vcf_id, sample_name, contig, "position", reference, alternates, comment_text, author_name, created, last_modified) FROM stdin;
COPY user_comments (id, vcf_id, sample_name, contig, "position", reference, alternates, comment_text, user_id, created, last_modified) FROM stdin;
1 1 NORMAL 20 61795 G T This is a comment on the second row! \N 2015-03-24 15:29:09.615967+00 2015-03-11 23:33:33.951753+00
2 1 NORMAL 20 65900 G A *This* is a comment with [Markdown](http://daringfireball.net/projects/markdown/syntax). \N 2015-03-24 15:29:09.615967+00 2015-03-11 23:34:18.19118+00
3 1 TUMOR 20 61795 G T *This* is a comment on the first variant with [Markdown](http://daringfireball.net/projects/markdown/syntax).\n \N 2015-03-24 15:29:09.615967+00 2015-03-12 15:30:20.570952+00
4 1 NORMAL 20 61795 G T This is another comment on the second row! \N 2015-03-24 17:40:44.984191+00 2015-03-24 17:40:44.984191+00
6 1 TUMOR 20 61795 G T This is a comment without Markdown by Bob! Bob 2015-03-24 17:46:40.962213+00 2015-03-24 17:46:40.962213+00
6 1 TUMOR 20 61795 G T This is a comment without Markdown by Bob! \N 2015-03-24 17:46:40.962213+00 2015-03-24 17:46:40.962213+00
5 1 TUMOR 20 61795 G T This is a comment without Markdown! \N 2015-03-24 17:43:23.497883+00 2015-03-24 17:43:23.497883+00
\.

Expand All @@ -136,4 +136,3 @@ SELECT pg_catalog.setval('vcfs_id_seq', 2, true);
--
-- PostgreSQL database dump complete
--

0 comments on commit e6e5609

Please sign in to comment.