2020-05-20 12:15:37 +02:00
Ext . define ( 'pmx-acls' , {
extend : 'Ext.data.Model' ,
fields : [
'path' , 'ugid' , 'ugid_type' , 'roleid' , 'propagate' ,
{
name : 'aclid' ,
calculate : function ( data ) {
2020-05-22 14:51:44 +02:00
return ` ${ data . path } for ${ data . ugid } - ${ data . roleid } ` ;
2020-05-20 12:15:37 +02:00
} ,
} ,
] ,
idProperty : 'aclid' ,
proxy : {
type : 'proxmox' ,
url : '/api2/json/access/acl' ,
} ,
} ) ;
Ext . define ( 'PBS.config.ACLView' , {
extend : 'Ext.grid.GridPanel' ,
alias : 'widget.pbsACLView' ,
2020-05-20 13:26:41 +02:00
title : gettext ( 'Permissions' ) ,
2020-05-20 12:15:37 +02:00
2020-11-10 07:33:14 +01:00
// Show only those permissions, which can affect this and children paths.
// That means that also higher up, "shorter" paths are included, as those
// can have a say in the rights on the asked path.
2020-05-20 12:15:37 +02:00
aclPath : undefined ,
2020-11-10 07:33:14 +01:00
// tell API to only return ACLs matching exactly the aclPath config.
2020-05-20 12:15:37 +02:00
aclExact : undefined ,
controller : {
xclass : 'Ext.app.ViewController' ,
2020-10-28 11:07:27 +01:00
addUserACL : function ( ) {
2020-05-20 12:15:37 +02:00
let me = this ;
let view = me . getView ( ) ;
2020-10-28 11:07:27 +01:00
Ext . create ( 'PBS.window.ACLEdit' , {
2020-05-20 12:15:37 +02:00
path : view . aclPath ,
2020-10-28 11:07:27 +01:00
aclType : 'user' ,
2022-05-18 18:09:15 +02:00
datastore : view . datastore ,
2020-05-20 12:15:37 +02:00
listeners : {
2022-05-18 18:04:16 +02:00
destroy : ( ) => me . reload ( ) ,
2020-05-20 12:15:37 +02:00
} ,
2020-10-28 11:07:27 +01:00
} ) . show ( ) ;
2020-05-20 12:15:37 +02:00
} ,
2020-10-28 11:07:27 +01:00
addTokenACL : function ( ) {
let me = this ;
let view = me . getView ( ) ;
Ext . create ( 'PBS.window.ACLEdit' , {
path : view . aclPath ,
aclType : 'token' ,
2022-05-18 18:09:15 +02:00
datastore : view . datastore ,
2020-10-28 11:07:27 +01:00
listeners : {
2022-05-18 18:04:16 +02:00
destroy : ( ) => me . reload ( ) ,
2020-10-28 11:07:27 +01:00
} ,
} ) . show ( ) ;
} ,
2020-05-20 12:15:37 +02:00
removeACL : function ( btn , event , rec ) {
let me = this ;
Proxmox . Utils . API2Request ( {
2020-09-25 18:29:42 +02:00
url : '/access/acl' ,
2020-05-20 12:15:37 +02:00
method : 'PUT' ,
params : {
'delete' : 1 ,
path : rec . data . path ,
role : rec . data . roleid ,
2020-10-30 15:18:41 +01:00
'auth-id' : rec . data . ugid ,
2020-05-20 12:15:37 +02:00
} ,
callback : function ( ) {
me . reload ( ) ;
} ,
2020-09-25 18:29:42 +02:00
failure : function ( response , opts ) {
2020-05-20 12:15:37 +02:00
Ext . Msg . alert ( gettext ( 'Error' ) , response . htmlStatus ) ;
} ,
} ) ;
} ,
reload : function ( ) { this . getView ( ) . getStore ( ) . rstore . load ( ) ; } ,
init : function ( view ) {
let proxy = view . getStore ( ) . rstore . getProxy ( ) ;
let params = { } ;
2020-11-10 07:33:14 +01:00
if ( typeof view . aclPath === "string" ) {
2020-11-09 14:47:38 +01:00
let pathFilter = Ext . create ( 'Ext.util.Filter' , {
filterPath : view . aclPath ,
2020-11-10 07:33:14 +01:00
filterAtoms : view . aclPath . split ( '/' ) ,
2020-11-09 14:47:38 +01:00
filterFn : function ( item ) {
let me = this ;
2020-11-10 07:33:14 +01:00
let path = item . data . path ;
if ( path === "/" || path === me . filterPath ) {
return true ;
} else if ( path . length > me . filterPath . length ) {
return path . startsWith ( me . filterPath + '/' ) ;
}
let pathAtoms = path . split ( '/' ) ;
let commonLength = Math . min ( pathAtoms . length , me . filterAtoms . length ) ;
for ( let i = 1 ; i < commonLength ; i ++ ) {
if ( me . filterAtoms [ i ] !== pathAtoms [ i ] ) {
return false ;
}
2020-11-09 14:47:38 +01:00
}
2020-11-10 07:33:14 +01:00
return true ;
2020-11-09 14:47:38 +01:00
} ,
} ) ;
view . getStore ( ) . addFilter ( pathFilter ) ;
2020-05-20 12:15:37 +02:00
}
if ( view . aclExact !== undefined ) {
2020-11-09 14:47:38 +01:00
if ( view . aclPath !== undefined ) {
params . path = view . aclPath ;
}
2020-05-20 12:15:37 +02:00
params . exact = view . aclExact ;
}
2020-11-09 14:47:38 +01:00
2020-05-20 12:15:37 +02:00
proxy . setExtraParams ( params ) ;
2020-05-26 12:23:26 +02:00
Proxmox . Utils . monStoreErrors ( view , view . getStore ( ) . rstore ) ;
2020-05-20 12:15:37 +02:00
} ,
2020-05-26 18:58:19 +02:00
control : {
'#' : { // view
activate : function ( ) {
this . getView ( ) . getStore ( ) . rstore . startUpdate ( ) ;
} ,
deactivate : function ( ) {
this . getView ( ) . getStore ( ) . rstore . stopUpdate ( ) ;
} ,
} ,
} ,
2020-05-20 12:15:37 +02:00
} ,
store : {
type : 'diff' ,
autoDestroy : true ,
autoDestroyRstore : true ,
2020-05-22 14:51:44 +02:00
sorters : 'aclid' ,
2020-05-20 12:15:37 +02:00
rstore : {
type : 'update' ,
storeid : 'pmx-acls' ,
model : 'pmx-acls' ,
interval : 5000 ,
} ,
} ,
tbar : [
{
text : gettext ( 'Add' ) ,
2020-10-28 11:07:27 +01:00
menu : {
xtype : 'menu' ,
items : [
{
text : gettext ( 'User Permission' ) ,
iconCls : 'fa fa-fw fa-user' ,
handler : 'addUserACL' ,
} ,
{
text : gettext ( 'API Token Permission' ) ,
iconCls : 'fa fa-fw fa-user-o' ,
handler : 'addTokenACL' ,
} ,
] ,
} ,
2020-05-20 12:15:37 +02:00
} ,
{
xtype : 'proxmoxStdRemoveButton' ,
handler : 'removeACL' ,
callback : 'reload' ,
} ,
] ,
columns : [
{
header : gettext ( 'Path' ) ,
2022-05-18 18:22:16 +02:00
minWidth : 250 ,
flex : 4 ,
2020-05-20 12:15:37 +02:00
sortable : true ,
renderer : Ext . String . htmlEncode ,
dataIndex : 'path' ,
} ,
{
2020-10-28 11:07:27 +01:00
header : gettext ( 'User/Group/API Token' ) ,
2020-10-31 11:36:48 +01:00
width : 200 ,
2020-05-20 12:15:37 +02:00
sortable : true ,
renderer : Ext . String . htmlEncode ,
dataIndex : 'ugid' ,
} ,
{
header : gettext ( 'Role' ) ,
2020-10-31 11:36:48 +01:00
width : 200 ,
2020-05-20 12:15:37 +02:00
sortable : true ,
dataIndex : 'roleid' ,
} ,
{
header : gettext ( 'Propagate' ) ,
2022-05-18 18:22:16 +02:00
flex : 9 , // last element flex looks better
2020-05-20 12:15:37 +02:00
sortable : true ,
renderer : Proxmox . Utils . format _boolean ,
dataIndex : 'propagate' ,
} ,
] ,
} ) ;