KYLIN-2918 table acl gui Signed-off-by: chenzhx <c...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/1388b73b Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/1388b73b Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/1388b73b Branch: refs/heads/KYLIN-2881-review Commit: 1388b73be3ccae9e7aa6cdd07f41dd7ebbff1fa8 Parents: 0162d88 Author: luguosheng1314 <550175...@qq.com> Authored: Thu Jan 4 14:44:07 2018 +0800 Committer: chenzhx <c...@apache.org> Committed: Tue Jan 16 14:49:53 2018 +0800 ---------------------------------------------------------------------- webapp/app/index.html | 3 + webapp/app/js/controllers/acl.js | 145 ++++++++++++++++++++++ webapp/app/js/services/acl.js | 26 ++++ webapp/app/partials/tables/table_access.html | 133 ++++++++++++++++++++ webapp/app/partials/tables/table_detail.html | 20 +++ 5 files changed, 327 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/1388b73b/webapp/app/index.html ---------------------------------------------------------------------- diff --git a/webapp/app/index.html b/webapp/app/index.html index 791aa4a..12daaa2 100644 --- a/webapp/app/index.html +++ b/webapp/app/index.html @@ -146,6 +146,7 @@ <script src="js/services/tree.js"></script> <script src="js/services/users.js"></script> <script src="js/services/ngLoading.js"></script> +<script src="js/services/acl.js"></script> <!--New GUI--> <script src="js/services/models.js"></script> <script src="js/services/dashboard.js"></script> @@ -193,6 +194,8 @@ <script src="js/controllers/cubeAdvanceSetting.js"></script> <script src="js/controllers/cubeOverwriteProp.js"></script> <script src="js/controllers/cubeMeasures.js"></script> +<script src="js/controllers/acl.js"></script> + <!--New GUI--> <script src="js/controllers/modelSchema.js"></script> <script src="js/controllers/modelDimensions.js"></script> http://git-wip-us.apache.org/repos/asf/kylin/blob/1388b73b/webapp/app/js/controllers/acl.js ---------------------------------------------------------------------- diff --git a/webapp/app/js/controllers/acl.js b/webapp/app/js/controllers/acl.js new file mode 100644 index 0000000..6f83d21 --- /dev/null +++ b/webapp/app/js/controllers/acl.js @@ -0,0 +1,145 @@ +/* + * 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. + */ + +'use strict'; +KylinApp.controller('AclCtrl', function ($scope, AclService, TableModel,loadingRequest,SweetAlert,$modal, ProjectModel) { + $scope.tableModel = TableModel; + $scope.tableUserAclList = []; + $scope.tableGroupAclList = []; + $scope.selectTableName = ''; + $scope.projectModel = ProjectModel; + var loadTableAclList = function (loadtype) { + if (!loadtype || loadtype === 'user') { + AclService.getTableAclList({ + project:$scope.projectModel.selectedProject, + tablename:$scope.selectTableName, + type:'user' + }, function (result) { + $scope.tableUserAclList = result; + }) + } + if (!loadtype || loadtype === 'group') { + AclService.getTableAclList({ + project: $scope.projectModel.selectedProject, + tablename: $scope.selectTableName, + type: 'group' + }, function (result) { + $scope.tableGroupAclList = result; + }) + } + + } + + $scope.$watch('tableModel.selectedSrcTable.name',function(){ + $scope.selectTableName = TableModel.selectedSrcTable.database +'.'+ TableModel.selectedSrcTable.name + if(!TableModel.selectedSrcTable.name || !$scope.projectModel) { + return; + } + loadTableAclList(); + }); + $scope.delTableAcl = function (type, name) { + SweetAlert.swal({ + title: '', + text: "Are you sure to drop this table acl?", + type: '', + showCancelButton: true, + confirmButtonColor: '#DD6B55', + confirmButtonText: "Yes", + closeOnConfirm: true + }, function (isConfirm) { + if (isConfirm) { + loadingRequest.show(); + AclService.cancelAclSetOfTable({ + type:type, + project: $scope.projectModel.selectedProject, + tablename:$scope.selectTableName, + username: name + },function () { + loadingRequest.hide(); + loadTableAclList(type); + SweetAlert.swal('Success!', 'Table acl drop is done successfully', 'success'); + }) + } + }) + } + + $scope.addTableAcl = function(model){ + $modal.open({ + templateUrl: 'addTableAcl.html', + windowClass:"cubewindow", + controller: AclAddCtrl, + resolve: { + scope: function () { + return $scope; + } + } + }); + } + var AclAddCtrl = function ($scope, $modalInstance, AclService,SweetAlert,loadingRequest,ProjectModel,TableModel) { + $scope.newTableAcl = { + type: 'user', + name: '' + } + $scope.selectTableName = TableModel.selectedSrcTable.database +'.'+ TableModel.selectedSrcTable.name + $scope.projectModel = ProjectModel; + $scope.tableUserAclBlackList = [] + $scope.tableGroupAclBlackList = [] + AclService.getTableAclBlackList({ + project: $scope.projectModel.selectedProject, + tablename: $scope.selectTableName, + type:'user' + }, function (result) { + $scope.tableUserAclBlackList = result; + }) + AclService.getTableAclBlackList({ + project: $scope.projectModel.selectedProject, + tablename: $scope.selectTableName, + type:'group' + }, function (result) { + $scope.tableGroupAclBlackList = result; + }) + + $scope.userType = [{name:'User',value:'user'},{name:'Group',value:'group'}]; + $scope.cancel = function () { + $modalInstance.dismiss('cancel'); + }; + $scope.addAcl = function () { + loadingRequest.show() + AclService.saveAclSetOfTable({ + type:$scope.newTableAcl.type, + project: $scope.projectModel.selectedProject, + tablename:$scope.selectTableName, + username: $scope.newTableAcl.name + },{},function () { + loadingRequest.hide(); + SweetAlert.swal('Success!', 'Table acl add successfully', 'success'); + loadTableAclList() + $scope.cancel() + },function (e) { + if (e.data && e.data.exception) { + var message = e.data.exception; + var msg = !!(message) ? message : 'Failed to take action.'; + SweetAlert.swal('Oops...', msg, 'error'); + } else { + SweetAlert.swal('Oops...', "Failed to take action.", 'error'); + } + loadingRequest.hide(); + }) + } + } +}) http://git-wip-us.apache.org/repos/asf/kylin/blob/1388b73b/webapp/app/js/services/acl.js ---------------------------------------------------------------------- diff --git a/webapp/app/js/services/acl.js b/webapp/app/js/services/acl.js new file mode 100644 index 0000000..0331665 --- /dev/null +++ b/webapp/app/js/services/acl.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +KylinApp.factory('AclService', ['$resource', function ($resource, config) { + return $resource(Config.service.url + 'acl/:kind/:project/:type/:black/:tablename/:username', {}, { + getTableAclList: {method: 'GET', params: {kind:'table'}, isArray: true}, + getTableAclBlackList : {method: 'GET', params: {kind:'table', black: 'black'}, isArray: true}, + saveAclSetOfTable : {method: 'POST', params: {kind:'table'}, isArray: true}, + cancelAclSetOfTable: {method: 'DELETE', params: {kind:'table'}, isArray: false} + }); +}]); http://git-wip-us.apache.org/repos/asf/kylin/blob/1388b73b/webapp/app/partials/tables/table_access.html ---------------------------------------------------------------------- diff --git a/webapp/app/partials/tables/table_access.html b/webapp/app/partials/tables/table_access.html new file mode 100644 index 0000000..1d09f95 --- /dev/null +++ b/webapp/app/partials/tables/table_access.html @@ -0,0 +1,133 @@ +<!-- +* 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. +--> +<div ng-controller="AclCtrl"> + <br/> + <button type="button" class="btn btn-success" ng-click="addTableAcl()"><span class="fa fa-plus"></span> Grant</button> + <table class="table table-hover table-striped list"> + <thead> + <tr style="cursor: pointer"> + <th> + Id + </th> + <th> + User / Role name + </th> + <th> + Actions + </th> + </tr> + </thead> + <tr + ng-repeat="groupAcl in tableGroupAclList"> + <td> + {{ $index +1}} + </td> + <td> + <span class="fa fa-group"></span> {{ groupAcl}} + </td> + <td> + <div class="dropdown"> + <button class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> + Action + <span class="caret"></span> + </button> + <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> + <li><a ng-click="delTableAcl('group', groupAcl)">Delete</a></li> + </ul> + </div> + </td> + </tr> + <tr + ng-repeat="userAcl in tableUserAclList"> + <td> + {{ $index +tableGroupAclList.length +1}} + </td> + <td> + <span class="fa fa-user"></span> {{ userAcl}} + </td> + <td> + <div class="dropdown"> + <button class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> + Action + <span class="caret"></span> + </button> + <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> + <li><a ng-click="delTableAcl('user', userAcl)">Delete</a></li> + </ul> + </div> + </td> + </tr> + </table> + + <script type="text/ng-template" id="addTableAcl.html"> + <div class="modal-header"> + <h4 tooltip="submit">Add Grant</h4> + </div> + <ng-form name="forms.tableAclForm" novalidate="novalidate" class="modal-body" style="background-color: white"> + + <div class="row"> + <div class="col-md-2"></div> + <div class="col-md-8"> + <div class="row"> + <div class="form-group"> + <b>Type</b> + <br/> + <select ng-required="true" chosen ng-model="newTableAcl.type" + style="width: 100% !important;" + ng-options="user.value as user.name for user in userType" + class="chosen-select"> + <option value="user">User</option> + <option value="group">Group</option> + </select> + </div> + </div> + <div class="row"> + <div class="form-group" ng-show="newTableAcl.type == 'user'"> + <b>User / Role name</b> + <br/> + <select ng-required="true" chosen ng-model="newTableAcl.name" + ng-options="black as black for black in tableUserAclBlackList" + style="width: 100% !important;" + data-placeholder="select a user" + class="chosen-select"> + </select> + </div> + + <div class="form-group" ng-show="newTableAcl.type == 'group'"> + <b>User / Group name</b> + <br/> + <select ng-required="true" chosen ng-model="newTableAcl.name" + ng-options="black as black for black in tableGroupAclBlackList" + style="width: 100% !important;" + data-placeholder="select a group" + class="chosen-select"> + <option value=""></option> + </select> + </div> + + </div> + </div> + <div class="col-md-2"></div> + </div> + </ng-form> + <div class="modal-footer"> + <button class="btn btn-primary" ng-click="cancel()">Close</button> + <button class="btn btn-success" ng-click="addAcl()" ng-disabled="forms.tableAclForm.$invalid">Submit</button> + </div> + </script> +</div> http://git-wip-us.apache.org/repos/asf/kylin/blob/1388b73b/webapp/app/partials/tables/table_detail.html ---------------------------------------------------------------------- diff --git a/webapp/app/partials/tables/table_detail.html b/webapp/app/partials/tables/table_detail.html index 7ebe6d9..9e28194 100644 --- a/webapp/app/partials/tables/table_detail.html +++ b/webapp/app/partials/tables/table_detail.html @@ -32,6 +32,9 @@ <li> <a data-toggle="tab" ng-if="tableModel.selectedSrcTable.source_type==1" href="#streaming">Streaming Cluster</a> </li> + <li> + <a data-toggle="tab" href="#access">Access</a> + </li> </ul> <div class="tab-content"> <!--Schema--> @@ -166,7 +169,24 @@ <div ng-include="'partials/cubeDesigner/streamingConfig.html'" ng-init="state.mode='view'"></div> </div> + <!--access--> + <div id="access" class="tab-pane"> + + <div class="tabbable nav-tabs"> + <ul class="nav nav-tabs"> + <li class="active"> + <a data-toggle="tab" href="#accesstable">Table</a> + </li> + </ul> + <div class="tab-content"> + <div id="accesstable" class="tab-pane active"> + <div ng-include="'partials/tables/table_access.html'"></div> + </div> + </div> + </div> + + </div> </div> </div>