You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by GitBox <gi...@apache.org> on 2020/05/21 13:59:28 UTC

[GitHub] [cloudstack-primate] sureshanaparti opened a new pull request #353: UI changes for Dynamic roles improvements

sureshanaparti opened a new pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353


   Summary
   ===========
   
   This PR addresses the below UI improvements for current Dynamic roles functionality.
   
   - Export rules of a role to a CSV file, with name: _<RoleName>_<RoleType>.csv_
   - Import a role with its rules using a CSV file.
   - Create a role from any of the existing role.
   
   UI screens
   ===========
   
   Export Rules button:
   <img width="819" alt="ExportRulesFromRolePermissions" src="https://user-images.githubusercontent.com/12028987/82566102-0e462100-9b99-11ea-8b35-4fb014103d50.png">
   
   Import Role button:
   <img width="931" alt="ImportRoleButtonFromRolesUI" src="https://user-images.githubusercontent.com/12028987/82566138-1a31e300-9b99-11ea-8104-913029988ba3.png">
   
   Import Role UI:
   <img width="598" alt="ImportRoleUI" src="https://user-images.githubusercontent.com/12028987/82566149-1e5e0080-9b99-11ea-88a1-f9a6e7204581.png">
   
   Create Role UI, with Clone from Role:
   <img width="520" alt="CreateRole" src="https://user-images.githubusercontent.com/12028987/82566170-2453e180-9b99-11ea-9a88-ee856fb7625e.png">
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] borisstoyanov commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652208833


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-641079423






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r439951303



##########
File path: src/config/section/role.js
##########
@@ -35,12 +35,16 @@ export default {
       icon: 'plus',
       label: 'label.add.role',
       listView: true,
-      args: ['name', 'description', 'type'],
-      mapping: {
-        type: {
-          options: ['Admin', 'DomainAdmin', 'User']
-        }
-      }
+      popup: true,
+      component: () => import('@/views/iam/CreateRole.vue')
+    },
+    {
+      api: 'importRole',
+      icon: 'cloud-upload',
+      label: 'Import Role',

Review comment:
       @rhtyd Updated with new key in _locales/en.json_




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] rhtyd merged pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd merged pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-651051138


   Packaging result: :heavy_check_mark:centos :heavy_check_mark:debian :heavy_check_mark:archive.
   QA: http://primate-qa.cloudstack.cloud:8080/client/pr/353 (JID-2161)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-635422589


   > @sureshanaparti added some comments. I've not able to test the UI yet.
   > For translation, @rhtyd can comment better.
   > There are still too many strings directly used in ImportRole.vue
   
   Ignore other language translations except english


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429892387



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]

Review comment:
       Updated




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652250436


   Packaging result: :heavy_check_mark:centos :heavy_check_mark:debian :heavy_check_mark:archive.
   QA: http://primate-qa.cloudstack.cloud:8080/client/pr/353 (JID-2172)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] rhtyd commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-638049815


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-639261056


   Packaging result: :heavy_check_mark:centos :heavy_check_mark:debian :heavy_check_mark:archive.
   QA: http://primate-qa.cloudstack.cloud:8080/client/pr/353 (JID-1968)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-651718905


   @borisstoyanov a Jenkins job has been kicked to build primate packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429897348



##########
File path: src/views/iam/RolePermissionTab.vue
##########
@@ -227,6 +232,47 @@ export default {
         this.resetNewFields()
         this.fetchData()
       })
+    },
+    csv ({ data = null, columnDelimiter = ',', lineDelimiter = '\n' }) {
+      let result = null
+      let ctr = null
+
+      if (data === null || !data.length) {
+        return null
+      }
+
+      var keys = ['rule', 'permission', 'description']
+
+      result = ''
+      result += keys.join(columnDelimiter)
+      result += lineDelimiter
+
+      data.forEach(item => {
+        ctr = 0
+        keys.forEach(key => {
+          if (ctr > 0) {
+            result += columnDelimiter
+          }
+
+          if (item[key] === undefined) {
+            item[key] = ''
+          }
+          result += typeof item[key] === 'string' && item[key].includes(columnDelimiter) ? `"${item[key]}"` : item[key]
+          ctr++
+        })
+        result += lineDelimiter
+      })
+
+      return result
+    },
+    exportRolePermissions () {
+      const csvData = this.csv({ data: this.rules })
+
+      const hiddenElement = document.createElement('a')

Review comment:
       > we need to delete this element?
   
   element for the csv data to download as a file




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652875080


   @borisstoyanov a Jenkins job has been kicked to build primate packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429894803



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <a-form-item :label="$t('forced')">
+          <a-switch
+            v-decorator="['forced', {
+              initialValue: false
+            }]" />
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button>
+          <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+
+export default {
+  name: 'ImportRole',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    action: {
+      type: Object,
+      required: true
+    }
+  },
+  data () {
+    return {
+      fileList: [],
+      loading: false
+    }
+  },
+  beforeCreate () {
+    this.form = this.$form.createForm(this)
+  },
+  methods: {
+    handleRemove (file) {
+      const index = this.fileList.indexOf(file)
+      const newFileList = this.fileList.slice()
+      newFileList.splice(index, 1)
+      this.fileList = newFileList
+    },
+    handleChange (info) {
+      if (info.file.status === 'error') {
+        this.$notification.error({
+          message: 'File Upload Failed',
+          description: 'File: ' + info.file.name + ' Upload Failed'
+        })
+      }
+    },
+    beforeUpload (file) {
+      if (file.type !== 'text/csv') {
+        alert('Only CSV file can be imported')
+        return false
+      }
+
+      this.fileList = [file]
+      return false
+    },
+    handleSubmit (e) {
+      e.preventDefault()
+      this.form.validateFields((err, values) => {
+        if (err) {
+          return
+        }
+        const params = {}
+        for (const key in values) {
+          const input = values[key]
+          if (input === undefined) {
+            continue
+          }
+          if (key === 'file') {
+            continue
+          }
+
+          params[key] = input
+        }
+
+        if (this.fileList.length !== 1) {
+          return
+        }
+
+        this.loadCSVFile(this.fileList[0]).then((rules) => {
+          rules.forEach(function (values, index) {
+            for (const key in values) {
+              params['rules[' + index + '].' + key] = values[key]
+            }
+          })
+
+          this.importRole(params)
+        })
+      })
+    },
+    closeAction () {
+      this.$emit('close-action')
+    },
+    importRole (params) {
+      this.loading = true
+      api('importRole', {}, 'POST', params).then(json => {
+        const role = json.importroleresponse.role
+        if (role) {
+          this.$emit('refresh-data')
+          this.$notification.success({
+            message: 'Import Role',
+            description: 'Sucessfully imported Role ' + params.name
+          })
+        }
+      }).catch(error => {
+        this.$notifyError(error)
+      }).finally(() => {
+        this.loading = false
+        this.closeAction()
+      })
+    },
+    csvToJson (csv) {
+      var lines = csv.split('\n')
+      var result = []
+      var headers = lines[0].split(',')
+
+      lines.map((line, indexLine) => {
+        if (indexLine < 1) return // Jump header line
+        var obj = {}
+        var currentline = line.split(',')
+
+        headers.map((header, indexHeader) => {
+          obj[header] = currentline[indexHeader]
+        })
+        result.push(obj)
+      })
+      result.pop() // remove the last item because undefined values
+
+      return result
+    },
+    loadCSVFile (file) {
+      return new Promise((resolve, reject) => {
+        if (window.FileReader) {
+          var reader = new FileReader()
+          reader.onload = (event) => {
+            var csv = event.target.result
+            // var lines = csv.split('\n')
+            // var result = []
+            // var headers = lines[0].split(',')
+
+            // lines.map((line, indexLine) => {
+            //  if (indexLine < 1) return
+            //  var obj = {}
+            //  var currentline = line.split(',')
+
+            //  headers.map((header, indexHeader) => {
+            //    obj[header] = currentline[indexHeader]
+            //  })
+            //  result.push(obj)
+            // })
+            // result.pop()
+

Review comment:
       > To be removed
   
   Removed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652212091


   Packaging result: :heavy_check_mark:centos :heavy_check_mark:debian :heavy_check_mark:archive.
   QA: http://primate-qa.cloudstack.cloud:8080/client/pr/353 (JID-2170)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] rhtyd commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-649490466


   @davidjumani @shwstppr can you review this as well?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-645765662


   @rhtyd a Jenkins job has been kicked to build primate packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429893783



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]

Review comment:
       Used existing translation `message.error.select`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429892025



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">

Review comment:
       updated the key to rules.file. @shwstppr have address other existing keys to be aligned to this pattern, may be in separate PR.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429894679



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <a-form-item :label="$t('forced')">
+          <a-switch
+            v-decorator="['forced', {
+              initialValue: false
+            }]" />
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button>
+          <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+
+export default {
+  name: 'ImportRole',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    action: {
+      type: Object,
+      required: true
+    }

Review comment:
       > Is this used in code?
   
   Unused code, removed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] rhtyd commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r439937108



##########
File path: src/config/section/role.js
##########
@@ -35,12 +35,16 @@ export default {
       icon: 'plus',
       label: 'label.add.role',
       listView: true,
-      args: ['name', 'description', 'type'],
-      mapping: {
-        type: {
-          options: ['Admin', 'DomainAdmin', 'User']
-        }
-      }
+      popup: true,
+      component: () => import('@/views/iam/CreateRole.vue')
+    },
+    {
+      api: 'importRole',
+      icon: 'cloud-upload',
+      label: 'Import Role',

Review comment:
       @sureshanaparti please move this to locales/en.json; add a new key.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] borisstoyanov commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652874466


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] rhtyd commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-639258936


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429892142



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">

Review comment:
       > can the key here read rules.file or something? Will be more aligned to other translation keys
   
   updated the key to rules.file. @shwstppr have address other existing keys to be aligned to this pattern, may be in separate PR.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-639259048


   @rhtyd a Jenkins job has been kicked to build primate packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429892889



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]

Review comment:
       Updated




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] rhtyd commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-641078953


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652880263


   Packaging result: :heavy_check_mark:centos :heavy_check_mark:debian :heavy_check_mark:archive.
   QA: http://primate-qa.cloudstack.cloud:8080/client/pr/353 (JID-2190)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652246608


   @borisstoyanov a Jenkins job has been kicked to build primate packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-651722056


   Packaging result: :heavy_check_mark:centos :heavy_check_mark:debian :heavy_check_mark:archive.
   QA: http://primate-qa.cloudstack.cloud:8080/client/pr/353 (JID-2167)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-638050309


   @rhtyd a Jenkins job has been kicked to build primate packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429894468



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>

Review comment:
       > Do we need to call listRoles API instead or the functionality limited to these roles only?
   
   @shwstppr These are role types, limited to 4 types only: Admin, DomainAdmin, ResourceAdmin, User.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] borisstoyanov commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652246144


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429895293



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <a-form-item :label="$t('forced')">
+          <a-switch
+            v-decorator="['forced', {
+              initialValue: false
+            }]" />
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button>
+          <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+
+export default {
+  name: 'ImportRole',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    action: {
+      type: Object,
+      required: true
+    }
+  },
+  data () {
+    return {
+      fileList: [],
+      loading: false
+    }
+  },
+  beforeCreate () {
+    this.form = this.$form.createForm(this)
+  },
+  methods: {
+    handleRemove (file) {
+      const index = this.fileList.indexOf(file)
+      const newFileList = this.fileList.slice()
+      newFileList.splice(index, 1)
+      this.fileList = newFileList
+    },
+    handleChange (info) {
+      if (info.file.status === 'error') {
+        this.$notification.error({
+          message: 'File Upload Failed',
+          description: 'File: ' + info.file.name + ' Upload Failed'
+        })
+      }
+    },
+    beforeUpload (file) {
+      if (file.type !== 'text/csv') {
+        alert('Only CSV file can be imported')
+        return false
+      }
+
+      this.fileList = [file]
+      return false
+    },
+    handleSubmit (e) {
+      e.preventDefault()
+      this.form.validateFields((err, values) => {
+        if (err) {
+          return
+        }
+        const params = {}
+        for (const key in values) {
+          const input = values[key]
+          if (input === undefined) {
+            continue
+          }
+          if (key === 'file') {
+            continue
+          }
+
+          params[key] = input
+        }
+
+        if (this.fileList.length !== 1) {
+          return
+        }
+
+        this.loadCSVFile(this.fileList[0]).then((rules) => {
+          rules.forEach(function (values, index) {
+            for (const key in values) {
+              params['rules[' + index + '].' + key] = values[key]
+            }
+          })
+
+          this.importRole(params)
+        })
+      })
+    },
+    closeAction () {
+      this.$emit('close-action')
+    },
+    importRole (params) {
+      this.loading = true
+      api('importRole', {}, 'POST', params).then(json => {
+        const role = json.importroleresponse.role
+        if (role) {
+          this.$emit('refresh-data')
+          this.$notification.success({
+            message: 'Import Role',
+            description: 'Sucessfully imported Role ' + params.name
+          })
+        }
+      }).catch(error => {
+        this.$notifyError(error)
+      }).finally(() => {
+        this.loading = false
+        this.closeAction()
+      })
+    },
+    csvToJson (csv) {
+      var lines = csv.split('\n')
+      var result = []
+      var headers = lines[0].split(',')
+
+      lines.map((line, indexLine) => {
+        if (indexLine < 1) return // Jump header line
+        var obj = {}
+        var currentline = line.split(',')
+
+        headers.map((header, indexHeader) => {
+          obj[header] = currentline[indexHeader]
+        })
+        result.push(obj)
+      })
+      result.pop() // remove the last item because undefined values
+
+      return result
+    },
+    loadCSVFile (file) {
+      return new Promise((resolve, reject) => {
+        if (window.FileReader) {
+          var reader = new FileReader()
+          reader.onload = (event) => {
+            var csv = event.target.result
+            // var lines = csv.split('\n')
+            // var result = []
+            // var headers = lines[0].split(',')
+
+            // lines.map((line, indexLine) => {
+            //  if (indexLine < 1) return
+            //  var obj = {}
+            //  var currentline = line.split(',')
+
+            //  headers.map((header, indexHeader) => {
+            //    obj[header] = currentline[indexHeader]
+            //  })
+            //  result.push(obj)
+            // })
+            // result.pop()
+
+            var rules = this.csvToJson(csv)
+            resolve(rules)
+          }
+
+          reader.onerror = (event) => {
+            if (event.target.error.name === 'NotReadableError') {
+              alert('Cannot read file!')

Review comment:
       > Probably trying to show validation error but we don't show `alert`.
   > Not sure if this can help
   > 
   > https://github.com/apache/cloudstack-primate/blob/5ce6d1ca4606add910dd9bd40a410d57306bec78/src/views/offering/AddComputeOffering.vue#L497-L502
   
   @shwstppr Used this.$error() for alert dialog




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-645771624


   Packaging result: :heavy_check_mark:centos :heavy_check_mark:debian :heavy_check_mark:archive.
   QA: http://primate-qa.cloudstack.cloud:8080/client/pr/353 (JID-2042)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429892693



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import

Review comment:
       Added this string to translation file

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import

Review comment:
       > can be added in the translation file
   
   Added this string to translation file




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-651047268


   @davidjumani a Jenkins job has been kicked to build primate packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429893457



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />

Review comment:
       > We can directly show the description of API parameters as placeholders. See,
   > https://github.com/apache/cloudstack-primate/blob/master/src/views/image/RegisterOrUploadTemplate.vue#L66
   > https://github.com/apache/cloudstack-primate/blob/master/src/views/image/RegisterOrUploadTemplate.vue#L411-L415
   
   @shwstppr Thanks for pointing to this code. I've updated the code.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] shwstppr commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
shwstppr commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429199025



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]

Review comment:
       ```suggestion
                 rules: [{ required: true, message: $t('message.error.required.input') }]
   ```

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]

Review comment:
       ```suggestion
                 rules: [{ required: true, message: $t('message.error.required.input') }]
   ```

##########
File path: src/views/iam/RolePermissionTab.vue
##########
@@ -227,6 +232,47 @@ export default {
         this.resetNewFields()
         this.fetchData()
       })
+    },
+    csv ({ data = null, columnDelimiter = ',', lineDelimiter = '\n' }) {

Review comment:
       can we have a better name for method, something like generateRulesCSV, etc

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]

Review comment:
       message.error.required.input can be used

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>

Review comment:
       Do we need to call listRoles API instead or the functionality limited to these roles only?

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <a-form-item :label="$t('forced')">
+          <a-switch
+            v-decorator="['forced', {
+              initialValue: false
+            }]" />
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button>
+          <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+
+export default {
+  name: 'ImportRole',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    action: {
+      type: Object,
+      required: true
+    }

Review comment:
       Is this used in code?

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />

Review comment:
       We can directly show the description of API parameters as placeholders. See,
   https://github.com/apache/cloudstack-primate/blob/master/src/views/image/RegisterOrUploadTemplate.vue#L66
   https://github.com/apache/cloudstack-primate/blob/master/src/views/image/RegisterOrUploadTemplate.vue#L411-L415

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import

Review comment:
       can be added in the translation file

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">

Review comment:
       can the key here read rules.file or something? Will be more aligned to other translation keys

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <a-form-item :label="$t('forced')">
+          <a-switch
+            v-decorator="['forced', {
+              initialValue: false
+            }]" />
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button>
+          <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+
+export default {
+  name: 'ImportRole',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    action: {
+      type: Object,
+      required: true
+    }
+  },
+  data () {
+    return {
+      fileList: [],
+      loading: false
+    }
+  },
+  beforeCreate () {
+    this.form = this.$form.createForm(this)
+  },
+  methods: {
+    handleRemove (file) {
+      const index = this.fileList.indexOf(file)
+      const newFileList = this.fileList.slice()
+      newFileList.splice(index, 1)
+      this.fileList = newFileList
+    },
+    handleChange (info) {
+      if (info.file.status === 'error') {
+        this.$notification.error({
+          message: 'File Upload Failed',
+          description: 'File: ' + info.file.name + ' Upload Failed'
+        })
+      }
+    },
+    beforeUpload (file) {
+      if (file.type !== 'text/csv') {
+        alert('Only CSV file can be imported')
+        return false
+      }
+
+      this.fileList = [file]
+      return false
+    },
+    handleSubmit (e) {
+      e.preventDefault()
+      this.form.validateFields((err, values) => {
+        if (err) {
+          return
+        }
+        const params = {}
+        for (const key in values) {
+          const input = values[key]
+          if (input === undefined) {
+            continue
+          }
+          if (key === 'file') {
+            continue
+          }
+
+          params[key] = input
+        }
+
+        if (this.fileList.length !== 1) {
+          return
+        }
+
+        this.loadCSVFile(this.fileList[0]).then((rules) => {
+          rules.forEach(function (values, index) {
+            for (const key in values) {
+              params['rules[' + index + '].' + key] = values[key]
+            }
+          })
+
+          this.importRole(params)
+        })
+      })
+    },
+    closeAction () {
+      this.$emit('close-action')
+    },
+    importRole (params) {
+      this.loading = true
+      api('importRole', {}, 'POST', params).then(json => {
+        const role = json.importroleresponse.role
+        if (role) {
+          this.$emit('refresh-data')
+          this.$notification.success({
+            message: 'Import Role',
+            description: 'Sucessfully imported Role ' + params.name
+          })
+        }
+      }).catch(error => {
+        this.$notifyError(error)
+      }).finally(() => {
+        this.loading = false
+        this.closeAction()
+      })
+    },
+    csvToJson (csv) {
+      var lines = csv.split('\n')
+      var result = []
+      var headers = lines[0].split(',')
+
+      lines.map((line, indexLine) => {
+        if (indexLine < 1) return // Jump header line
+        var obj = {}
+        var currentline = line.split(',')
+
+        headers.map((header, indexHeader) => {
+          obj[header] = currentline[indexHeader]
+        })
+        result.push(obj)
+      })
+      result.pop() // remove the last item because undefined values
+
+      return result
+    },
+    loadCSVFile (file) {
+      return new Promise((resolve, reject) => {
+        if (window.FileReader) {
+          var reader = new FileReader()
+          reader.onload = (event) => {
+            var csv = event.target.result
+            // var lines = csv.split('\n')
+            // var result = []
+            // var headers = lines[0].split(',')
+
+            // lines.map((line, indexLine) => {
+            //  if (indexLine < 1) return
+            //  var obj = {}
+            //  var currentline = line.split(',')
+
+            //  headers.map((header, indexHeader) => {
+            //    obj[header] = currentline[indexHeader]
+            //  })
+            //  result.push(obj)
+            // })
+            // result.pop()
+
+            var rules = this.csvToJson(csv)
+            resolve(rules)
+          }
+
+          reader.onerror = (event) => {
+            if (event.target.error.name === 'NotReadableError') {
+              alert('Cannot read file!')

Review comment:
       Probably trying to show validation error but we don't show `alert`.
   Not sure if this can help https://github.com/apache/cloudstack-primate/blob/5ce6d1ca4606add910dd9bd40a410d57306bec78/src/views/offering/AddComputeOffering.vue#L497-L502

##########
File path: src/views/iam/RolePermissionTab.vue
##########
@@ -227,6 +232,47 @@ export default {
         this.resetNewFields()
         this.fetchData()
       })
+    },
+    csv ({ data = null, columnDelimiter = ',', lineDelimiter = '\n' }) {
+      let result = null
+      let ctr = null
+
+      if (data === null || !data.length) {
+        return null
+      }
+
+      var keys = ['rule', 'permission', 'description']
+
+      result = ''
+      result += keys.join(columnDelimiter)
+      result += lineDelimiter
+
+      data.forEach(item => {
+        ctr = 0
+        keys.forEach(key => {
+          if (ctr > 0) {
+            result += columnDelimiter
+          }
+
+          if (item[key] === undefined) {
+            item[key] = ''
+          }
+          result += typeof item[key] === 'string' && item[key].includes(columnDelimiter) ? `"${item[key]}"` : item[key]
+          ctr++
+        })
+        result += lineDelimiter
+      })
+
+      return result
+    },
+    exportRolePermissions () {
+      const csvData = this.csv({ data: this.rules })
+
+      const hiddenElement = document.createElement('a')

Review comment:
       we need to delete this element?

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <a-form-item :label="$t('forced')">
+          <a-switch
+            v-decorator="['forced', {
+              initialValue: false
+            }]" />
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button>
+          <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+
+export default {
+  name: 'ImportRole',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    action: {
+      type: Object,
+      required: true
+    }
+  },
+  data () {
+    return {
+      fileList: [],
+      loading: false
+    }
+  },
+  beforeCreate () {
+    this.form = this.$form.createForm(this)
+  },
+  methods: {
+    handleRemove (file) {
+      const index = this.fileList.indexOf(file)
+      const newFileList = this.fileList.slice()
+      newFileList.splice(index, 1)
+      this.fileList = newFileList
+    },
+    handleChange (info) {
+      if (info.file.status === 'error') {
+        this.$notification.error({
+          message: 'File Upload Failed',
+          description: 'File: ' + info.file.name + ' Upload Failed'
+        })
+      }
+    },
+    beforeUpload (file) {
+      if (file.type !== 'text/csv') {
+        alert('Only CSV file can be imported')
+        return false
+      }
+
+      this.fileList = [file]
+      return false
+    },
+    handleSubmit (e) {
+      e.preventDefault()
+      this.form.validateFields((err, values) => {
+        if (err) {
+          return
+        }
+        const params = {}
+        for (const key in values) {
+          const input = values[key]
+          if (input === undefined) {
+            continue
+          }
+          if (key === 'file') {
+            continue
+          }
+
+          params[key] = input
+        }
+
+        if (this.fileList.length !== 1) {
+          return
+        }
+
+        this.loadCSVFile(this.fileList[0]).then((rules) => {
+          rules.forEach(function (values, index) {
+            for (const key in values) {
+              params['rules[' + index + '].' + key] = values[key]
+            }
+          })
+
+          this.importRole(params)
+        })
+      })
+    },
+    closeAction () {
+      this.$emit('close-action')
+    },
+    importRole (params) {
+      this.loading = true
+      api('importRole', {}, 'POST', params).then(json => {
+        const role = json.importroleresponse.role
+        if (role) {
+          this.$emit('refresh-data')
+          this.$notification.success({
+            message: 'Import Role',
+            description: 'Sucessfully imported Role ' + params.name
+          })
+        }
+      }).catch(error => {
+        this.$notifyError(error)
+      }).finally(() => {
+        this.loading = false
+        this.closeAction()
+      })
+    },
+    csvToJson (csv) {
+      var lines = csv.split('\n')
+      var result = []
+      var headers = lines[0].split(',')
+
+      lines.map((line, indexLine) => {
+        if (indexLine < 1) return // Jump header line
+        var obj = {}
+        var currentline = line.split(',')
+
+        headers.map((header, indexHeader) => {
+          obj[header] = currentline[indexHeader]
+        })
+        result.push(obj)
+      })
+      result.pop() // remove the last item because undefined values
+
+      return result
+    },
+    loadCSVFile (file) {
+      return new Promise((resolve, reject) => {
+        if (window.FileReader) {
+          var reader = new FileReader()
+          reader.onload = (event) => {
+            var csv = event.target.result
+            // var lines = csv.split('\n')
+            // var result = []
+            // var headers = lines[0].split(',')
+
+            // lines.map((line, indexLine) => {
+            //  if (indexLine < 1) return
+            //  var obj = {}
+            //  var currentline = line.split(',')
+
+            //  headers.map((header, indexHeader) => {
+            //    obj[header] = currentline[indexHeader]
+            //  })
+            //  result.push(obj)
+            // })
+            // result.pop()
+

Review comment:
       To be removed

##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <a-form-item :label="$t('forced')">
+          <a-switch
+            v-decorator="['forced', {
+              initialValue: false
+            }]" />
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button>
+          <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+
+export default {
+  name: 'ImportRole',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    action: {
+      type: Object,
+      required: true
+    }
+  },
+  data () {
+    return {
+      fileList: [],
+      loading: false
+    }
+  },
+  beforeCreate () {
+    this.form = this.$form.createForm(this)
+  },
+  methods: {
+    handleRemove (file) {
+      const index = this.fileList.indexOf(file)
+      const newFileList = this.fileList.slice()
+      newFileList.splice(index, 1)
+      this.fileList = newFileList
+    },
+    handleChange (info) {
+      if (info.file.status === 'error') {
+        this.$notification.error({
+          message: 'File Upload Failed',
+          description: 'File: ' + info.file.name + ' Upload Failed'
+        })
+      }
+    },
+    beforeUpload (file) {
+      if (file.type !== 'text/csv') {
+        alert('Only CSV file can be imported')
+        return false
+      }
+
+      this.fileList = [file]
+      return false
+    },
+    handleSubmit (e) {
+      e.preventDefault()
+      this.form.validateFields((err, values) => {
+        if (err) {
+          return
+        }
+        const params = {}
+        for (const key in values) {
+          const input = values[key]
+          if (input === undefined) {
+            continue
+          }
+          if (key === 'file') {
+            continue
+          }
+
+          params[key] = input
+        }
+
+        if (this.fileList.length !== 1) {
+          return
+        }
+
+        this.loadCSVFile(this.fileList[0]).then((rules) => {
+          rules.forEach(function (values, index) {
+            for (const key in values) {
+              params['rules[' + index + '].' + key] = values[key]
+            }
+          })
+
+          this.importRole(params)
+        })
+      })
+    },
+    closeAction () {
+      this.$emit('close-action')
+    },
+    importRole (params) {
+      this.loading = true
+      api('importRole', {}, 'POST', params).then(json => {
+        const role = json.importroleresponse.role
+        if (role) {
+          this.$emit('refresh-data')
+          this.$notification.success({
+            message: 'Import Role',
+            description: 'Sucessfully imported Role ' + params.name
+          })
+        }
+      }).catch(error => {
+        this.$notifyError(error)
+      }).finally(() => {
+        this.loading = false
+        this.closeAction()
+      })
+    },
+    csvToJson (csv) {
+      var lines = csv.split('\n')
+      var result = []
+      var headers = lines[0].split(',')
+
+      lines.map((line, indexLine) => {
+        if (indexLine < 1) return // Jump header line
+        var obj = {}
+        var currentline = line.split(',')
+
+        headers.map((header, indexHeader) => {
+          obj[header] = currentline[indexHeader]
+        })
+        result.push(obj)
+      })
+      result.pop() // remove the last item because undefined values
+
+      return result
+    },
+    loadCSVFile (file) {
+      return new Promise((resolve, reject) => {
+        if (window.FileReader) {
+          var reader = new FileReader()
+          reader.onload = (event) => {
+            var csv = event.target.result
+            // var lines = csv.split('\n')
+            // var result = []
+            // var headers = lines[0].split(',')
+
+            // lines.map((line, indexLine) => {
+            //  if (indexLine < 1) return
+            //  var obj = {}
+            //  var currentline = line.split(',')
+
+            //  headers.map((header, indexHeader) => {
+            //    obj[header] = currentline[indexHeader]
+            //  })
+            //  result.push(obj)
+            // })
+            // result.pop()
+
+            var rules = this.csvToJson(csv)
+            resolve(rules)
+          }
+
+          reader.onerror = (event) => {
+            if (event.target.error.name === 'NotReadableError') {
+              alert('Cannot read file!')
+              reject(event.target.error)
+            }
+          }
+
+          reader.readAsText(file)
+        } else {
+          alert('FileReader not supported in this browser.')

Review comment:
       Better use `this.$notification.error` or check if it can be show through validator




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] borisstoyanov commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-651718631


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-652209221


   @borisstoyanov a Jenkins job has been kicked to build primate packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429895447



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <a-form-item :label="$t('forced')">
+          <a-switch
+            v-decorator="['forced', {
+              initialValue: false
+            }]" />
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button>
+          <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+
+export default {
+  name: 'ImportRole',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    action: {
+      type: Object,
+      required: true
+    }
+  },
+  data () {
+    return {
+      fileList: [],
+      loading: false
+    }
+  },
+  beforeCreate () {
+    this.form = this.$form.createForm(this)
+  },
+  methods: {
+    handleRemove (file) {
+      const index = this.fileList.indexOf(file)
+      const newFileList = this.fileList.slice()
+      newFileList.splice(index, 1)
+      this.fileList = newFileList
+    },
+    handleChange (info) {
+      if (info.file.status === 'error') {
+        this.$notification.error({
+          message: 'File Upload Failed',
+          description: 'File: ' + info.file.name + ' Upload Failed'
+        })
+      }
+    },
+    beforeUpload (file) {
+      if (file.type !== 'text/csv') {
+        alert('Only CSV file can be imported')
+        return false
+      }
+
+      this.fileList = [file]
+      return false
+    },
+    handleSubmit (e) {
+      e.preventDefault()
+      this.form.validateFields((err, values) => {
+        if (err) {
+          return
+        }
+        const params = {}
+        for (const key in values) {
+          const input = values[key]
+          if (input === undefined) {
+            continue
+          }
+          if (key === 'file') {
+            continue
+          }
+
+          params[key] = input
+        }
+
+        if (this.fileList.length !== 1) {
+          return
+        }
+
+        this.loadCSVFile(this.fileList[0]).then((rules) => {
+          rules.forEach(function (values, index) {
+            for (const key in values) {
+              params['rules[' + index + '].' + key] = values[key]
+            }
+          })
+
+          this.importRole(params)
+        })
+      })
+    },
+    closeAction () {
+      this.$emit('close-action')
+    },
+    importRole (params) {
+      this.loading = true
+      api('importRole', {}, 'POST', params).then(json => {
+        const role = json.importroleresponse.role
+        if (role) {
+          this.$emit('refresh-data')
+          this.$notification.success({
+            message: 'Import Role',
+            description: 'Sucessfully imported Role ' + params.name
+          })
+        }
+      }).catch(error => {
+        this.$notifyError(error)
+      }).finally(() => {
+        this.loading = false
+        this.closeAction()
+      })
+    },
+    csvToJson (csv) {
+      var lines = csv.split('\n')
+      var result = []
+      var headers = lines[0].split(',')
+
+      lines.map((line, indexLine) => {
+        if (indexLine < 1) return // Jump header line
+        var obj = {}
+        var currentline = line.split(',')
+
+        headers.map((header, indexHeader) => {
+          obj[header] = currentline[indexHeader]
+        })
+        result.push(obj)
+      })
+      result.pop() // remove the last item because undefined values
+
+      return result
+    },
+    loadCSVFile (file) {
+      return new Promise((resolve, reject) => {
+        if (window.FileReader) {
+          var reader = new FileReader()
+          reader.onload = (event) => {
+            var csv = event.target.result
+            // var lines = csv.split('\n')
+            // var result = []
+            // var headers = lines[0].split(',')
+
+            // lines.map((line, indexLine) => {
+            //  if (indexLine < 1) return
+            //  var obj = {}
+            //  var currentline = line.split(',')
+
+            //  headers.map((header, indexHeader) => {
+            //    obj[header] = currentline[indexHeader]
+            //  })
+            //  result.push(obj)
+            // })
+            // result.pop()
+
+            var rules = this.csvToJson(csv)
+            resolve(rules)
+          }
+
+          reader.onerror = (event) => {
+            if (event.target.error.name === 'NotReadableError') {
+              alert('Cannot read file!')
+              reject(event.target.error)
+            }
+          }
+
+          reader.readAsText(file)
+        } else {
+          alert('FileReader not supported in this browser.')

Review comment:
       > Better use `this.$notification.error` or check if it can be show through validator
   
   Used this.$error() for alert dialog




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] rhtyd commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r439937266



##########
File path: src/views/iam/ImportRole.vue
##########
@@ -0,0 +1,267 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item :label="$t('rulesFile')">
+          <a-upload-dragger
+            :multiple="false"
+            :fileList="fileList"
+            :remove="handleRemove"
+            :beforeUpload="beforeUpload"
+            @change="handleChange"
+            v-decorator="['file', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]">
+            <p class="ant-upload-drag-icon">
+              <a-icon type="cloud-upload" />
+            </p>
+            <p class="ant-upload-text" v-if="fileList.length === 0">
+              Click or drag rule defintions CVS file to import
+            </p>
+          </a-upload-dragger>
+        </a-form-item>
+        <a-form-item :label="$t('name')">
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: 'Please enter input' }]
+            }]"
+            :placeholder="$t('role.name')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('description')">
+          <a-input
+            v-decorator="['description']"
+            :placeholder="$t('role.description')" />
+        </a-form-item>
+
+        <a-form-item :label="$t('type')">
+          <a-select
+            v-decorator="['type', {
+              rules: [{ required: true, message: 'Please select option'}]
+            }]"
+            :placeholder="$t('role.type')">
+            <a-select-option value="Admin">Admin</a-select-option>
+            <a-select-option value="DomainAdmin">DomainAdmin</a-select-option>
+            <a-select-option value="ResourceAdmin">ResourceAdmin</a-select-option>
+            <a-select-option value="User">User</a-select-option>

Review comment:
       Instead of manually writing the html; why not define an array of the default 4 types and use a v-for?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] blueorangutan commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-638054615


   Packaging result: :heavy_check_mark:centos :heavy_check_mark:debian :heavy_check_mark:archive. JID-1958


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] davidjumani commented on pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#issuecomment-651040713


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack-primate] sureshanaparti commented on a change in pull request #353: UI changes for Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #353:
URL: https://github.com/apache/cloudstack-primate/pull/353#discussion_r429896090



##########
File path: src/views/iam/RolePermissionTab.vue
##########
@@ -227,6 +232,47 @@ export default {
         this.resetNewFields()
         this.fetchData()
       })
+    },
+    csv ({ data = null, columnDelimiter = ',', lineDelimiter = '\n' }) {

Review comment:
       > can we have a better name for method, something like generateRulesCSV, etc
   
   updated method name




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org