From e6e560982d67fcaaeebbd78fdad0d0c2915fe394 Mon Sep 17 00:00:00 2001 From: "B. Arman Aksoy" Date: Thu, 3 Sep 2015 13:09:39 -0400 Subject: [PATCH] better handle Anonymous users when login is disabled --- cycledash/api/comments.py | 1 + cycledash/auth.py | 18 ++++++++++++++++++ tests/data.sql | 5 ++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cycledash/api/comments.py b/cycledash/api/comments.py index ddccab6..2a09922 100644 --- a/cycledash/api/comments.py +++ b/cycledash/api/comments.py @@ -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, diff --git a/cycledash/auth.py b/cycledash/auth.py index 79fd568..6c0a478 100644 --- a/cycledash/auth.py +++ b/cycledash/auth.py @@ -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 diff --git a/tests/data.sql b/tests/data.sql index 553ea26..b9d4b5c 100644 --- a/tests/data.sql +++ b/tests/data.sql @@ -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 \. @@ -136,4 +136,3 @@ SELECT pg_catalog.setval('vcfs_id_seq', 2, true); -- -- PostgreSQL database dump complete -- -