Skip to content

Add namespace picker to service account tab on membership page #1213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions app/scripts/controllers/membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ angular
$scope.newBinding.newRole = null;
};

var refreshServiceAccountsList = function(ctx) {
DataService
.list('serviceaccounts', ctx)
.then(function(resp) {
var serviceAccounts = _.keys(resp.by('metadata.name')).sort();
angular.extend($scope, {
serviceAccounts: serviceAccounts,
refreshServiceAccounts: function(search) {
if(search && !_.includes($scope.serviceAccounts, search)) {
$scope.serviceAccounts = [search].concat(serviceAccounts);
} else {
$scope.serviceAccounts = serviceAccounts;
}
}
});
});
};

var refreshRoleBindingList = function(toUpdateOnError) {
DataService
.list('rolebindings', requestContext, null , {
Expand Down Expand Up @@ -159,6 +177,7 @@ angular
},
selectTab: function(selected) {
$scope.newBinding.kind = selected;
$scope.newBinding.name = '';
}
});

Expand Down Expand Up @@ -219,15 +238,18 @@ angular
$scope.user = resp;
});


DataService
.list('projects', {})
.then(function(resp) {
var projects = _.map(resp.by('metadata.name'), function(project) {
return project.metadata.name;
});
var projects = _.keys(resp.by('metadata.name')).sort();
angular.extend($scope, {
projects: projects,
selectProject: function(projectName) {
$scope.newBinding.name = '';
refreshServiceAccountsList({
namespace: projectName
});
},
refreshProjects: function(search) {
if(search && !_.includes($scope.projects, search)) {
$scope.projects = [search].concat(projects);
Expand All @@ -243,6 +265,7 @@ angular
.then(_.spread(function(project, context) {
requestContext = context;
refreshRoleBindingList();
refreshServiceAccountsList(requestContext);
angular.extend($scope, {
project: project,
subjectKinds: subjectKinds,
Expand Down Expand Up @@ -364,5 +387,6 @@ angular
}
});
});

}));
});
13 changes: 8 additions & 5 deletions app/styles/_membership.less
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
min-width: 50%;
}
.word-break-all;
min-width: 225px;
max-width: 30%;
padding: 0 5px 10px 0;
width: 100%;
padding: 0 0px 10px 0;
input {
max-width: 150px;
}
Expand Down Expand Up @@ -71,7 +70,6 @@
width: 150px;
}
.select-role {
width: 150px;
small {
color: #999;
}
Expand Down Expand Up @@ -124,7 +122,9 @@
}
}
.col-name {
width: 30%;
min-width: 225px;
max-width: 30%;
padding: 0 5px 10px 0;
input {
max-width: 175px;
}
Expand All @@ -134,6 +134,9 @@
display: block;
}
}
.select-role {
width: 150px;
}
}
}
}
68 changes: 38 additions & 30 deletions app/views/membership.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,71 +167,79 @@ <h3>
<div
ng-if="mode.edit"
class="item-row form-new-role" row mobile="column">
<div class="col-name" column>
<div class="col-name pad-bottom-none" row mobile="column" tablet="column">
<label
ng-attr-for="newBindingName"
class="sr-only">
Name
</label>

<!-- name entry field for everything but service accounts -->
<input
ng-if="newBinding.kind !== 'ServiceAccount'"
type="text"
class="form-control input-name"
placeholder="Name"
ng-model="newBinding.name"
autocorrect="off"
autocapitalize="off"
spellcheck="false">
<!-- namespace entry/picker for service accounts -->
<div
ng-if="newBinding.kind === 'ServiceAccount'"
class="service-account-namespace hidden-sm hidden-md hidden-lg"
class="service-account-namespace"
aria-hidden="true">
<ui-select
ng-model="newBinding.namespace"
on-select="selectProject($item, $model)"
theme="bootstrap"
search-enabled="true"
title="Select a project"
class="select-role">
class="select-role pad-bottom-sm">
<ui-select-match
placeholder="Select a project">
<span ng-bind="newBinding.namespace"></span>
<span>{{newBinding.namespace}}</span>
</ui-select-match>
<ui-select-choices
repeat="projectName in projects | filter: $select.search"
refresh="refreshProjects($select.search)"
refresh-delay="200">
<div>{{projectName}}</div>
<div ng-bind-html="projectName | highlight : $select.search"></div>
</ui-select-choices>
</ui-select>
</div>

<span
ng-if="newBinding.kind === 'ServiceAccount'"
class="mar-left-md mar-right-md hidden-xs">/</span>

<!-- name entry/picker for service accounts -->
<div
ng-if="newBinding.kind === 'ServiceAccount'"
class="service-account-name">
<ui-select
ng-model="newBinding.name"
theme="bootstrap"
search-enabled="true"
title="Select a service account"
class="select-role">
<ui-select-match
placeholder="Service account">
<span>{{newBinding.name}}</span>
</ui-select-match>
<ui-select-choices
repeat="saName in serviceAccounts | filter: $select.search"
refresh="refreshServiceAccounts($select.search)"
refresh-delay="200">
<div ng-bind-html="saName | highlight : $select.search"></div>
</ui-select-choices>
</ui-select>
</div>
</div>
<div
class="action-set"
flex row tablet="column" mobile="column">
<div
class="col-roles"
row tablet="column" flex wrap axis="start">
<div
ng-if="newBinding.kind === 'ServiceAccount'"
class="service-account-namespace hidden-xs">
<ui-select
ng-model="newBinding.namespace"
theme="bootstrap"
search-enabled="true"
title="Select a project"
class="select-project">
<ui-select-match
placeholder="Select a project">
<span ng-bind="newBinding.namespace"></span>
</ui-select-match>
<ui-select-choices
repeat="projectName in projects | filter: $select.search"
refresh="refreshProjects($select.search)"
refresh-delay="200">
<div>{{projectName}}</div>
</ui-select-choices>
</ui-select>
</div>
</div>
<div class="col-roles" flex row tablet="column">&nbsp;</div>
<div class="col-add-role">
<div ng-show="mode.edit" row>
<ui-select
Expand Down
53 changes: 33 additions & 20 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5343,6 +5343,16 @@ details:e
}, v = function() {
d.disableAddForm = !1, d.newBinding.name = "", d.newBinding.namespace = o, d.newBinding.newRole = null;
}, w = function(a) {
i.list("serviceaccounts", a).then(function(a) {
var b = _.keys(a.by("metadata.name")).sort();
angular.extend(d, {
serviceAccounts:b,
refreshServiceAccounts:function(a) {
a && !_.includes(d.serviceAccounts, a) ? d.serviceAccounts = [ a ].concat(b) :d.serviceAccounts = b;
}
});
});
}, x = function(a) {
i.list("rolebindings", n, null, {
errorNotification:!1
}).then(function(a) {
Expand All @@ -5354,9 +5364,9 @@ subjectKindsForUI:k.mapRolebindingsForUI(a.by("metadata.name"), s)
}, function() {
a && (d.roleBindings[a.metadata.name] = a, d.subjectKindsForUI = k.mapRolebindingsForUI(d.roleBindings, s)), v();
});
}, x = function(b, c) {
}, y = function(b, c) {
d.disableAddForm = !0, l.create(b, c, o, n).then(function() {
w(), u("rolebindingCreate", "success", t.update.subject.success({
x(), u("rolebindingCreate", "success", t.update.subject.success({
roleName:b.metadata.name,
subjectName:c.name
}));
Expand All @@ -5368,9 +5378,9 @@ subjectName:c.name
httpErr:a("getErrorDetails")(d)
}));
});
}, y = function(b, c, e) {
}, z = function(b, c, e) {
d.disableAddForm = !0, l.addSubject(b, c, e, n).then(function() {
w(), u("rolebindingUpdate", "success", t.update.subject.success({
x(), u("rolebindingUpdate", "success", t.update.subject.success({
roleName:b.roleRef.name,
subjectName:c.name
}));
Expand All @@ -5382,16 +5392,16 @@ subjectName:c.name
httpErr:a("getErrorDetails")(d)
}));
});
}, z = {};
c.tab && (z[c.tab] = !0);
var A = k.getSubjectKinds();
}, A = {};
c.tab && (A[c.tab] = !0);
var B = k.getSubjectKinds();
angular.extend(d, {
selectedTab:z,
selectedTab:A,
projectName:o,
alerts:{},
forms:{},
emptyMessage:"Loading...",
subjectKinds:A,
subjectKinds:B,
newBinding:{
role:"",
kind:c.tab || "User",
Expand All @@ -5404,7 +5414,7 @@ mode:{
edit:!1
},
selectTab:function(a) {
d.newBinding.kind = a;
d.newBinding.kind = a, d.newBinding.name = "";
}
}), angular.extend(d, {
excludeExistingRoles:function(a) {
Expand All @@ -5424,7 +5434,7 @@ return a ? e + (q(a, "description") || b) :b;
}
}
});
var B = function(a, b, c, e) {
var C = function(a, b, c, e) {
var f = {
alerts:{},
detailsMarkup:t.remove.areYouSure.html.subject({
Expand All @@ -5446,22 +5456,25 @@ roleName:c
g.withUser().then(function(a) {
d.user = a;
}), i.list("projects", {}).then(function(a) {
var b = _.map(a.by("metadata.name"), function(a) {
return a.metadata.name;
});
var b = _.keys(a.by("metadata.name")).sort();
angular.extend(d, {
projects:b,
selectProject:function(a) {
d.newBinding.name = "", w({
namespace:a
});
},
refreshProjects:function(a) {
a && !_.includes(d.projects, a) ? d.projects = [ a ].concat(b) :d.projects = b;
}
});
}), j.get(c.project).then(_.spread(function(c, e) {
n = e, w(), angular.extend(d, {
n = e, x(), w(n), angular.extend(d, {
project:c,
subjectKinds:A,
subjectKinds:B,
canUpdateRolebindings:r("rolebindings", "update", o),
confirmRemove:function(c, e, g) {
var i = null, j = B(c, e, g, d.user.metadata.name);
var i = null, j = C(c, e, g, d.user.metadata.name);
_.isEqual(c, d.user.metadata.name) && k.isLastRole(d.user.metadata.name, d.roleBindings) && (i = !0), f.open({
animation:!0,
templateUrl:"views/modals/confirm.html",
Expand All @@ -5474,7 +5487,7 @@ return j;
}).result.then(function() {
l.removeSubject(c, g, d.roleBindings, n).then(function(a) {
i ? b.url("./") :(h.getProjectRules(o, !0).then(function() {
w(a[0]);
x(a[0]);
var b = r("rolebindings", "update", o);
angular.extend(d, {
canUpdateRolebindings:b,
Expand Down Expand Up @@ -5511,7 +5524,7 @@ name:a
}) ? u("rolebindingUpdate", "info", t.update.subject.exists({
roleName:c.metadata.name,
subjectName:a
})) :g ? y(g, f, e) :x(c, f, e);
})) :g ? z(g, f, e) :y(c, f, e);
}
}), m.listAllRoles(n, {
errorNotification:!1
Expand All @@ -5524,7 +5537,7 @@ name:a
}
});
};
w(), angular.extend(d, {
x(), angular.extend(d, {
toggle:{
roles:!1
},
Expand Down
Loading