"Fossies" - the Fresh Open Source Software Archive

Member "nocodb-0.83.5/packages/nc-gui/components/project/tableTabs/aclTsFileDbGql.vue" (27 Nov 2021, 11044 Bytes) of package /linux/misc/nocodb-0.83.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) vue.js (beta) source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <!-- eslint-disable -->
    2 <template>
    3   <div>
    4     <v-card style="">
    5       <v-toolbar flat height="42" class="toolbar-border-bottom">
    6         <v-toolbar-title>
    7           <v-breadcrumbs
    8             :items="[{
    9                        text: nodes.env,
   10                        disabled: true,
   11                        href: '#'
   12                      },{
   13                        text: nodes.dbAlias,
   14                        disabled: true,
   15                        href: '#'
   16                      },
   17                      {
   18                        text: nodes.tn + ' (ACL)',
   19                        disabled: true,
   20                        href: '#'
   21                      }]"
   22             divider=">"
   23             small
   24           >
   25             <template #divider>
   26               <v-icon small color="grey lighten-2">
   27                 forward
   28               </v-icon>
   29             </template>
   30           </v-breadcrumbs>
   31         </v-toolbar-title>
   32         <v-spacer />
   33         <x-btn
   34           v-ge="['acl-gql','reload']"
   35           outlined
   36           tooltip="Reload ACL"
   37           color="primary"
   38           small
   39           @click="aclInit"
   40         >
   41           <v-icon small left>
   42             refresh
   43           </v-icon>
   44           Reload
   45         </x-btn>
   46         <x-btn
   47           v-ge="['acl-gql','open-folder']"
   48           tooltip="Open ACL Folder"
   49           icon="mdi-folder-open"
   50           outlined
   51           small
   52           color="primary"
   53           @click="openFolder"
   54         >
   55           Open Folder
   56         </x-btn>
   57         <x-btn
   58           v-ge="['acl-gql','save']"
   59           outlined
   60           tooltip="Save ACL"
   61           color="primary"
   62           class="primary"
   63           small
   64           :disabled="disableSaveButton"
   65           @click="save"
   66         >
   67           <v-icon small left>
   68             save
   69           </v-icon>
   70           Save
   71         </x-btn>
   72       </v-toolbar>
   73 
   74       <v-text-field
   75         v-model="search"
   76         dense
   77         hide-details
   78         class="ma-2"
   79         :placeholder="`Search ${nodes.tn} resolvers`"
   80         prepend-inner-icon="search"
   81         outlined
   82       />
   83 
   84       <v-simple-table v-if="policies && policies.length" dense>
   85         <thead>
   86           <tr>
   87             <th colspan="2" class="text-center" rowspan="2">
   88               <div class="d-flex justify-center">
   89                 <v-tooltip bottom>
   90                   <template #activator="{ on }">
   91                     <v-checkbox
   92                       v-model="allToggle"
   93                       v-ge="['acl-gql','open-folder']"
   94                       small
   95                       class="mt-1 flex-shrink-1"
   96                       dense
   97                       v-on="on"
   98                     />
   99                   </template>
  100                   <span>{{ allToggle ? 'Disable' : 'Enable' }} all {{ nodes.tn }} resolvers for all roles</span>
  101                 </v-tooltip>
  102                 <span class="title">{{ nodes.tn }} Resolvers</span>
  103               </div>
  104             </th>
  105             <th
  106               v-for="role in roles"
  107               style="border-left: 1px solid grey;border-bottom: 1px solid grey"
  108             >
  109               <div class="d-flex align-center justify-center">
  110                 <span>{{ role }}</span>
  111               </div>
  112             </th>
  113           </tr>
  114           <tr>
  115             <th
  116               v-for="role in roles"
  117               class="pa-1"
  118               style="border-left: 1px solid grey;border-bottom: 1px solid grey"
  119             >
  120               <div class="d-flex justify-center">
  121                 <v-tooltip bottom>
  122                   <template #activator="{ on }">
  123                     <v-checkbox
  124                       v-model="columnToggle[role]"
  125                       v-ge="['acl-gql','open-folder']"
  126                       small
  127                       class="mt-0"
  128                       dense
  129                       v-on="on"
  130                       @change="toggleColumn(role,columnToggle[role])"
  131                     />
  132                   </template>
  133                   <span>
  134                     <span>{{ columnToggle[role] ? 'Disable' : 'Enable' }} all resolvers for {{ role }}</span></span>
  135                 </v-tooltip>
  136               </div>
  137             </th>
  138           </tr>
  139         </thead>
  140         <tbody>
  141           <tr v-for="(resolver,path) in data1" v-show="!search || path.toLowerCase().indexOf(search.toLowerCase()) > -1" key="path" :>
  142             <td width="20" class="pl-6 pr-3">
  143               <v-tooltip bottom>
  144                 <template #activator="{ on }">
  145                   <v-checkbox
  146                     v-model="rowToggle[path]"
  147                     v-ge="['acl-gql','open-folder']"
  148                     small
  149                     class="mt-0 ml-3"
  150                     dense
  151                     v-on="on"
  152                     @change="toggleRow(path,rowToggle[path])"
  153                   />
  154                 </template>
  155 
  156                 <span>{{ rowToggle[path] ? 'Disable' : 'Enable' }} this resolver for all roles</span>
  157               </v-tooltip>
  158             </td>
  159             <td class="pl-0">
  160               <v-tooltip bottom>
  161                 <template #activator="{ on }">
  162                   <span v-on="on">{{ path }}</span>
  163                 </template>
  164                 <span>{{ path }}</span>
  165               </v-tooltip>
  166             </td>
  167             <template v-for="(role) in roles">
  168               <td :key="`${path}_${role}`" style="border-left: 1px solid grey" class="pa-1">
  169                 <div class="d-flex justify-center">
  170                   <v-checkbox
  171                     v-model="data1[path][role]"
  172                     v-ge="['acl-gql','open-folder']"
  173                     small
  174                     class="mt-0"
  175                     dense
  176                     @change="toggleCell(path,role,data1[path][role])"
  177                   />
  178                 </div>
  179               </td>
  180             </template>
  181           </tr>
  182         </tbody>
  183       </v-simple-table>
  184 
  185       <v-alert v-else-if="policies" outlined type="info">
  186         Permission file not found
  187       </v-alert>
  188     </v-card>
  189   </div>
  190 </template>
  191 
  192 <script>
  193 import { mapGetters } from 'vuex'
  194 
  195 // const {fs, importFresh, shell, path} = require("electron").remote.require('./libs');
  196 
  197 export default {
  198   name: 'AclTsFileDbGql',
  199 
  200   props: ['nodes'],
  201   data() {
  202     return {
  203       disableSaveButton: true,
  204       search: '',
  205       policyPath: '',
  206       policies: null,
  207       columnToggle: {},
  208       rowToggle: {},
  209       roles: [
  210         'creator',
  211         'editor',
  212         'guest'
  213       ],
  214       data1: null
  215     }
  216   },
  217   methods: {
  218     openFolder() {
  219       //  shell.openItem(path.dirname(this.policyPath));
  220     },
  221     toggleColumn(role, checked) {
  222       for (const [resolver, roles] of Object.entries(this.data1)) {
  223         this.$set(roles, role, checked)
  224         this.toggleCell(resolver, role, checked)
  225       }
  226     },
  227     toggleRow(resolver, checked) {
  228       for (const role in this.data1[resolver]) {
  229         this.$set(this.data1[resolver], role, checked)
  230         this.toggleCell(resolver, role, checked)
  231       }
  232     },
  233     toggleAll(checked) {
  234       this.disableSaveButton = false
  235       for (const path in this.data1) {
  236         this.rowToggle[path] = checked
  237       }
  238       for (const role of this.roles) {
  239         this.columnToggle[role] = checked
  240       }
  241 
  242       for (const roles of Object.values(this.data1)) {
  243         for (const role of this.roles) {
  244           this.$set(roles, role, checked)
  245         }
  246       }
  247     },
  248     toggleCell(resolver, role, checked) {
  249       this.disableSaveButton = false
  250       this.$set(this.columnToggle, role, Object.values(this.data1).some(roles => roles[role]))
  251       this.$set(this.rowToggle, resolver, Object.values(this.data1[resolver]).some(enabled => enabled))
  252     },
  253     initColumnCheckBox() {
  254       for (const role of this.roles) {
  255         this.columnToggle[role] = Object.values(this.data1).some(roles => roles[role])
  256       }
  257     },
  258     initRowCheckBox() {
  259       for (const path in this.data1) {
  260         this.rowToggle[path] = Object.entries(this.data1[path]).filter(([role, v]) => {
  261           if (!this.roles.includes(role)) { this.roles = [...this.roles, role] }
  262           return v
  263         }).length
  264       }
  265     },
  266     async aclInit() {
  267       try {
  268         console.log(this.sqlMgr)
  269         this.disableSaveButton = true
  270         // this.policies = (await this.sqlMgr.xcResolverPolicyGet({
  271         //   env: this.nodes.env,
  272         //   dbAlias: this.nodes.dbAlias,
  273         //   tn: this.nodes.tn
  274         // })).data.list;
  275         this.policies = (await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcResolverPolicyGet', {
  276           env: this.nodes.env,
  277           dbAlias: this.nodes.dbAlias,
  278           tn: this.nodes.tn
  279         }])).data.list
  280 
  281         // .data.list;
  282         this.data = JSON.parse(JSON.stringify(this.policies))
  283         this.data1 = this.data.reduce((aclObj, resolver) => {
  284           if (resolver.resolver) {
  285             aclObj[resolver.resolver] = resolver.acl
  286           }
  287           return aclObj
  288         }, {})
  289 
  290         this.initColumnCheckBox()
  291         this.initRowCheckBox()
  292       } catch (e) {
  293         console.log(e)
  294       }
  295     },
  296     async save() {
  297       try {
  298         // await this.sqlMgr.xcResolverPolicyUpdate({
  299         //   env: this.nodes.env,
  300         //   dbAlias: this.nodes.dbAlias,
  301         //   tn: this.nodes.tn,
  302         //   data: this.data
  303         // })
  304 
  305         await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcResolverPolicyUpdate', {
  306           env: this.nodes.env,
  307           dbAlias: this.nodes.dbAlias,
  308           tn: this.nodes.tn,
  309           data: this.data
  310         }])
  311 
  312         this.disableSaveButton = true
  313         this.$toast.success(`${this.policyPath} updated successfully`).goAway(3000)
  314       } catch (e) {
  315         console.log(e)
  316         this.$toast.error(`${this.policyPath} updating failed`).goAway(3000)
  317       }
  318     }
  319   },
  320   computed: {
  321     ...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
  322     allToggle: {
  323       get() {
  324         return this.data1 && Object.values(this.data1).some(roles => Object.values(roles).some(v => v))
  325       },
  326       set(checked) {
  327         this.toggleAll(checked)
  328       }
  329     }
  330   },
  331   watch: {},
  332   async mounted() {
  333     await this.aclInit()
  334   }
  335 }
  336 </script>
  337 
  338 <style scoped>
  339 
  340 </style>
  341 <!--
  342 /**
  343  * @copyright Copyright (c) 2021, Xgene Cloud Ltd
  344  *
  345  * @author Naveen MR <oof1lab@gmail.com>
  346  * @author Pranav C Balan <pranavxc@gmail.com>
  347  *
  348  * @license GNU AGPL version 3 or any later version
  349  *
  350  * This program is free software: you can redistribute it and/or modify
  351  * it under the terms of the GNU Affero General Public License as
  352  * published by the Free Software Foundation, either version 3 of the
  353  * License, or (at your option) any later version.
  354  *
  355  * This program is distributed in the hope that it will be useful,
  356  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  357  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  358  * GNU Affero General Public License for more details.
  359  *
  360  * You should have received a copy of the GNU Affero General Public License
  361  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  362  *
  363  */
  364 -->