backend-plus 2.5.0-betha.1 → 2.5.0-betha.2
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 +41 -4
- package/package.json +1 -1
|
@@ -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,20 @@ 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
|
+
...(username ? [
|
|
793
|
+
`SELECT set_app_user(${be.db.quoteLiteral(username)})`
|
|
794
|
+
] : [])
|
|
795
|
+
]).then(function(){
|
|
792
796
|
var search_path = be.config.db.search_path;
|
|
793
797
|
if(search_path.length>0){
|
|
794
798
|
return client.query("set SEARCH_PATH TO "+be.db.quoteIdentList(search_path)).execute().then(function(){
|
|
@@ -999,6 +1003,8 @@ AppBackend.prototype.start = function start(opts){
|
|
|
999
1003
|
}
|
|
1000
1004
|
be.getDbClient(req).then(function(cli){
|
|
1001
1005
|
client = cli;
|
|
1006
|
+
return client.query("select set_app_user('!login')").execute();
|
|
1007
|
+
}).then(function(){
|
|
1002
1008
|
var infoFieldList=be.config.login.infoFieldList||(be.config.login.rolFieldName?[be.config.login.userFieldName,be.config.login.rolFieldName]:[be.config.login.userFieldName]);
|
|
1003
1009
|
return client.query(
|
|
1004
1010
|
"SELECT "+infoFieldList.map(function(fieldOrPair){ return fieldOrPair.split(' as ').map(function(ident){ return be.db.quoteIdent(ident)}).join(' as '); })+
|
|
@@ -2924,6 +2930,37 @@ AppBackend.prototype.dumpDbSchemaPartial = async function dumpDbSchemaPartial(pa
|
|
|
2924
2930
|
throw err;
|
|
2925
2931
|
}
|
|
2926
2932
|
}
|
|
2933
|
+
lines.push(`
|
|
2934
|
+
create or replace function set_app_user(p_user text) returns text
|
|
2935
|
+
volatile language plpgsql
|
|
2936
|
+
as
|
|
2937
|
+
$body$
|
|
2938
|
+
declare
|
|
2939
|
+
${be.config.login.infoFieldList.map(fieldName => `
|
|
2940
|
+
${db.quoteIdent('v_'+fieldName)} text;`
|
|
2941
|
+
).join('')}
|
|
2942
|
+
begin
|
|
2943
|
+
if p_user = '!login' then
|
|
2944
|
+
${be.config.login.infoFieldList.map(fieldName => `
|
|
2945
|
+
set backend_plus._${fieldName} = '!';`).join('')}
|
|
2946
|
+
|
|
2947
|
+
set backend_plus._mode = login;
|
|
2948
|
+
else
|
|
2949
|
+
select ${be.config.login.infoFieldList.map(fieldName => db.quoteIdent(fieldName)).join(', ')}
|
|
2950
|
+
into ${be.config.login.infoFieldList.map(fieldName => db.quoteIdent('v_'+fieldName)).join(', ')}
|
|
2951
|
+
from usuarios u left join personas p using (idper)
|
|
2952
|
+
where u."usuario" = p_user;
|
|
2953
|
+
${be.config.login.infoFieldList.map(fieldName => `
|
|
2954
|
+
perform set_config('backend_plus._${fieldName}', v_${fieldName}, false);`).join('')}
|
|
2955
|
+
|
|
2956
|
+
set backend_plus._mode = normal;
|
|
2957
|
+
end if;
|
|
2958
|
+
perform set_config('backend_plus._user', p_user, false);
|
|
2959
|
+
return p_user;
|
|
2960
|
+
end;
|
|
2961
|
+
$body$;
|
|
2962
|
+
|
|
2963
|
+
`)
|
|
2927
2964
|
var enancePart= 'do $SQL_ENANCE$\n begin\n' + enanceLines.join('\n')+'\n' + 'end\n$SQL_ENANCE$;';
|
|
2928
2965
|
var someNotFound=false;
|
|
2929
2966
|
try {
|
package/package.json
CHANGED