From d5f37b41c15168fbefe1f4c51a5d0745ed6da7a6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 28 2014 07:37:33 +0000 Subject: Add a generic method to check if the user logged in is an admin of a specified repo --- diff --git a/progit/__init__.py b/progit/__init__.py index 931aad7..5937138 100644 --- a/progit/__init__.py +++ b/progit/__init__.py @@ -94,6 +94,17 @@ def is_admin(): return not groups.isdisjoint(admins) +def is_repo_admin(repo_obj): + """ Return whether the user is an admin of the provided repo. """ + if not authenticated() \ + or not flask.g.fas_user.cla_done: + return False + + user = flask.g.fas_user.username + + return repo_obj.user or user in repo_obj.users + + def cla_required(function): """ Flask decorator to retrict access to CLA signed user. To use this decorator you need to have a function named 'auth_login'.