Write generic function for controller on UI and fix 404 page. Signed-off-by: Velmurugan Periasamy <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/4a34f48a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/4a34f48a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/4a34f48a Branch: refs/heads/master Commit: 4a34f48af48f7ed13cacdf6bcf501b1f9331af39 Parents: e039b7c Author: Gautam Borad <[email protected]> Authored: Fri Mar 20 00:15:50 2015 +0530 Committer: Velmurugan Periasamy <[email protected]> Committed: Thu Mar 19 15:29:50 2015 -0400 ---------------------------------------------------------------------- security-admin/src/main/webapp/scripts/Main.js | 8 ++++-- .../webapp/scripts/controllers/Controller.js | 5 ++++ .../src/main/webapp/scripts/routers/Router.js | 5 +++- .../src/main/webapp/scripts/utils/XAGlobals.js | 2 ++ .../src/main/webapp/scripts/utils/XAUtils.js | 23 ++++++++++++++--- .../webapp/scripts/views/common/ErrorView.js | 16 +++++++++--- .../views/policies/RangerPolicyCreate.js | 4 +-- .../scripts/views/service/ServiceCreate.js | 4 +-- security-admin/src/main/webapp/styles/xa.css | 4 +++ .../webapp/templates/common/ErrorView_tmpl.html | 27 ++++---------------- .../main/webapp/templates/helpers/XAHelpers.js | 25 ++++++------------ 11 files changed, 69 insertions(+), 54 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/scripts/Main.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/Main.js b/security-admin/src/main/webapp/scripts/Main.js index 1300a60..cefaa31 100644 --- a/security-admin/src/main/webapp/scripts/Main.js +++ b/security-admin/src/main/webapp/scripts/Main.js @@ -24,13 +24,17 @@ 'routers/Router', 'controllers/Controller', 'modules/XAOverrides', + 'utils/XAUtils', 'hbs!tmpl/common/loading_tmpl' ], -function ( Backbone, App, RegionManager, AppRouter, AppController, XAOverrides,loadingHTML ) { +function ( Backbone, App, RegionManager, AppRouter, AppController, XAOverrides, XAUtils, loadingHTML ) { 'use strict'; + var controller = new AppController(); + //deny some routes access for normal users + controller = XAUtils.filterAllowedActions(controller); App.appRouter = new AppRouter({ - controller: new AppController() + controller: controller }); App.appRouter.on('beforeroute', function(event) { $(App.rContent.$el).html(loadingHTML); http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/scripts/controllers/Controller.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/controllers/Controller.js b/security-admin/src/main/webapp/scripts/controllers/Controller.js index 71910a9..9915fb5 100644 --- a/security-admin/src/main/webapp/scripts/controllers/Controller.js +++ b/security-admin/src/main/webapp/scripts/controllers/Controller.js @@ -346,6 +346,11 @@ define(function(require) { })); }); }, + /**************** ERROR PAGE ******************************/ + pageNotFoundAction : function() { + var XAUtils = require('utils/XAUtils'); + XAUtils.defaultErrorHandler(undefined, { 'status' : 404 }); + }, }); }); http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/scripts/routers/Router.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/routers/Router.js b/security-admin/src/main/webapp/scripts/routers/Router.js index cda8ea3..095e56e 100644 --- a/security-admin/src/main/webapp/scripts/routers/Router.js +++ b/security-admin/src/main/webapp/scripts/routers/Router.js @@ -53,7 +53,10 @@ function(Backbone){ "!/service/:serviceId/policies" : "policyManageAction", "!/service/:serviceId/policies/create" : "RangerPolicyCreateAction", - "!/service/:serviceId/policies/:id/edit": "RangerPolicyEditAction" + "!/service/:serviceId/policies/:id/edit": "RangerPolicyEditAction", + + /*************** ERROR PAGE ****************************************/ + "*actions" : "pageNotFoundAction" } }); http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/scripts/utils/XAGlobals.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/utils/XAGlobals.js b/security-admin/src/main/webapp/scripts/utils/XAGlobals.js index 2e0c2e4..a3dbe9b 100644 --- a/security-admin/src/main/webapp/scripts/utils/XAGlobals.js +++ b/security-admin/src/main/webapp/scripts/utils/XAGlobals.js @@ -62,6 +62,8 @@ define(function(require){ XAGlobals.hardcoded.HDFSAssetId = 1; XAGlobals.hardcoded.HBaseAssetId = 2; XAGlobals.hardcoded.HiveAssetId = 3; + XAGlobals.DenyControllerActions = ['userManagerAction','userCreateAction','userEditAction','groupCreateAction', + 'groupEditAction','auditReportAction','loginSessionDetail','serviceCreateAction','serviceEditAction']; return XAGlobals; }); http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/scripts/utils/XAUtils.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/utils/XAUtils.js b/security-admin/src/main/webapp/scripts/utils/XAUtils.js index d540110..efcbd83 100644 --- a/security-admin/src/main/webapp/scripts/utils/XAUtils.js +++ b/security-admin/src/main/webapp/scripts/utils/XAUtils.js @@ -402,12 +402,13 @@ define(function(require) { var App = require('App'); var vError = require('views/common/ErrorView'); if (error.status == 404 ) { - // trigger event or route to login here. App.rContent.show(new vError({ - pageNotFound :true + status : error.status })); }else if (error.status == 401 ) { - window.location.replace('login.jsp'); + App.rContent.show(new vError({ + status : error.status + })); } }; XAUtils.select2Focus = function(event) { @@ -778,6 +779,20 @@ define(function(require) { XAUtils.getRangerServiceDef = function(name) { return "service/plugins/definitions/name/"+name; }; - + XAUtils.filterAllowedActions = function(controller) { + var SessionMgr = require('mgrs/SessionMgr'); + var XAGlobals = require('utils/XAGlobals'); + var that = this; + if(!SessionMgr.isSystemAdmin()){ + _.each(XAGlobals.DenyControllerActions, function(routeMethodName) { + if(!_.isUndefined(controller[routeMethodName])){ + controller[routeMethodName] = function(){ + that.defaultErrorHandler(undefined, {'status':401}); + }; + } + }); + } + return controller; + }; return XAUtils; }); http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/scripts/views/common/ErrorView.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/views/common/ErrorView.js b/security-admin/src/main/webapp/scripts/views/common/ErrorView.js index 2d1adeb..a9d5739 100644 --- a/security-admin/src/main/webapp/scripts/views/common/ErrorView.js +++ b/security-admin/src/main/webapp/scripts/views/common/ErrorView.js @@ -33,9 +33,17 @@ define(function(require){ template: ErrorView_tmpl, templateHelpers :function(){ + var msg = '', moreInfo = ''; + if(this.status == 401){ + msg = 'Access Denied (401)' + moreInfo = "Sorry, you don't have enough privileges to view this page."; + }else{ + msg = 'Page not found (404).' + moreInfo = "Sorry, this page isn't here or has moved."; + } return { - restrictedAccess :this.restrictedAccess || false, - pageNotFound :this.pageNotFound || false + 'msg' : msg, + 'moreInfo' : moreInfo }; }, /** ui selector cache */ @@ -59,7 +67,7 @@ define(function(require){ initialize: function(options) { console.log("initialized a ErrorView ItemView"); - _.extend(this, _.pick(options, 'restrictedAccess','pageNotFound')); + _.extend(this, _.pick(options, 'status')); this.bindEvents(); }, @@ -76,7 +84,7 @@ define(function(require){ $('#r_breadcrumbs').hide(); }, goBackClick : function(){ - + history.back(); }, /** all post render plugin initialization */ http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js index 0df992f..7370ee8 100644 --- a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js +++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js @@ -50,9 +50,9 @@ define(function(require){ breadCrumbs :function(){ if(this.model.isNew()) - return [XALinks.get('RepositoryManager'),XALinks.get('ManagePolicies',{model : this.rangerService}),XALinks.get('PolicyCreate')]; + return [XALinks.get('ServiceManager'),XALinks.get('ManagePolicies',{model : this.rangerService}),XALinks.get('PolicyCreate')]; else - return [XALinks.get('RepositoryManager'),XALinks.get('ManagePolicies',{model : this.rangerService}),XALinks.get('PolicyEdit')]; + return [XALinks.get('ServiceManager'),XALinks.get('ManagePolicies',{model : this.rangerService}),XALinks.get('PolicyEdit')]; } , /** Layout sub regions */ http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js index 4347479..01141b6 100644 --- a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js +++ b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js @@ -49,9 +49,9 @@ define(function(require){ breadCrumbs :function(){ if(this.model.isNew()) - return [XALinks.get('RepositoryManager'), XALinks.get('ServiceCreate', {model:this.model})]; + return [XALinks.get('ServiceManager'), XALinks.get('ServiceCreate', {model:this.model})]; else - return [XALinks.get('RepositoryManager'), XALinks.get('ServiceEdit',{model:this.model})]; + return [XALinks.get('ServiceManager'), XALinks.get('ServiceEdit',{model:this.model})]; }, /** Layout sub regions */ http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/styles/xa.css ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/styles/xa.css b/security-admin/src/main/webapp/styles/xa.css index 5f8e580..d15ce94 100644 --- a/security-admin/src/main/webapp/styles/xa.css +++ b/security-admin/src/main/webapp/styles/xa.css @@ -1778,4 +1778,8 @@ margin-top: -29px; } td.select-row-cell { text-align: center; +} +.ranger-notifications { + right: 33px!important; + top: 41px!important; } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/templates/common/ErrorView_tmpl.html ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/templates/common/ErrorView_tmpl.html b/security-admin/src/main/webapp/templates/common/ErrorView_tmpl.html index f180b07..e2f03b2 100644 --- a/security-admin/src/main/webapp/templates/common/ErrorView_tmpl.html +++ b/security-admin/src/main/webapp/templates/common/ErrorView_tmpl.html @@ -14,32 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. --}} -{{#if pageNotFound}} -<div data-id="pageNotFoundPage" class="error-page"> -<div class="error-box" style="margin-top: 0px;"> - <div class="icon-box"><img src="images/error-404-icon.png"></div> - - <h1>Page not found (404).</h1> - <p>Sorry, this page isn't here or has moved.</p> - - <a href="#!/policymanager" class="btn btn-primary btn-small" data-id="goBack"><i class="icon-long-arrow-left"></i> Go back</a> - <!-- <a href="#!/policymanager" class="btn btn-small" data-id="home">Home</a> --> -</div> -</div> -{{/if}} - -{{#if restrictedAccess}} -<div data-id="restrictedAccessPage" class="error-page"> +<div data-id="pageNotFoundPage" class="error-page"> <div class="error-box" style="margin-top: 0px;"> <div class="icon-box"><img src="images/error-404-icon.png"></div> + <h1>{{msg}}</h1> + <p>{{moreInfo}}</p> - <h1>Restricted Access (403)</h1> - <p>Please try again later. Thank you.</p> - - <!-- <a href="#!/policymanager" class="btn btn-small" data-id="goBack"><i class="icon-long-arrow-left"></i> Go back</a> - <a href="#!/policymanager" class="btn btn-small" data-id="home">Home</a> --> + <a href="javascript:;" class="btn btn-primary btn-small" data-id="goBack"><i class="icon-long-arrow-left"></i> Go back</a> + <a href="#!/policymanager" class="btn btn-small" data-id="home">Home</a> </div> </div> -{{/if}} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4a34f48a/security-admin/src/main/webapp/templates/helpers/XAHelpers.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/templates/helpers/XAHelpers.js b/security-admin/src/main/webapp/templates/helpers/XAHelpers.js index 33f7642..afb31d9 100644 --- a/security-admin/src/main/webapp/templates/helpers/XAHelpers.js +++ b/security-admin/src/main/webapp/templates/helpers/XAHelpers.js @@ -483,30 +483,21 @@ }); Handlebars.registerHelper('getServices', function(services, serviceDef) { var XAEnums = require('utils/XAEnums'); - var tr = ''; + var tr = '', serviceOperationDiv = ''; var serviceType = serviceDef.get('name'); - /*_.each(XAEnums.AssetType, function(asset){ - if(asset.label.toUpperCase() == serviceType.toUpperCase()){ - serviceType = asset.label; - return; - } - });*/ - if(!_.isUndefined(services[serviceType])){ _.each(services[serviceType],function(serv){ serviceName = serv.get('name'); - tr += '<tr>\ - <td>\ - <div>\ - <a data-id="'+serv.id+'" href="#!/service/'+serv.id+'/policies">'+serv.attributes.name+'</a>\ - <div class="pull-right">\ + if(SessionMgr.isSystemAdmin()){ + serviceOperationDiv = '<div class="pull-right">\ <a data-id="'+serv.id+'" class="btn btn-mini" href="#!/service/'+serviceDef.id+'/edit/'+serv.id+'" title="Edit"><i class="icon-edit"></i></a>\ <a data-id="'+serv.id+'" class="deleteRepo btn btn-mini btn-danger" href="javascript:void(0);" title="Delete">\ <i class="icon-trash"></i></a>\ - </div>\ - </div>\ - </td>\ - </tr>'; + </div>' + } + tr += '<tr><td><div>\ + <a data-id="'+serv.id+'" href="#!/service/'+serv.id+'/policies">'+serv.attributes.name+'</a>'+serviceOperationDiv+'\ + </div></td></tr>'; }); } return tr;
