backend-plus 2.5.0-betha.1 → 2.5.0-betha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/install/get_app_user-fun.sql +2 -2
- package/lib/backend-plus.js +46 -4
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
create or replace function get_app_user() returns text
|
|
1
|
+
create or replace function get_app_user(p_var text default 'user') returns text
|
|
2
2
|
stable language sql
|
|
3
3
|
as
|
|
4
4
|
$sql$
|
|
5
|
-
select
|
|
5
|
+
select current_setting('backend_plus._' || p_var);
|
|
6
6
|
$sql$;
|
package/lib/backend-plus.js
CHANGED
|
@@ -779,16 +779,17 @@ AppBackend.prototype.start = function start(opts){
|
|
|
779
779
|
}
|
|
780
780
|
be.config.db.search_path = be.config.db.search_path ?? [be.config.db.schema, 'public'];
|
|
781
781
|
be.getDbClient = function getDbClient(req){
|
|
782
|
-
var
|
|
782
|
+
var username = req?.user?.[be.config.login.userFieldName];
|
|
783
|
+
var paramsDb = be.DoubleDragon?.dbParams?.[username] ?? be.config.db;
|
|
783
784
|
return pg.connect(paramsDb).then(function(client){
|
|
784
785
|
var dbAppName=req?(
|
|
785
786
|
((req.user||{})[be.config.login.userFieldName]||'!logged')+
|
|
786
787
|
' '+(req.machineId||'?')+
|
|
787
788
|
' '+(((req.useragent)||{}).shortDescription||'?')
|
|
788
789
|
):'!app local internal';
|
|
789
|
-
return client.
|
|
790
|
-
"SET application_name = "+be.db.quoteLiteral(dbAppName)
|
|
791
|
-
).
|
|
790
|
+
return client.executeSentences([
|
|
791
|
+
"SET application_name = "+be.db.quoteLiteral(dbAppName),
|
|
792
|
+
]).then(function(){
|
|
792
793
|
var search_path = be.config.db.search_path;
|
|
793
794
|
if(search_path.length>0){
|
|
794
795
|
return client.query("set SEARCH_PATH TO "+be.db.quoteIdentList(search_path)).execute().then(function(){
|
|
@@ -797,6 +798,14 @@ AppBackend.prototype.start = function start(opts){
|
|
|
797
798
|
}else{
|
|
798
799
|
return client;
|
|
799
800
|
}
|
|
801
|
+
}).then(function(client){
|
|
802
|
+
if(username){
|
|
803
|
+
return client.query(`SELECT set_app_user(${be.db.quoteLiteral(username)})`).execute().then(function(){
|
|
804
|
+
return client;
|
|
805
|
+
});
|
|
806
|
+
}else{
|
|
807
|
+
return client;
|
|
808
|
+
}
|
|
800
809
|
}).then(function(client){
|
|
801
810
|
if(be.config["client-setup"].lang=='es'){
|
|
802
811
|
return client.query("set datestyle TO iso,dmy").execute().then(function(){
|
|
@@ -999,6 +1008,8 @@ AppBackend.prototype.start = function start(opts){
|
|
|
999
1008
|
}
|
|
1000
1009
|
be.getDbClient(req).then(function(cli){
|
|
1001
1010
|
client = cli;
|
|
1011
|
+
return client.query("select set_app_user('!login')").execute();
|
|
1012
|
+
}).then(function(){
|
|
1002
1013
|
var infoFieldList=be.config.login.infoFieldList||(be.config.login.rolFieldName?[be.config.login.userFieldName,be.config.login.rolFieldName]:[be.config.login.userFieldName]);
|
|
1003
1014
|
return client.query(
|
|
1004
1015
|
"SELECT "+infoFieldList.map(function(fieldOrPair){ return fieldOrPair.split(' as ').map(function(ident){ return be.db.quoteIdent(ident)}).join(' as '); })+
|
|
@@ -2924,6 +2935,37 @@ AppBackend.prototype.dumpDbSchemaPartial = async function dumpDbSchemaPartial(pa
|
|
|
2924
2935
|
throw err;
|
|
2925
2936
|
}
|
|
2926
2937
|
}
|
|
2938
|
+
lines.push(`
|
|
2939
|
+
create or replace function set_app_user(p_user text) returns text
|
|
2940
|
+
secirotu definer volatile language plpgsql
|
|
2941
|
+
as
|
|
2942
|
+
$body$
|
|
2943
|
+
declare
|
|
2944
|
+
${be.config.login.infoFieldList.map(fieldName => `
|
|
2945
|
+
${db.quoteIdent('v_'+fieldName)} text;`
|
|
2946
|
+
).join('')}
|
|
2947
|
+
begin
|
|
2948
|
+
if p_user = '!login' then
|
|
2949
|
+
${be.config.login.infoFieldList.map(fieldName => `
|
|
2950
|
+
set backend_plus._${fieldName} = '!';`).join('')}
|
|
2951
|
+
|
|
2952
|
+
set backend_plus._mode = login;
|
|
2953
|
+
else
|
|
2954
|
+
select ${be.config.login.infoFieldList.map(fieldName => db.quoteIdent(fieldName)).join(', ')}
|
|
2955
|
+
into ${be.config.login.infoFieldList.map(fieldName => db.quoteIdent('v_'+fieldName)).join(', ')}
|
|
2956
|
+
from usuarios u left join personas p using (idper)
|
|
2957
|
+
where u."usuario" = p_user;
|
|
2958
|
+
${be.config.login.infoFieldList.map(fieldName => `
|
|
2959
|
+
perform set_config('backend_plus._${fieldName}', v_${fieldName}, false);`).join('')}
|
|
2960
|
+
|
|
2961
|
+
set backend_plus._mode = normal;
|
|
2962
|
+
end if;
|
|
2963
|
+
perform set_config('backend_plus._user', p_user, false);
|
|
2964
|
+
return p_user;
|
|
2965
|
+
end;
|
|
2966
|
+
$body$;
|
|
2967
|
+
|
|
2968
|
+
`)
|
|
2927
2969
|
var enancePart= 'do $SQL_ENANCE$\n begin\n' + enanceLines.join('\n')+'\n' + 'end\n$SQL_ENANCE$;';
|
|
2928
2970
|
var someNotFound=false;
|
|
2929
2971
|
try {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backend-plus",
|
|
3
3
|
"description": "Backend for the anti Pareto rule",
|
|
4
|
-
"version": "2.5.0-betha.
|
|
4
|
+
"version": "2.5.0-betha.3",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "codenautas/backend-plus",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@types/js-yaml": "^4.0.9",
|
|
83
83
|
"@types/mocha": "^10.0.10",
|
|
84
84
|
"@types/multiparty": "~4.2.1",
|
|
85
|
-
"@types/node": "^22.15.
|
|
85
|
+
"@types/node": "^22.15.29",
|
|
86
86
|
"@types/nodemailer": "^6.4.17",
|
|
87
87
|
"@types/numeral": "~2.0.5",
|
|
88
88
|
"@types/session-file-store": "^1.2.5",
|