OLD | NEW |
(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 } |
OLD | NEW |