From 4382ebfd20420f4293d90c76bc1e1ca27b5b6f25 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Sat, 28 Sep 2013 17:11:10 -0400 Subject: [PATCH] Add ability to change the visibility of a repo, and show whether the repo is private in the repo-view screen --- data/model.py | 9 ++++ endpoints/api.py | 23 +++++++++- static/css/quay.css | 77 ++++++++++++++++++++++++++++++++ static/js/controllers.js | 31 ++++++++++--- static/partials/repo-admin.html | 78 ++++++++++++++++++++++++++++++++- static/partials/view-repo.html | 7 ++- 6 files changed, 214 insertions(+), 11 deletions(-) diff --git a/data/model.py b/data/model.py index 4abf9d055..b3edfac08 100644 --- a/data/model.py +++ b/data/model.py @@ -165,6 +165,15 @@ def repository_is_public(namespace_name, repository_name): return len(list(query)) > 0 +def set_repository_visibility(repo, visibility): + visibility_obj = Visibility.get(name=visibility) + if not visibility_obj: + return + + repo.visibility = visibility_obj + repo.save() + + def create_repository(namespace, name, owner): private = Visibility.get(name='private') repo = Repository.create(namespace=namespace, name=name, diff --git a/endpoints/api.py b/endpoints/api.py index 14b55ae88..67a1079d3 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -61,7 +61,7 @@ def match_repos_api(prefix): return { 'namespace': repo.namespace, 'name': repo.name, - 'description': repo.description, + 'description': repo.description } username = current_user.db_user.username @@ -111,6 +111,23 @@ def update_repo_api(namespace, repository): abort(404) +@app.route('/api/repository//changevisibility', methods=['POST']) +@login_required +@parse_repository_name +def change_repo_visibility_api(namespace, repository): + permission = AdministerRepositoryPermission(namespace, repository) + if permission.can(): + repo = model.get_repository(namespace, repository) + if repo: + values = request.get_json() + model.set_repository_visibility(repo, values['visibility']) + return jsonify({ + 'success': True + }) + + abort(404) + + def image_view(image): return { 'id': image.image_id, @@ -136,7 +153,8 @@ def get_repo_api(namespace, repository): } permission = ReadRepositoryPermission(namespace, repository) - if permission.can() or model.repository_is_public(namespace, repository): + is_public = model.repository_is_public(namespace, repository) + if permission.can() or is_public: repo = model.get_repository(namespace, repository) if repo: tags = model.list_repository_tags(namespace, repository) @@ -150,6 +168,7 @@ def get_repo_api(namespace, repository): 'tags': tag_dict, 'can_write': can_write, 'can_admin': can_admin, + 'is_public': is_public }) abort(404) # Not fount diff --git a/static/css/quay.css b/static/css/quay.css index 4542f720d..9fc96054c 100644 --- a/static/css/quay.css +++ b/static/css/quay.css @@ -86,6 +86,33 @@ p.editable:hover i { margin-right: 6px; } +.repo .header .icon-container { + position: relative; + background: #eee; + padding: 4px; + border-radius: 50%; + display: inline-block; + width: 46px; + height: 46px; + text-align: center; + line-height: 38px; + margin-right: 10px; +} + +.repo .header .icon-container .icon-lock { + font-size: 50%; + position: absolute; + bottom: -6px; + right: 0px; + background: rgb(253, 191, 191); + width: 20px; + display: inline-block; + border-radius: 50%; + text-align: center; + height: 20px; + line-height: 21px; +} + .repo .description { margin-bottom: 40px; } @@ -272,6 +299,56 @@ p.editable:hover i { width: 54px; } +.repo-admin .repo-access-state .state-icon { + text-align: center; + margin-bottom: 10px; +} + +.repo-admin .repo-access-state .state-icon i { + font-size: 46px; + width: 54px; + height: 54px; + line-height: 54px; + border-radius: 50%; + display: inline-block; +} + +.repo-admin .repo-access-state { + text-align: center; + width: 520px; +} + +.repo-admin .repo-access-state .state-icon i.icon-lock { + background: rgb(253, 191, 191); +} + +.repo-admin .repo-access-state .state-icon i.icon-unlock-alt { + background: rgb(170, 236, 170); +} + +.repo-admin .change-access { + margin-top: 20px; + padding-top: 20px; + border-top: 1px solid #eee; + text-align: center; +} + +.repo-admin .change-access .alert { + color: black; + background: white; + border: 1px solid transparent; +} + +.repo-admin .change-access .alert .alert-content { + opacity: 0; +} + +.repo-admin .change-access:hover .alert { + background: inherit; + border: inherit; +} + + /* Overrides for typeahead to work with bootstrap 3. */ .twitter-typeahead .tt-query, diff --git a/static/js/controllers.js b/static/js/controllers.js index 62d0e692b..acb7c61ea 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -212,17 +212,36 @@ function RepoAdminCtrl($scope, Restangular, $routeParams, $rootScope) { }); }; + $scope.askChangeAccess = function(newAccess) { + $('#make' + newAccess + 'Modal').modal({}); + }; + + $scope.changeAccess = function(newAccess) { + $('#make' + newAccess + 'Modal').modal('hide'); + + var visibility = { + 'visibility': newAccess + }; + var visibilityPost = Restangular.one('repository/' + namespace + '/' + name + '/changevisibility'); + visibilityPost.customPOST(visibility).then(function() { + $scope.repo.is_public = newAccess == 'public'; + }, function() { + $('#cannotchangeModal').modal({}); + }); + }; + + // Fetch the repository information. + var repositoryFetch = Restangular.one('repository/' + namespace + '/' + name); + repositoryFetch.get().then(function(repo) { + $scope.repo = repo; + }); + + // Fetch the permissions. var permissionsFetch = Restangular.one('repository/' + namespace + '/' + name + '/permissions'); permissionsFetch.get().then(function(resp) { $rootScope.title = 'Settings - ' + namespace + '/' + name; - $scope.repo = { - 'namespace': namespace, - 'name': name - }; - $scope.permissions = resp.permissions; }, function() { - $scope.repo = null; $scope.permissions = null; $rootScope.title = 'Unknown Repository'; }); diff --git a/static/partials/repo-admin.html b/static/partials/repo-admin.html index edad9294b..a7372e46b 100644 --- a/static/partials/repo-admin.html +++ b/static/partials/repo-admin.html @@ -9,9 +9,10 @@ {{repo.namespace}} / {{repo.name}} - + +
-
Access Permissions
+
User Access Permissions
@@ -51,6 +52,33 @@
+
+ + +
+
Repository Settings
+
+
+
+ + This repository is currently private. Only users on the above access list may interact with it. + +
+ +
+
+ +
+
+ + This repository is currently public and visible to all users. + +
+ +
+
+
+
+ + + + + + + +