Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Unified Diff: appengine/monorail/features/stars.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/monorail/features/spammodel.py ('k') | appengine/monorail/features/test/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/monorail/features/stars.py
diff --git a/appengine/monorail/features/stars.py b/appengine/monorail/features/stars.py
new file mode 100644
index 0000000000000000000000000000000000000000..83d7e1ced17b23a4f51c35c4c5f724c8c39fc876
--- /dev/null
+++ b/appengine/monorail/features/stars.py
@@ -0,0 +1,43 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""This is a starring servlet for users and projects."""
+
+import logging
+
+from framework import jsonfeed
+from framework import monorailrequest
+
+USER_STARS_SCOPE = 'users'
+PROJECT_STARS_SCOPE = 'projects'
+
+
+class SetStarsFeed(jsonfeed.JsonFeed):
+ """Process an AJAX request to (un)set a star on a project or user."""
+
+ def HandleRequest(self, mr):
+ """Retrieves the star persistence object and sets a star."""
+ starrer_id = mr.auth.user_id
+ item = mr.GetParam('item') # a project name or a user ID number
+ scope = mr.GetParam('scope')
+ starred = bool(mr.GetIntParam('starred'))
+ logging.info('Handling user set star request: %r %r %r %r',
+ starrer_id, item, scope, starred)
+
+ if scope == PROJECT_STARS_SCOPE:
+ project = self.services.project.GetProjectByName(mr.cnxn, item)
+ self.services.project_star.SetStar(
+ mr.cnxn, project.project_id, starrer_id, starred)
+
+ elif scope == USER_STARS_SCOPE:
+ user_id = int(item)
+ self.services.user_star.SetStar(mr.cnxn, user_id, starrer_id, starred)
+
+ else:
+ raise monorailrequest.InputException('unexpected star scope: %s' % scope)
+
+ return {
+ 'starred': starred,
+ }
« no previous file with comments | « appengine/monorail/features/spammodel.py ('k') | appengine/monorail/features/test/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698