Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 6482ed7

Browse files
author
Vítor Avelino
committed
namespaces: unified admin page with regular page
We got rid of the admin namespaces page and unified the vision of the admin on the regular namespace page. So, if the user is an admin, they will be seeing all of the namespaces and will be able to manage all of them. If the user is a regular one, everything stays the same. API is also affected by this change. One improvement we did was to separate the other namespaces the user had access to without being through membership in a different panel. This will help the user understand better how they have access to those namespaces. Signed-off-by: Vítor Avelino <[email protected]>
1 parent 79bf527 commit 6482ed7

File tree

18 files changed

+190
-214
lines changed

18 files changed

+190
-214
lines changed

app/assets/javascripts/modules/namespaces/pages/index.vue

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<template>
22
<div class="namespaces-index-page">
3+
<new-namespace-form :state="state" form-state="newFormVisible"></new-namespace-form>
4+
35
<namespaces-panel :namespaces="specialNamespaces" :namespaces-path="namespacesPath" :webhooks-path="webhooksPath" prefix="sns_">
46
<h5 slot="name">
57
<a data-placement="right"
@@ -13,16 +15,18 @@
1315
</a>
1416
Special namespaces
1517
</h5>
16-
</namespaces-panel>
17-
18-
<new-namespace-form :state="state" form-state="newFormVisible"></new-namespace-form>
19-
20-
<namespaces-panel :namespaces="normalNamespaces" :namespaces-path="namespacesPath" :webhooks-path="webhooksPath" :table-sortable="true">
21-
<h5 slot="name">Namespaces you have access to</h5>
2218
<div slot="actions" v-if="canCreateNamespace">
2319
<toggle-link text="Create new namespace" :state="state" state-key="newFormVisible" class="toggle-link-new-namespace"></toggle-link>
2420
</div>
2521
</namespaces-panel>
22+
23+
<namespaces-panel :namespaces="normalNamespaces" :namespaces-path="namespacesPath" :webhooks-path="webhooksPath" :table-sortable="true" class="member-namespaces-panel">
24+
<h5 slot="name">Namespaces you have access to through membership</h5>
25+
</namespaces-panel>
26+
27+
<namespaces-panel :namespaces="otherNamespaces" :namespaces-path="namespacesPath" :webhooks-path="webhooksPath" prefix="ons_" :table-sortable="true" v-if="otherNamespaces.length">
28+
<h5 slot="name">Other namespaces</h5>
29+
</namespaces-panel>
2630
</div>
2731
</template>
2832

@@ -54,6 +58,9 @@
5458
canCreateNamespace: {
5559
type: Boolean,
5660
},
61+
accessibleTeamsIds: {
62+
type: Array,
63+
},
5764
},
5865
5966
components: {
@@ -65,31 +72,50 @@
6572
data() {
6673
return {
6774
state: NamespacesStore.state,
68-
normalNamespaces: [],
69-
specialNamespaces: [],
75+
namespaces: [],
7076
};
7177
},
7278
79+
computed: {
80+
otherNamespaces() {
81+
// eslint-disable-next-line
82+
return this.namespaces.filter((n) => {
83+
return !n.global &&
84+
n.id !== this.userNamespaceId &&
85+
this.accessibleTeamsIds.indexOf(n.team_id) === -1;
86+
});
87+
},
88+
89+
normalNamespaces() {
90+
// eslint-disable-next-line
91+
return this.namespaces.filter((n) => {
92+
return !n.global &&
93+
n.id !== this.userNamespaceId &&
94+
this.accessibleTeamsIds.indexOf(n.team_id) !== -1;
95+
});
96+
},
97+
98+
specialNamespaces() {
99+
return this.namespaces.filter(n => n.global || n.id === this.userNamespaceId);
100+
},
101+
},
102+
73103
methods: {
74104
onCreate(namespace) {
75-
const currentNamespaces = this.normalNamespaces;
105+
const currentNamespaces = this.namespaces;
76106
const namespaces = [
77107
...currentNamespaces,
78108
namespace,
79109
];
80110
81-
set(this, 'normalNamespaces', namespaces);
111+
set(this, 'namespaces', namespaces);
82112
},
83113
84114
loadData() {
85115
NamespacesService.all().then((response) => {
86116
const namespaces = response.data;
87117
88-
const normal = namespaces.filter(n => !n.global && n.id !== this.userNamespaceId);
89-
const special = namespaces.filter(n => n.global || n.id === this.userNamespaceId);
90-
91-
set(this, 'normalNamespaces', normal);
92-
set(this, 'specialNamespaces', special);
118+
set(this, 'namespaces', namespaces);
93119
set(this.state, 'isLoading', false);
94120
});
95121
},

app/controllers/admin/namespaces_controller.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

app/controllers/namespaces_controller.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ def update
5656

5757
# GET /namespace/typeahead/%QUERY
5858
def typeahead
59-
@query = params[:query]
60-
valid_teams = TeamUser.get_valid_team_ids(current_user.id)
61-
matches = Team.search_from_query(valid_teams, "#{@query}%").pluck(:name)
59+
valid_teams_ids = if current_user.admin?
60+
Team.all_non_special.pluck(:id)
61+
else
62+
TeamUser.get_valid_team_ids(current_user.id)
63+
end
64+
65+
query = "#{params[:query]}%"
66+
matches = Team.search_from_query(valid_teams_ids, query).pluck(:name)
6267
matches = matches.map { |team| { name: ActionController::Base.helpers.sanitize(team) } }
6368
respond_to do |format|
6469
format.json { render json: matches.to_json }

app/controllers/teams_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TeamsController < ApplicationController
99

1010
# GET /teams
1111
def index
12-
@teams = policy_scope(Team).page(params[:page])
12+
@teams = policy_scope(Team)
1313
@teams_serialized = API::Entities::Teams.represent(
1414
@teams,
1515
current_user: current_user,

app/models/namespace.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class Namespace < ActiveRecord::Base
2929
attributes :name, :description
3030
end
3131

32-
scope :special_for, lambda { |user|
33-
where("global = ? OR namespaces.id = ?", true, user.namespace_id)
34-
}
35-
3632
# This regexp is extracted from the reference package of Docker Distribution
3733
# and it matches a valid namespace name.
3834
NAME_REGEXP = /\A[a-z0-9]+(?:[._\\-][a-z0-9]+)*\Z/

app/policies/namespace_policy.rb

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,23 @@ def initialize(user, scope)
8282
end
8383

8484
def resolve
85-
scope
86-
.joins(team: [:team_users])
87-
.where(
88-
"(namespaces.visibility = :public OR namespaces.visibility = :protected " \
89-
"OR team_users.user_id = :user_id) AND " \
90-
"namespaces.global = :global AND namespaces.id != :namespace_id",
91-
public: Namespace.visibilities[:visibility_public],
92-
protected: Namespace.visibilities[:visibility_protected],
93-
user_id: user.id, global: false, namespace_id: user.namespace_id
94-
)
95-
.distinct
85+
if user.admin?
86+
global = scope.where(global: true)
87+
normal = scope.not_portus
88+
.where(global: false)
89+
.order(created_at: :asc)
90+
global + normal
91+
else
92+
scope
93+
.joins(team: [:team_users])
94+
.where(
95+
"namespaces.visibility = :public OR namespaces.visibility = :protected " \
96+
"OR team_users.user_id = :user_id",
97+
public: Namespace.visibilities[:visibility_public],
98+
protected: Namespace.visibilities[:visibility_protected],
99+
user_id: user.id
100+
)
101+
end
96102
end
97103
end
98104

app/views/admin/dashboard/index.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
.col-md-3.col-xs-12.namespaces
4848
.panel-overview
4949
.panel-heading
50-
= link_to 'Namespaces', admin_namespaces_path
50+
= link_to 'Namespaces', namespaces_path
5151
.panel-body
5252
.row
5353
.col-xs-3.col-md-4

app/views/namespaces/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<namespaces-index-page
22
:can-create-namespace="<%= can_create_namespace? %>"
33
:user-namespace-id="<%= current_user.namespace_id %>"
4+
:accessible-teams-ids="<%= current_user.teams.pluck(:id) %>"
45
webhooks-path="webhooks"
56
namespaces-path="<%= namespaces_path %>">
67
</namespaces-index-page>

config/routes/admin.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
resources :activities, only: [:index]
55
resources :dashboard, only: [:index]
66
resources :registries, except: %i[show destroy]
7-
resources :namespaces, only: [:index]
87
resources :users do
98
put "toggle_admin", on: :member
109
end

lib/api/helpers.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
require "portus/auth_from_token"
44
require "api/helpers/errors"
5-
require "api/helpers/namespaces"
65

76
module API
87
module Helpers
98
include ::Portus::AuthFromToken
109

1110
include Errors
12-
include Namespaces
1311

1412
# On success it will fill the @user instance variable with the currently
1513
# authenticated user for the API. Otherwise it will raise:

0 commit comments

Comments
 (0)