| OLD | NEW |
| 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
| 3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 from google.appengine.api import oauth | 5 from google.appengine.api import oauth |
| 6 from google.appengine.api import users | 6 from google.appengine.api import users |
| 7 | 7 |
| 8 import handlers | 8 import handlers |
| 9 import models | 9 import models |
| 10 | 10 |
| 11 class PackageUploaders(object): | 11 class PackageUploaders(object): |
| 12 """The handler for /api/packages/*/uploaders/*.""" | 12 """The handler for /api/packages/*/uploaders/*.""" |
| 13 | 13 |
| 14 @handlers.api(1) | 14 @handlers.api(1) |
| 15 @handlers.requires_uploader | 15 @handlers.requires_uploader |
| 16 @models.transactional | 16 @models.transactional |
| 17 def create(self, package_id, email): | 17 def create(self, package_id, email): |
| 18 """Add a new uploader for this package. | 18 """Add a new uploader for this package. |
| 19 | 19 |
| 20 Only other uploaders may add new uploaders.""" | 20 Only other uploaders may add new uploaders.""" |
| 21 | 21 |
| 22 package = handlers.request().package | 22 package = handlers.request().package |
| 23 user_to_add = users.User(email) | 23 user_to_add = users.User(email) |
| 24 if package.has_uploader(user_to_add): | 24 if package.has_uploader(user_to_add): |
| 25 handlers.http_error( | 25 handlers.http_error( |
| 26 400, "User '%s' is already an uploader for package '%s'." % | 26 400, "User '%s' is already an uploader for package '%s'." % |
| 27 (email, package.name)) | 27 (email, package.name)) |
| 28 | 28 |
| 29 package.uploaders.append(user_to_add) | 29 package.uploaders.append(user_to_add) |
| 30 package.temp_synchronize_uploaders_to_uploaderemails() |
| 30 package.put() | 31 package.put() |
| 31 package.invalidate_cache() | 32 package.invalidate_cache() |
| 32 return handlers.json_success( | 33 return handlers.json_success( |
| 33 "'%s' added as an uploader for package '%s'." % | 34 "'%s' added as an uploader for package '%s'." % |
| 34 (email, package.name)) | 35 (email, package.name)) |
| 35 | 36 |
| 36 @handlers.api(1) | 37 @handlers.api(1) |
| 37 @handlers.requires_uploader | 38 @handlers.requires_uploader |
| 38 @models.transactional | 39 @models.transactional |
| 39 def delete(self, package_id, id, format=None): | 40 def delete(self, package_id, id, format=None): |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 (user_to_delete.nickname(), package.name)) | 54 (user_to_delete.nickname(), package.name)) |
| 54 | 55 |
| 55 if len(package.uploaders) == 1: | 56 if len(package.uploaders) == 1: |
| 56 handlers.http_error( | 57 handlers.http_error( |
| 57 400, ("Package '%s' only has one uploader, so that uploader " + | 58 400, ("Package '%s' only has one uploader, so that uploader " + |
| 58 "can't be removed.") % package.name) | 59 "can't be removed.") % package.name) |
| 59 | 60 |
| 60 email_to_delete = user_to_delete.email().lower() | 61 email_to_delete = user_to_delete.email().lower() |
| 61 package.uploaders = [uploader for uploader in package.uploaders | 62 package.uploaders = [uploader for uploader in package.uploaders |
| 62 if uploader.email().lower() != email_to_delete] | 63 if uploader.email().lower() != email_to_delete] |
| 64 package.temp_synchronize_uploaders_to_uploaderemails() |
| 63 package.put() | 65 package.put() |
| 64 package.invalidate_cache() | 66 package.invalidate_cache() |
| 65 return handlers.json_success( | 67 return handlers.json_success( |
| 66 "'%s' is no longer an uploader for package '%s'." % | 68 "'%s' is no longer an uploader for package '%s'." % |
| 67 (id, package.name)) | 69 (id, package.name)) |
| OLD | NEW |