Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 6aacde2a7f1f3e2651d0786277480d1d9727daab Author: Bohuslav Kabrda bkabrda@redhat.com Date: Thu Mar 28 13:10:52 2013 +0100
Move build creation authorization to logic.
coprs_frontend/coprs/logic/builds_logic.py | 11 +++++------ coprs_frontend/coprs/logic/users_logic.py | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/coprs_frontend/coprs/logic/builds_logic.py b/coprs_frontend/coprs/logic/builds_logic.py index 2a91f95..834217d 100644 --- a/coprs_frontend/coprs/logic/builds_logic.py +++ b/coprs_frontend/coprs/logic/builds_logic.py @@ -6,6 +6,7 @@ from coprs import models from coprs import signals
from coprs.logic import coprs_logic +from coprs.logic import users_logic
class BuildsLogic(object): @classmethod @@ -59,6 +60,8 @@ class BuildsLogic(object): def add(cls, user, pkgs, copr): coprs_logic.CoprsLogic.raise_if_unfinished_action(user, copr, 'Can't build while there is an operation in progress: {action}') + users_logic.UsersLogic.raise_if_cant_build_in_copr(user, copr, + 'You don't have permissions to build in this copr.') build = models.Build( pkgs=pkgs, copr=copr, @@ -66,15 +69,11 @@ class BuildsLogic(object): chroots=' '.join(map(lambda x: x.chroot_name, copr.active_mock_chroots)), user=user, submitted_on=int(time.time())) - # no need to check for authorization here - cls.new(user, build, copr, check_authorized=False) + cls.new(user, build, copr) return build
@classmethod - def new(cls, user, build, copr, check_authorized = True): - if check_authorized: - if not user.can_build_in(copr): - raise exceptions.InsufficientRightsException('User {0} cannot build in copr {1}/{2}'.format(user.name, copr.owner.name, copr.name)) + def new(cls, user, build, copr): if not build.submitted_on: build.submitted_on = int(time.time()) if not build.user: diff --git a/coprs_frontend/coprs/logic/users_logic.py b/coprs_frontend/coprs/logic/users_logic.py index 8ff0eb2..3f6d048 100644 --- a/coprs_frontend/coprs/logic/users_logic.py +++ b/coprs_frontend/coprs/logic/users_logic.py @@ -9,3 +9,11 @@ class UsersLogic(object): # TODO: this is a bit inconsistent - shouldn't the user method be called can_update? if not user.can_edit(copr): raise exceptions.InsufficientRightsException(message) + + @classmethod + def raise_if_cant_build_in_copr(cls, user, copr, message): + """This method raises InsufficientRightsException if given user cant build in + given copr. Returns None otherwise. + """ + if not user.can_build_in(copr): + raise exceptions.InsufficientRightsException(message)
copr-devel@lists.fedorahosted.org