This commit is contained in:
Joseph Schorr 2013-09-30 19:08:38 -04:00
commit 2d69e2b031
3 changed files with 20 additions and 9 deletions

View file

@ -16,6 +16,15 @@ from auth.permissions import (ReadRepositoryPermission,
logger = logging.getLogger(__name__)
def api_login_required(f):
@wraps(f)
def decorated_view(*args, **kwargs):
if not current_user.is_authenticated():
abort(401)
return f(*args, **kwargs)
return decorated_view
@app.errorhandler(model.DataModelException)
def handle_dme(ex):
return make_response(ex.message, 400)
@ -42,7 +51,7 @@ def get_logged_in_user():
@app.route('/api/users/<prefix>', methods=['GET'])
@login_required
@api_login_required
def get_matching_users(prefix):
users = model.get_matching_users(prefix)
@ -52,7 +61,7 @@ def get_matching_users(prefix):
@app.route('/api/repository/', methods=['POST'])
@login_required
@api_login_required
def create_repo_api():
pass
@ -95,7 +104,7 @@ def list_repos_api():
@app.route('/api/repository/<path:repository>', methods=['PUT'])
@login_required
@api_login_required
@parse_repository_name
def update_repo_api(namespace, repository):
permission = ModifyRepositoryPermission(namespace, repository)
@ -113,7 +122,7 @@ def update_repo_api(namespace, repository):
@app.route('/api/repository/<path:repository>/changevisibility', methods=['POST'])
@login_required
@api_login_required
@parse_repository_name
def change_repo_visibility_api(namespace, repository):
permission = AdministerRepositoryPermission(namespace, repository)
@ -202,7 +211,7 @@ def list_tag_images(namespace, repository, tag):
@app.route('/api/repository/<path:repository>/permissions/', methods=['GET'])
@login_required
@api_login_required
@parse_repository_name
def list_repo_permissions(namespace, repository):
permission = AdministerRepositoryPermission(namespace, repository)
@ -219,7 +228,7 @@ def list_repo_permissions(namespace, repository):
@app.route('/api/repository/<path:repository>/permissions/<username>',
methods=['GET'])
@login_required
@api_login_required
@parse_repository_name
def get_permissions(namespace, repository, username):
logger.debug('Get repo: %s/%s permissions for user %s' %
@ -234,7 +243,7 @@ def get_permissions(namespace, repository, username):
@app.route('/api/repository/<path:repository>/permissions/<username>',
methods=['PUT', 'POST'])
@login_required
@api_login_required
@parse_repository_name
def change_permissions(namespace, repository, username):
permission = AdministerRepositoryPermission(namespace, repository)
@ -261,7 +270,7 @@ def change_permissions(namespace, repository, username):
@app.route('/api/repository/<path:repository>/permissions/<username>',
methods=['DELETE'])
@login_required
@api_login_required
@parse_repository_name
def delete_permissions(namespace, repository, username):
permission = AdministerRepositoryPermission(namespace, repository)

View file

@ -63,7 +63,7 @@
<!--<button type="button" class="btn btn-default navbar-btn">Sign in</button>-->
<a href="javascript:void(0)" class="dropdown-toggle user-dropdown" data-toggle="dropdown">
<img src="http://www.gravatar.com/avatar/{{ user.gravatar }}?s=32&d=identicon" />
<img src="//www.gravatar.com/avatar/{{ user.gravatar }}?s=32&d=identicon" />
{{ user.username }}
<b class="caret"></b>
</a>

View file

@ -6,6 +6,8 @@ WSGIRestrictEmbedded On
<VirtualHost *:80>
SetEnvIf X-Forwarded-Proto https HTTPS=1
Alias /static /opt/python/current/app/static/
<Directory /opt/python/current/app/>
Order allow,deny