From 650dbe5f5bc8e5db14c6cbb4624cf81d5e7579ed Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 7 Aug 2017 15:59:06 -0400 Subject: [PATCH] Add config to enable "public" namespaces These are namespaces that will be displayed in the repo list view, regardless of whether the user is a member. --- config.py | 6 ++++++ endpoints/api/user.py | 9 ++++++++- static/js/pages/repo-list.js | 8 +++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 197a1f34e..005ea4880 100644 --- a/config.py +++ b/config.py @@ -273,6 +273,12 @@ class DefaultConfig(ImmutableConfig): # rather than only write access or admin access. FEATURE_READER_BUILD_LOGS = False + # If a namespace is defined in the public namespace list, then it will appear on *all* + # user's repository list pages, regardless of whether that user is a member of the namespace. + # Typically, this is used by an enterprise customer in configuring a set of "well-known" + # namespaces. + PUBLIC_NAMESPACES = [] + # The namespace to use for library repositories. # Note: This must remain 'library' until Docker removes their hard-coded namespace for libraries. # See: https://github.com/docker/docker/blob/master/registry/session.go#L320 diff --git a/endpoints/api/user.py b/endpoints/api/user.py index 14a180b50..e0446e122 100644 --- a/endpoints/api/user.py +++ b/endpoints/api/user.py @@ -79,6 +79,7 @@ def user_view(user, previous_username=None): 'name': o.username, 'avatar': avatar.get_data_for_org(o), 'can_create_repo': CreateRepositoryPermission(o.username).can(), + 'public': o.username in app.config.get('PUBLIC_NAMESPACES', []), } if user_admin: @@ -89,7 +90,13 @@ def user_view(user, previous_username=None): return org_response - organizations = model.organization.get_user_organizations(user.username) + # Retrieve the organizations for the user. + organizations = list(model.organization.get_user_organizations(user.username)) + + # Add any public namespaces. + public_namespaces = app.config.get('PUBLIC_NAMESPACES', []) + if public_namespaces: + organizations.extend([model.user.get_namespace_user(ns) for ns in public_namespaces]) def login_view(login): try: diff --git a/static/js/pages/repo-list.js b/static/js/pages/repo-list.js index 30e889bbb..f294c630e 100644 --- a/static/js/pages/repo-list.js +++ b/static/js/pages/repo-list.js @@ -11,7 +11,7 @@ }]); - function RepoListCtrl($scope, $sanitize, $q, Restangular, UserService, ApiService, Features) { + function RepoListCtrl($scope, $sanitize, $q, Restangular, UserService, ApiService, Features, Config) { $scope.namespace = null; $scope.page = 1; $scope.publicPageCount = null; @@ -35,7 +35,8 @@ user.organizations.map(function(org) { $scope.namespaces.push({ 'name': org.name, - 'avatar': org.avatar + 'avatar': org.avatar, + 'public': org.public }); }); @@ -99,7 +100,8 @@ var options = { 'namespace': namespace.name, 'last_modified': true, - 'popularity': true + 'popularity': true, + 'public': namespace.public }; namespace.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {