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

Side by Side Diff: app/handlers/api/package_uploaders.py

Issue 815973002: Remove legacy Package.uploaders PackageVersion.{uploader,readme,changelog} properties (Closed) Base URL: https://github.com/dart-lang/pub-dartlang.git@master
Patch Set: Small fix in changelog/readme handling for new uploads Created 6 years 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 | « app/handlers/__init__.py ('k') | app/handlers/api/package_versions.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 if package.has_uploader_email(email):
24 if package.has_uploader(user_to_add):
25 handlers.http_error( 24 handlers.http_error(
26 400, "User '%s' is already an uploader for package '%s'." % 25 400, "User '%s' is already an uploader for package '%s'." %
27 (email, package.name)) 26 (email, package.name))
28 27
29 package.uploaders.append(user_to_add) 28 package.uploaderEmails.append(email)
30 package.temp_synchronize_uploaders_to_uploaderemails()
31 package.put() 29 package.put()
32 package.invalidate_cache() 30 package.invalidate_cache()
33 return handlers.json_success( 31 return handlers.json_success(
34 "'%s' added as an uploader for package '%s'." % 32 "'%s' added as an uploader for package '%s'." %
35 (email, package.name)) 33 (email, package.name))
36 34
37 @handlers.api(1) 35 @handlers.api(1)
38 @handlers.requires_uploader 36 @handlers.requires_uploader
39 @models.transactional 37 @models.transactional
40 def delete(self, package_id, id, format=None): 38 def delete(self, package_id, id, format=None):
41 """Delete one of this package's uploaders. 39 """Delete one of this package's uploaders.
42 40
43 Only uploaders may delete uploaders. If only one uploader remains, that 41 Only uploaders may delete uploaders. If only one uploader remains, that
44 uploader may not be deleted until a new one is added. 42 uploader may not be deleted until a new one is added.
45 """ 43 """
46 44
45 # TODO: WHAT IS THIS `format` THING ?
47 if format: id = id + '.' + format 46 if format: id = id + '.' + format
48 47
49 package = handlers.request().package 48 package = handlers.request().package
50 user_to_delete = users.User(id) 49 email = id
51 if not package.has_uploader(user_to_delete): 50 if not package.has_uploader_email(email):
52 handlers.http_error( 51 handlers.http_error(
53 400, "'%s' isn't an uploader for package '%s'." % 52 400, "'%s' isn't an uploader for package '%s'." %
54 (user_to_delete.nickname(), package.name)) 53 (email, package.name))
55 54
56 if len(package.uploaders) == 1: 55 if len(package.uploaderEmails) == 1:
57 handlers.http_error( 56 handlers.http_error(
58 400, ("Package '%s' only has one uploader, so that uploader " + 57 400, ("Package '%s' only has one uploader, so that uploader " +
59 "can't be removed.") % package.name) 58 "can't be removed.") % package.name)
60 59
61 email_to_delete = user_to_delete.email().lower() 60 email_to_delete = email.lower()
62 package.uploaders = [uploader for uploader in package.uploaders 61 package.uploaderEmails = [email for email in package.uploaderEmails
63 if uploader.email().lower() != email_to_delete] 62 if email.lower() != email_to_delete]
64 package.temp_synchronize_uploaders_to_uploaderemails()
65 package.put() 63 package.put()
66 package.invalidate_cache() 64 package.invalidate_cache()
67 return handlers.json_success( 65 return handlers.json_success(
68 "'%s' is no longer an uploader for package '%s'." % 66 "'%s' is no longer an uploader for package '%s'." %
69 (id, package.name)) 67 (id, package.name))
68
OLDNEW
« no previous file with comments | « app/handlers/__init__.py ('k') | app/handlers/api/package_versions.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698