"Fossies" - the Fresh Open Source Software Archive

Member "nocodb-0.83.5/packages/nc-gui/components/project/tableTabs/aclGql.vue" (27 Nov 2021, 10654 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="data1" 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">
  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,i) 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 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: 'AclGql',
  199 
  200   props: ['nodes'],
  201   data() {
  202     return {
  203       disableSaveButton: true,
  204       search: '',
  205       policyPath: '',
  206       columnToggle: {},
  207       rowToggle: {},
  208       roles: [
  209         'creator',
  210         'editor',
  211         'guest'
  212       ],
  213       data1: null
  214     }
  215   },
  216   methods: {
  217     openFolder() {
  218       // shell.openItem(path.dirname(this.policyPath))
  219     },
  220     toggleColumn(role, checked) {
  221       for (const [resolver, roles] of Object.entries(this.data1)) {
  222         this.$set(roles, role, checked)
  223         this.toggleCell(resolver, role, checked)
  224       }
  225     },
  226     toggleRow(resolver, checked) {
  227       for (const role in this.data1[resolver]) {
  228         this.$set(this.data1[resolver], role, checked)
  229         this.toggleCell(resolver, role, checked)
  230       }
  231     },
  232     toggleAll(checked) {
  233       this.disableSaveButton = false
  234       for (const path in this.data1) {
  235         this.rowToggle[path] = checked
  236       }
  237       for (const role of this.roles) {
  238         this.columnToggle[role] = checked
  239       }
  240 
  241       for (const roles of Object.values(this.data1)) {
  242         for (const role of this.roles) {
  243           this.$set(roles, role, checked)
  244         }
  245       }
  246     },
  247     toggleCell(resolver, role, checked) {
  248       this.disableSaveButton = false
  249       this.$set(this.columnToggle, role, Object.values(this.data1).some(roles => roles[role]))
  250       this.$set(this.rowToggle, resolver, Object.values(this.data1[resolver]).some(enabled => enabled))
  251     },
  252     initColumnCheckBox() {
  253       for (const role of this.roles) {
  254         this.columnToggle[role] = Object.values(this.data1).some(roles => roles[role])
  255       }
  256     },
  257     initRowCheckBox() {
  258       for (const path in this.data1) {
  259         this.rowToggle[path] = Object.entries(this.data1[path]).filter(([role, v]) => {
  260           if (!this.roles.includes(role)) { this.roles = [...this.roles, role] }
  261           return v
  262         }).length
  263       }
  264     },
  265     async aclInit() {
  266       this.disableSaveButton = true
  267       this.policyPath = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'projectGetGqlPolicyPath', {
  268         env: this.nodes.env,
  269         dbAlias: this.nodes.dbAlias,
  270         tn: this.nodes.tn
  271       }])
  272       try {
  273         console.log(this.policyPath, this.data1)
  274         this.data1 = JSON.parse(
  275           JSON.stringify(
  276             (
  277               await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'importFresh', { path: this.policyPath }])
  278             ).permissions
  279           )
  280         )
  281         this.initColumnCheckBox()
  282         this.initRowCheckBox()
  283       } catch (e) {
  284         console.log(e)
  285       }
  286     },
  287     async save() {
  288       try {
  289         // await this.sqlMgr.writeFile({
  290         //   path: this.policyPath,
  291         //   data: `module.exports.permissions = ${JSON.stringify(this.data1, 0, 2)}`
  292         // });
  293         await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'writeFile', {
  294           path: this.policyPath,
  295           data: `module.exports.permissions = ${JSON.stringify(this.data1, 0, 2)}`
  296         }])
  297         this.disableSaveButton = true
  298         this.$toast.success(`${this.policyPath} updated successfully`).goAway(3000)
  299       } catch (e) {
  300         console.log(e)
  301         this.$toast.error(`${this.policyPath} updating failed`).goAway(3000)
  302       }
  303     }
  304   },
  305   computed: {
  306     ...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
  307     allToggle: {
  308       get() {
  309         return this.data1 && Object.values(this.data1).some(roles => Object.values(roles).some(v => v))
  310       },
  311       set(checked) {
  312         this.toggleAll(checked)
  313       }
  314     }
  315   },
  316   watch: {},
  317   async created() {
  318     await this.aclInit()
  319   }
  320 }
  321 </script>
  322 
  323 <style scoped>
  324 
  325 </style>
  326 <!--
  327 /**
  328  * @copyright Copyright (c) 2021, Xgene Cloud Ltd
  329  *
  330  * @author Naveen MR <oof1lab@gmail.com>
  331  * @author Pranav C Balan <pranavxc@gmail.com>
  332  *
  333  * @license GNU AGPL version 3 or any later version
  334  *
  335  * This program is free software: you can redistribute it and/or modify
  336  * it under the terms of the GNU Affero General Public License as
  337  * published by the Free Software Foundation, either version 3 of the
  338  * License, or (at your option) any later version.
  339  *
  340  * This program is distributed in the hope that it will be useful,
  341  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  342  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  343  * GNU Affero General Public License for more details.
  344  *
  345  * You should have received a copy of the GNU Affero General Public License
  346  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  347  *
  348  */
  349 -->