Files
portainer/app/kubernetes/components/datatables/volumes-datatable/volumesDatatableController.js
T
Yi Chen 2247d8c3a2 (feat)k8s/RBAC: Provide Portainer RBAC functionality for Kubernetes endpoints (#35)
* + endpoint and namespace level authorizations
+ user namespace authorization API
+ k8s client setup service account with k8s roles and policies by portainer role
* User authorization changes refresh token cache
* rbac authorizes k8s requests
* CE to EE migrator to include new authorizations

* code clean up
* comments

* * merge in the RestrictDefaultNamespace changes

* - remove unnecessary check for default namespace

* + updates namespace access policies when generating token

* * updates namespace access policies when querying the user namespace endpoint

* + k8s rule in rbac.go for endpoint access test
+ missing k8s cluster rules for different roles

* feat(rbac): update kube rbac

* feat(rbac): use the authorization directive

* feat(rbac): Update namespace access policies when user/team is deleted

* refactor(app): use new angular-multi-select capabilities

* feat(rbac): fix authorizations

* feat(rbac): fix userAccessPolicies update bug

* feat(rbac): add W applications authorizations

* feat(rbac): add application details W authorizations

* feat(rbac): add configurations W autohorizations

* feat(rbac): add configuration details W authorizations

* feat(rbac): add volumes W authorizations

* feat(rbac): add volume details W authorizations

* feat(rbac): add componentstatus to portainer-view role and add cluster/node authorizations

* fix(rbac): disable application note for non authorized user

* fix(rbac): add endpoints list and components status to portainer-basic

* fix(rbac): allow user to access default namespace when restrict default namespace isn't activated

* fix(rbac): remove default namespace from useraccesspolicies when restrict default namespace isn't activated

* fix(rbac): change some things

* fix(rbac): allow standard user to access container console

* - removed unused parameter

* fix(rbac): fix team authorizations

Co-authored-by: Maxime Bajeux <max.bajeux@gmail.com>
Co-authored-by: xAt0mZ <baron_l@epitech.eu>
2020-11-03 22:08:09 +13:00

94 lines
3.0 KiB
JavaScript

import angular from 'angular';
import KubernetesVolumeHelper from 'Kubernetes/helpers/volumeHelper';
// TODO: review - refactor to use `extends GenericDatatableController`
class KubernetesVolumesDatatableController {
/* @ngInject */
constructor($async, $controller, KubernetesNamespaceHelper, DatatableService, Authentication) {
this.$async = $async;
this.$controller = $controller;
this.KubernetesNamespaceHelper = KubernetesNamespaceHelper;
this.DatatableService = DatatableService;
this.Authentication = Authentication;
this.onInit = this.onInit.bind(this);
this.allowSelection = this.allowSelection.bind(this);
this.isDisplayed = this.isDisplayed.bind(this);
}
onSettingsShowSystemChange() {
this.DatatableService.setDataTableSettings(this.tableKey, this.settings);
}
disableRemove(item) {
return this.isSystemNamespace(item) || this.isUsed(item);
}
isUsed(item) {
return KubernetesVolumeHelper.isUsed(item);
}
isSystemNamespace(item) {
return this.KubernetesNamespaceHelper.isSystemNamespace(item.ResourcePool.Namespace.Name);
}
isDisplayed(item) {
return !this.isSystemNamespace(item) || this.settings.showSystem;
}
isExternalVolume(item) {
return KubernetesVolumeHelper.isExternalVolume(item);
}
allowSelection(item) {
return !this.disableRemove(item);
}
async onInit() {
this.setDefaults();
this.prepareTableFromDataset();
this.settings.showSystem = false;
this.state.orderBy = this.orderBy;
var storedOrder = this.DatatableService.getDataTableOrder(this.tableKey);
if (storedOrder !== null) {
this.state.reverseOrder = storedOrder.reverse;
this.state.orderBy = storedOrder.orderBy;
}
var textFilter = this.DatatableService.getDataTableTextFilters(this.tableKey);
if (textFilter !== null) {
this.state.textFilter = textFilter;
this.onTextFilterChange();
}
var storedFilters = this.DatatableService.getDataTableFilters(this.tableKey);
if (storedFilters !== null) {
this.filters = storedFilters;
}
if (this.filters && this.filters.state) {
this.filters.state.open = false;
}
var storedSettings = this.DatatableService.getDataTableSettings(this.tableKey);
if (storedSettings !== null) {
this.settings = storedSettings;
this.settings.open = false;
}
if (!this.Authentication.hasAuthorizations(['K8sAccessSystemNamespaces']) && this.settings.showSystem) {
this.settings.showSystem = false;
this.DatatableService.setDataTableSettings(this.tableKey, this.settings);
}
this.onSettingsRepeaterChange();
}
$onInit() {
const ctrl = angular.extend({}, this.$controller('GenericDatatableController'), this);
angular.extend(this, ctrl);
return this.$async(this.onInit);
}
}
export default KubernetesVolumesDatatableController;
angular.module('portainer.kubernetes').controller('KubernetesVolumesDatatableController', KubernetesVolumesDatatableController);