Merge branch 'dev' of ssh://git.verdnatura.es:/var/lib/git/salix into dev
This commit is contained in:
commit
041be5ec93
|
@ -17,8 +17,10 @@
|
|||
"params": {
|
||||
"client": "card.client"
|
||||
},
|
||||
"description": "Datos básicos",
|
||||
"icon": "person"
|
||||
"menu": {
|
||||
"description": "Datos básicos",
|
||||
"icon": "person"
|
||||
}
|
||||
}, {
|
||||
"url": "/fiscal-data",
|
||||
"state": "clientCard.fiscalData",
|
||||
|
@ -26,8 +28,10 @@
|
|||
"params": {
|
||||
"client": "card.client"
|
||||
},
|
||||
"description": "Datos fiscales",
|
||||
"icon": "account_balance"
|
||||
"menu": {
|
||||
"description": "Datos fiscales",
|
||||
"icon": "account_balance"
|
||||
}
|
||||
}, {
|
||||
"url": "/billing-data",
|
||||
"state": "clientCard.billingData",
|
||||
|
@ -35,8 +39,10 @@
|
|||
"params": {
|
||||
"client": "card.client"
|
||||
},
|
||||
"description": "Datos facturación",
|
||||
"icon": "assignment"
|
||||
"menu": {
|
||||
"description": "Datos facturación",
|
||||
"icon": "assignment"
|
||||
}
|
||||
},{
|
||||
"url": "/addresses",
|
||||
"state": "clientCard.addresses",
|
||||
|
@ -49,8 +55,10 @@
|
|||
"params": {
|
||||
"client": "card.client"
|
||||
},
|
||||
"description": "Consignatarios",
|
||||
"icon": "local_shipping"
|
||||
"menu": {
|
||||
"description": "Consignatarios",
|
||||
"icon": "local_shipping"
|
||||
}
|
||||
}, {
|
||||
"url": "/create",
|
||||
"state": "clientCard.addresses.create",
|
||||
|
@ -66,8 +74,10 @@
|
|||
"params": {
|
||||
"client": "card.client"
|
||||
},
|
||||
"description": "Acceso web",
|
||||
"icon": "language"
|
||||
"menu": {
|
||||
"description": "Acceso web",
|
||||
"icon": "language"
|
||||
}
|
||||
},{
|
||||
"url": "/notes",
|
||||
"state": "clientCard.notes",
|
||||
|
@ -80,8 +90,11 @@
|
|||
"params": {
|
||||
"client": "card.client"
|
||||
},
|
||||
"description": "Notas",
|
||||
"icon": "insert_drive_file"
|
||||
"menu": {
|
||||
"description": "Notas",
|
||||
"icon": "insert_drive_file"
|
||||
}
|
||||
|
||||
}, {
|
||||
"url": "/create",
|
||||
"state": "clientCard.notes.create",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<mg-ajax path="/client/api/Clients/{{edit.params.id}}/card" options="mgEdit" actions="card.client=edit.model;"></mg-ajax>
|
||||
<vn-empty style="min-width: 18em; padding-left: 1em; padding-bottom: 1em;">
|
||||
<vn-descriptor client="card.client" active="card.client.active" class="display-block" ></vn-descriptor>
|
||||
<vn-left-menu items="card.items"></vn-left-menu>
|
||||
<vn-left-menu></vn-left-menu>
|
||||
</vn-empty>
|
||||
<vn-auto>
|
||||
<vn-vertical style="max-width: 70em; margin: 0 auto;" ui-view></vn-vertical>
|
||||
|
|
|
@ -6,22 +6,10 @@ export const NAME = 'vnClientCard';
|
|||
export default class vnClientCard {
|
||||
constructor() {
|
||||
this.client = null;
|
||||
this.items = [];
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
routes.client.routes.forEach(i => {
|
||||
if (i.description)
|
||||
this.items.push({
|
||||
description: i.description,
|
||||
icon: i.icon,
|
||||
href: i.state
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.component(NAME, {
|
||||
template: require('./index.html'),
|
||||
controllerAs: 'card',
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import {module} from '../module';
|
||||
|
||||
function vnAcl(aclService, $compile) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function(scope, element, attrs) {
|
||||
let acls = attrs.vnAcl.split(',');
|
||||
let action = attrs.vnAclAction || 'disabled';
|
||||
if (!aclService.aclPermission(acls)) {
|
||||
if (action === 'disabled') {
|
||||
let input = element[0].querySelector('input');
|
||||
input.setAttribute("ng-disabled", "true");
|
||||
$compile(input)(scope);
|
||||
} else {
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
vnAcl.$inject = ['aclService', '$compile'];
|
||||
|
||||
module.directive('vnAcl', vnAcl);
|
|
@ -2,3 +2,4 @@ import './id';
|
|||
import './focus';
|
||||
import './dialog';
|
||||
import './validation';
|
||||
import './acl';
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import ngModule from './module';
|
||||
|
||||
function aclService() {
|
||||
this.roles = window.Salix.acl.roles;
|
||||
this.routeHasPermission = function(route) {
|
||||
let hasPermission;
|
||||
if (!route.acl)
|
||||
hasPermission = true;
|
||||
else if (!this.roles || !Object.keys(this.roles).length)
|
||||
hasPermission = false;
|
||||
else
|
||||
hasPermission = this.aclPermission(route.acl);
|
||||
return hasPermission;
|
||||
};
|
||||
this.aclPermission = function(aclCollection) {
|
||||
let hasPermission = false;
|
||||
let total = aclCollection.length;
|
||||
for (let i = 0; i < total; i++) {
|
||||
if (this.roles[aclCollection[i]]) {
|
||||
hasPermission = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hasPermission;
|
||||
};
|
||||
}
|
||||
|
||||
ngModule.service('aclService', aclService);
|
|
@ -1,5 +1,6 @@
|
|||
import './module';
|
||||
import './spliting';
|
||||
import './aclService';
|
||||
import './configroutes';
|
||||
import './config';
|
||||
import './run';
|
||||
|
|
|
@ -75,3 +75,5 @@ function interceptorConfig($httpProvider) {
|
|||
$httpProvider.interceptors.push('vnAppInterceptor');
|
||||
}
|
||||
ngModule.config(interceptorConfig);
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
import ngModule from '../../module';
|
||||
import './style.css';
|
||||
|
||||
export default class vnLeftMenu {
|
||||
constructor(aclService, $state) {
|
||||
this.aclService = aclService;
|
||||
this.$state = $state;
|
||||
this.items = [];
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
let station = this.$state.current.data.station || 'default';
|
||||
if (routes[station]) {
|
||||
routes[station].routes.forEach(i => {
|
||||
if (i.menu && this.aclService.routeHasPermission(i))
|
||||
this.items.push({
|
||||
description: i.menu.description,
|
||||
icon: i.menu.icon,
|
||||
href: i.state
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
vnLeftMenu.$inject = ['aclService', '$state'];
|
||||
|
||||
ngModule.component('vnLeftMenu', {
|
||||
template: require('./left-menu.html'),
|
||||
bindings: {
|
||||
items: '<'
|
||||
}
|
||||
controller: vnLeftMenu
|
||||
});
|
||||
|
|
|
@ -11,9 +11,10 @@ function loader(moduleName) {
|
|||
return load;
|
||||
}
|
||||
|
||||
config.$inject = ['$stateProvider', '$urlRouterProvider'];
|
||||
function config($stateProvider, $urlRouterProvider) {
|
||||
config.$inject = ['$stateProvider', '$urlRouterProvider', 'aclServiceProvider'];
|
||||
function config($stateProvider, $urlRouterProvider, aclServiceProvider) {
|
||||
splitingRegister.registerGraph(deps);
|
||||
let aclService = aclServiceProvider.$get();
|
||||
|
||||
function getParams(route) {
|
||||
let params = '';
|
||||
|
@ -34,16 +35,20 @@ function config($stateProvider, $urlRouterProvider) {
|
|||
for (let file in routes) {
|
||||
let fileRoutes = routes[file].routes;
|
||||
let moduleName = routes[file].module;
|
||||
|
||||
fileRoutes.forEach(function(route) {
|
||||
$stateProvider.state(route.state, {
|
||||
url: route.url,
|
||||
abstract: route.abstract || false,
|
||||
template: `<${route.component} ${getParams(route)}></${route.component}>`,
|
||||
resolve: {
|
||||
loader: loader(moduleName)
|
||||
}
|
||||
});
|
||||
if (aclService.routeHasPermission(route)) {
|
||||
$stateProvider.state(route.state, {
|
||||
url: route.url,
|
||||
abstract: route.abstract || false,
|
||||
template: `<${route.component} ${getParams(route)}></${route.component}>`,
|
||||
resolve: {
|
||||
loader: loader(moduleName)
|
||||
},
|
||||
data: {
|
||||
station: file
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'angular-ui-router';
|
||||
import '@uirouter/angularjs';
|
||||
|
||||
export const angularUiRouter = {
|
||||
name: 'ui.router'
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
"url": "http://git.verdnatura.es:/salix"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uirouter/angularjs": "^1.0.3",
|
||||
"angular": "^1.6.4",
|
||||
"angular-cookies": "^1.6.4",
|
||||
"angular-paging": "^2.2.2",
|
||||
"angular-translate": "^2.13.1",
|
||||
"angular-translate-loader-partial": "^2.13.1",
|
||||
"angular-ui-router": "^1.0.0-beta.3",
|
||||
"material-design-lite": "^1.3.0",
|
||||
"mg-crud": "^1.1.2",
|
||||
"oclazyload": "^0.6.3",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Salix</title>
|
||||
<script src="/salix/acl"></script>
|
||||
</head>
|
||||
<body ng-app="salix">
|
||||
<vn-app></vn-app>
|
||||
|
|
|
@ -9,6 +9,17 @@ module.exports = function (app) {
|
|||
});
|
||||
});
|
||||
|
||||
app.get('/acl', function(req, res){
|
||||
let token = req.cookies.vnToken;
|
||||
validateToken(token, function(isValid) {
|
||||
if (isValid)
|
||||
sendUserRole(res);
|
||||
else
|
||||
sendACL(res, {});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.get('/login', function (req, res) {
|
||||
let token = req.query.token;
|
||||
let continueUrl = req.query.continue;
|
||||
|
@ -33,6 +44,9 @@ module.exports = function (app) {
|
|||
function validateToken(tokenId, cb) {
|
||||
app.models.AccessToken.findById(tokenId, function(err, token) {
|
||||
if (token) {
|
||||
if(token.userId){
|
||||
app.currentUser = {id: token.userId};
|
||||
}
|
||||
token.validate (function (err, isValid) {
|
||||
cb(isValid === true);
|
||||
});
|
||||
|
@ -42,6 +56,50 @@ module.exports = function (app) {
|
|||
});
|
||||
}
|
||||
|
||||
function sendUserRole(res){
|
||||
if(app.currentUser && app.currentUser.id){
|
||||
let query = {
|
||||
"where": {
|
||||
"principalId": `${app.currentUser.id}`,
|
||||
"principalType": "USER"
|
||||
},
|
||||
"include": [{
|
||||
"relation": "role",
|
||||
"scope": {
|
||||
"fields": ["name"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"relation": "user",
|
||||
"scope": {
|
||||
"fields": ["id", "username"]
|
||||
}
|
||||
}]
|
||||
};
|
||||
app.models.RoleMapping.belongsTo(app.models.User, {foreignKey: 'principalId', as: 'user'});
|
||||
app.models.RoleMapping.find(query, function(err, roles){
|
||||
if(roles){
|
||||
let acl = {
|
||||
userProfile: {},
|
||||
roles: {}
|
||||
};
|
||||
acl.userProfile = roles[0].user();
|
||||
Object.keys(roles).forEach(function(_, i){
|
||||
if(roles[i].roleId){
|
||||
let rol = roles[i].role();
|
||||
acl.roles[rol.name] = true;
|
||||
}
|
||||
});
|
||||
sendACL(res, acl);
|
||||
}
|
||||
else
|
||||
sendACL(res, {});
|
||||
});
|
||||
}
|
||||
else
|
||||
sendACL(res, {});
|
||||
}
|
||||
|
||||
function redirectToAuth (res, continueUrl) {
|
||||
let authUrl = app.get('url auth');
|
||||
let params = {
|
||||
|
@ -51,6 +109,12 @@ module.exports = function (app) {
|
|||
res.clearCookie ('vnToken');
|
||||
res.redirect(`${authUrl}/?${encodeUri(params)}`);
|
||||
}
|
||||
|
||||
function sendACL(res, acl){
|
||||
let aclStr = JSON.stringify(acl);
|
||||
res.header('Content-Type', 'application/javascript; charset=UTF-8');
|
||||
res.send(`(function(window){window.Salix = window.Salix || {}; window.Salix.acl = window.Salix.acl || {}; window.Salix.acl = ${aclStr}; })(window)`);
|
||||
}
|
||||
};
|
||||
|
||||
function encodeUri(object) {
|
||||
|
|
Loading…
Reference in New Issue