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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered by a BSD-style
3 # license that can be found in the LICENSE file or at
4 # https://developers.google.com/open-source/licenses/bsd
5
6 """This is a starring servlet for users and projects."""
7
8 import logging
9
10 from framework import jsonfeed
11 from framework import monorailrequest
12
13 USER_STARS_SCOPE = 'users'
14 PROJECT_STARS_SCOPE = 'projects'
15
16
17 class SetStarsFeed(jsonfeed.JsonFeed):
18 """Process an AJAX request to (un)set a star on a project or user."""
19
20 def HandleRequest(self, mr):
21 """Retrieves the star persistence object and sets a star."""
22 starrer_id = mr.auth.user_id
23 item = mr.GetParam('item') # a project name or a user ID number
24 scope = mr.GetParam('scope')
25 starred = bool(mr.GetIntParam('starred'))
26 logging.info('Handling user set star request: %r %r %r %r',
27 starrer_id, item, scope, starred)
28
29 if scope == PROJECT_STARS_SCOPE:
30 project = self.services.project.GetProjectByName(mr.cnxn, item)
31 self.services.project_star.SetStar(
32 mr.cnxn, project.project_id, starrer_id, starred)
33
34 elif scope == USER_STARS_SCOPE:
35 user_id = int(item)
36 self.services.user_star.SetStar(mr.cnxn, user_id, starrer_id, starred)
37
38 else:
39 raise monorailrequest.InputException('unexpected star scope: %s' % scope)
40
41 return {
42 'starred': starred,
43 }
OLDNEW
« 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