Skip to content

Commit

Permalink
Merge pull request #23 from WeBankPartners/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
zgyzgyhero authored Aug 11, 2021
2 parents a67f5bf + a821c2b commit bcb3af7
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 17 deletions.
22 changes: 19 additions & 3 deletions api/terminal/terminal/apps/assets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ def list(self,
permission_filters['auth_' + auth_type] = 1
permissions = resource.Permission().list(permission_filters)
auth_asset_ids = []
for permission in permissions:
auth_asset_ids.extend([auth_asset['asset_id'] for auth_asset in permission['assets']])
auth_asset_ids = set(auth_asset_ids)
fields = {
'id': 'id',
CONF.asset.asset_field_name: 'name',
Expand All @@ -132,6 +129,12 @@ def list(self,
CONF.asset.asset_field_password: 'password',
CONF.asset.asset_field_desc: 'description'
}
for permission in permissions:
expression_assets = self.list_asset_by_expression(permission['expression'], fields)
auth_asset_ids.extend([auth_asset['asset_id'] for auth_asset in permission['assets']])
auth_asset_ids.extend([asset['id'] for asset in expression_assets])
auth_asset_ids = set(auth_asset_ids)

datas = []
filters = filters or {}
# expression search
Expand Down Expand Up @@ -188,6 +191,19 @@ def list(self,
item['password'] = origin_password.decode()
return datas

def list_asset_by_expression(self, expression, field_mapping):
if expression:
wecube_client = wecube.WeCubeClient(CONF.wecube.base_url, None)
wecube_client.token = self._token
resp = wecube_client.post(
wecube_client.build_url('/platform/v1/data-model/dme/integrated-query'), {
'dataModelExpression': expression,
'filters': []
})
assets = resp['data'] or []
return self._transform_field(assets, field_mapping)
return []


class AssetFile(object):
def upload(self, filename, fileobj, destpath, rid):
Expand Down
7 changes: 4 additions & 3 deletions api/terminal/terminal/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import absolute_import

from talos.db.dictbase import DictBase
from sqlalchemy import Column, DateTime, ForeignKey, String, text
from sqlalchemy import Column, DateTime, ForeignKey, String, text, Text
from sqlalchemy.dialects.mysql import BIGINT, TINYINT
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Expand All @@ -15,8 +15,8 @@
class Permission(Base, DictBase):
__tablename__ = 'permission'
attributes = [
'id', 'name', 'description', 'enabled', 'auth_upload', 'auth_download', 'auth_execute', 'created_by',
'created_time', 'updated_by', 'updated_time', 'assets', 'roles'
'id', 'name', 'description', 'enabled', 'auth_upload', 'auth_download', 'auth_execute', 'expression',
'created_by', 'created_time', 'updated_by', 'updated_time', 'assets', 'roles'
]

id = Column(BIGINT(20), primary_key=True)
Expand All @@ -26,6 +26,7 @@ class Permission(Base, DictBase):
auth_upload = Column(TINYINT(4), nullable=False)
auth_download = Column(TINYINT(4), nullable=False)
auth_execute = Column(TINYINT(4), nullable=False)
expression = Column(Text())
created_by = Column(String(36))
created_time = Column(DateTime)
updated_by = Column(String(36))
Expand Down
4 changes: 4 additions & 0 deletions api/terminal/terminal/db/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class Permission(MetaCRUD):
crud.ColumnValidator(field='auth_upload', rule_type='in', rule=[0, 1], validate_on=('create:M', 'update:O')),
crud.ColumnValidator(field='auth_download', rule_type='in', rule=[0, 1], validate_on=('create:M', 'update:O')),
crud.ColumnValidator(field='auth_execute', rule_type='in', rule=[0, 1], validate_on=('create:M', 'update:O')),
crud.ColumnValidator(field='expression',
rule=my_validator.LengthValidator(0, 10240),
validate_on=('create:O', 'update:O'),
nullable=True),
crud.ColumnValidator(field='enabled', rule_type='in', rule=[0, 1], validate_on=('create:M', 'update:O')),
crud.ColumnValidator(field='created_by', validate_on=('create:O', 'update:O'), nullable=True),
crud.ColumnValidator(field='created_time', validate_on=('create:O', 'update:O'), nullable=True),
Expand Down
8 changes: 7 additions & 1 deletion init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ CREATE TABLE `bookmark_roles` (

ALTER TABLE terminal.bookmark_roles ADD CONSTRAINT fkey_bookmark_roles FOREIGN KEY (bookmark_id) REFERENCES terminal.bookmark(id) ON DELETE CASCADE;

#@v0.1.0.1-end@;
#@v0.1.0.1-end@;

#@v0.2.2.1-begin@;

ALTER TABLE terminal.permission ADD expression TEXT NULL;

#@v0.2.2.1-end@;
4 changes: 3 additions & 1 deletion ui/src/api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const editPermissions = (id, data) => req.patch(`/terminal/v1/permissions

export const addCollection = data => req.post(`/terminal/v1/bookmarks`, data)
export const getTargetOptions = (pkgName, entityName) =>
req.get(`/platform/v1/packages/${pkgName}/entities/${entityName}/retrieve`)
req.post(`/${pkgName}/entities/${entityName}/query`, {
additionalFilters: []
})
export const getEntityRefsByPkgNameAndEntityName = (pkgName, entityName) =>
req.get(`/platform/v1/models/package/${pkgName}/entity/${entityName}`)
export const getAllDataModels = () => req.get(`/platform/v1/models`)
Expand Down
1 change: 1 addition & 0 deletions ui/src/locale/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"t_auth_download": "Auth Download",
"t_auth_upload": "Auth Upload",
"t_auth_execute": "Auth Execute",
"t_auth_expression": "Auth Expression",
"t_enabled": "Enabled",
"t_name": "Name",
"t_roles": "Roles",
Expand Down
1 change: 1 addition & 0 deletions ui/src/locale/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"t_auth_download": "下载",
"t_auth_upload": "上传",
"t_auth_execute": "执行",
"t_auth_expression": "表达式授权",
"t_enabled": "启用",
"t_name": "名称",
"t_roles": "角色",
Expand Down
40 changes: 33 additions & 7 deletions ui/src/pages/management/permissions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:placeholder="$t('t_asset_id')"
style="width:340px"
>
<Option v-for="item in assertsOption" :value="item.id" :key="item.id">{{ item.ip_address }}</Option>
<Option v-for="item in assertsOption" :value="item.id" :key="item.id">{{ item.ip_address + '(' + item.name + ')' }}</Option>
</Select>
<Select
v-model="roles_id"
Expand All @@ -30,10 +30,19 @@
<label class="col-md-2 label-name">{{ $t('t_asset_id') }}:</label>
<Select v-model="modelConfig.addRow.assets" multiple filterable style="width:340px">
<Option v-for="item in modelConfig.slotConfig.assertsOption" :value="item.id" :key="item.id">
{{ item.ip_address }}
{{ item.ip_address + '(' + item.name + ')' }}
</Option>
</Select>
</div>
<div class="marginbottom params-each">
<label class="col-md-2 label-name">{{ $t('t_auth_expression') }}:</label>
<span><FilterRules
style="width:340px;display:inline-block;vertical-align: middle;"
:needAttr="true"
v-model="modelConfig.addRow.expression"
:allDataModelsWithAttrs="allEntityType"
></FilterRules></span>
</div>
<div class="marginbottom params-each">
<label class="col-md-2 label-name">{{ $t('t_roles') }}:</label>
<Select v-model="modelConfig.addRow.roles" multiple filterable style="width:340px">
Expand Down Expand Up @@ -65,12 +74,14 @@
</template>

<script>
import { getTableData, getAssets, getAllRoles, savePermission, editPermissions, deleteTableRow } from '@/api/server'
import { getTableData, getAssets, getAllRoles, savePermission, editPermissions, deleteTableRow, getAllDataModels } from '@/api/server'
import FilterRules from '../components/filter-rules.vue'
let tableEle = [
{
title: 't_name',
value: 'name',
display: true
display: true,
style: { width: '200px' }
},
{
title: 't_asset_id',
Expand All @@ -83,6 +94,11 @@ let tableEle = [
return res.join('/')
}
},
{
title: 't_auth_expression',
value: 'expression',
display: true
},
{
title: 't_roles',
value: 'roles',
Expand Down Expand Up @@ -196,6 +212,7 @@ export default {
// [通用]-保存用户新增、编辑时数据
name: null,
assets: [],
expression: '',
roles: [],
auth_upload: 1,
auth_download: 1,
Expand All @@ -215,7 +232,8 @@ export default {
asset_id: '',
assertsOption: [],
roles_id: '',
rolesOption: []
rolesOption: [],
allEntityType: []
}
},
mounted () {
Expand All @@ -242,6 +260,12 @@ export default {
this.rolesOption = data
}
},
async getAllDataModels () {
let { data, status } = await getAllDataModels()
if (status === 'OK') {
this.allEntityType = data
}
},
async initTableData () {
if (!this.asset_id) {
delete this.pageConfig.researchConfig.filters['assets.asset_id']
Expand Down Expand Up @@ -269,8 +293,9 @@ export default {
const { status, data } = await getAllRoles()
if (status === 'OK') {
this.modelConfig.slotConfig.rolesOption = data
this.$root.JQ('#add_object_Modal').modal('show')
}
await this.getAllDataModels()
this.$root.JQ('#add_object_Modal').modal('show')
},
async addPost () {
const { status } = await savePermission([this.modelConfig.addRow])
Expand Down Expand Up @@ -298,6 +323,7 @@ export default {
if (status === 'OK') {
this.modelConfig.slotConfig.rolesOption = data
}
await this.getAllDataModels()
this.$root.JQ('#add_object_Modal').modal('show')
},
async editPost () {
Expand Down Expand Up @@ -329,7 +355,7 @@ export default {
})
}
},
components: {}
components: {FilterRules}
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/management/session-records.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:placeholder="$t('t_asset_id')"
style="width:340px"
>
<Option v-for="item in assertsOption" :value="item.id" :key="item.id">{{ item.ip_address }}</Option>
<Option v-for="item in assertsOption" :value="item.id" :key="item.id">{{ item.ip_address + '(' + item.name + ')' }}</Option>
</Select>
<DatePicker
type="datetimerange"
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/management/transfer-records.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:placeholder="$t('t_asset_id')"
style="width:340px"
>
<Option v-for="item in assertsOption" :value="item.id" :key="item.id">{{ item.ip_address }}</Option>
<Option v-for="item in assertsOption" :value="item.id" :key="item.id">{{ item.ip_address + '(' + item.name + ')' }}</Option>
</Select>
<DatePicker
type="datetimerange"
Expand Down

0 comments on commit bcb3af7

Please sign in to comment.