Lizmap-web-client: LWC edition tool - send current login userid to postgresql table field

Created on 19 Jun 2017  路  31Comments  路  Source: 3liz/lizmap-web-client

how is it possible LWC send current login userid to postgresql table field in editing environment?

without correspondence between LWC users and postgresql users https://github.com/3liz/lizmap-web-client/issues/457

thanks

doc-needed question

All 31 comments

is it possible to improvise this feature? how?
thanks

At present, the only solution would be to use some Javascript which will

  • detects the user opened a form
  • get the login from the Lizmap interface
  • put it in some field if the field is empty.

Example of code

var formPrefix = 'jforms_view_edition';

// Name of the QGIS vector layer fields which must containt the user info
var userFields = {
    login: 'lizmap_user_login',
    firstname: 'lizmap_user_firstname',
    lastname: 'lizmap_user_lastname',
    organization: 'lizmap_user_organization'
};


lizMap.events.on({

    'lizmapeditionformdisplayed': function(e){

        // If user is logged in
        if( $('#info-user-login').length ){
            // Loop through the needed fields
            for( var f in userFields ){
                // If the user has some data for this property
                if( $('#info-user-' + f).text() ){
                    // If the field exists in the form
                    var fi = $('#' + formPrefix + '_' + userFields[f]);
                    if( fi.length ){
                        // Set val from lizmap user data
                        fi.val( $('#info-user-' + f).text() )
                        // Set disabled
                        fi.hide();
                    }
                }
            }
        }

    }

});

This is possible with some coding, but be aware it is a workaround and not bullet proof. A more robust and secure way would be to do this server side, which means we should add an option in Lizmap web client. For example, let the map editor give the name of the field in which to store the lizmap login for each editing layer. If the option is set, Lizmap will transform the field as Hidden, and set the content client and server side.

hi @mdouchin

thanks for your work

i put this script in media/js/myproject, using only one empty field to receive 'lizmap_user_login' but nothing happens... is something missing like layer name or or something else...?

Have you activated the JS ?
https://docs.3liz.com/fr/publish/advanced_lizmap_config.html#adding-your-own-javascript

yes, lizmapUserLogin.js

i have 2 editable layers in my project...

a test url ?

yes,

please, check your mailbox for access credentials

You have not adapted the script ! You need to change the dictionary userFields

For example, if you field for login is observacoes, you need this instead of the one put in my example

// Name of the QGIS vector layer fields which must containt the user info
var userFields = {
    login: 'observacoes'
};

sorry, i misinterpreted the script (observacoes: 'lizmap_user_login')...

now the form takes the value of the login but does not pass it to the database...
thanks

Can you look at lizmap/var/log/error.log and see if there is a SQL error when you save the form ?

hi @mdouchin

no, there are no errors...

i've tried with other projects, with other tables, without alias name for login field...
have you already tried with postgresql database?

Macau, i have exactly the same problem... it doesn't write in postgres database

hi

my postgresql log on insert feature:

2017-07-25 17:42:11 WEST [18838-7] user@databaseName LOG: statement: INSERT INTO "schema"."table" ("the_geom", "field1", "field2", "field3" ) VALUES (ST_GeomFromText('POINT(19629.678001044926 -74745.29503882483)', 3763), '2017-07-25', 55, 55 );

the field containing the login value login: 'observacoes' (observacoes) is not transported from lizmap form to the postgresql database.

hi @mdouchin

with the purpose to help debugging the problem, i've tried with a not null field

the form take the current user login value
obs

when submitting, the form controller doesn't recognize the value in the field
obs1

@josemvm Is your field published in the WFS column of the vector layer field ?

yes @mdouchin
i can save data in this field

hi @mdouchin

here is the problem: fi.attr('disabled', 'disabled');
with this code, which protects the field, the form controller interprets the field as empty

i commented this part of the code and instead i put the field as hidden in qgis project. so it works fine for me!

thanks

Thanks @josemvm for reporting a solution. I have updated the JS in my previous message and replace the addition of the disabled attribute by a more simple hide() methode

@josemvm This could be great in documentation :) as en example of the "add your own JS"

yes i think so, too. i will do it! :-)

done

@laurentj

this js script doesn麓t send the user name (login) to the postgresql, it works for local users only:

var formPrefix = 'jforms_view_edition';

// Name of the QGIS vector layer fields which must containt the user info
var userFields = {
    login: 'login',
    firstname: 'lizmap_user_firstname',
    lastname: 'lizmap_user_lastname',
    organization: 'lizmap_user_organization'
};


lizMap.events.on({

    'lizmapeditionformdisplayed': function(e){

        // If user is logged in
        if( $('#info-user-login').length ){
            // Loop through the needed fields
            for( var f in userFields ){
                // If the user has some data for this property
                if( $('#info-user-' + f).text() ){
                    // If the field exists in the form
                    var fi = $('#' + formPrefix + '_' + userFields[f]);
                    if( fi.length ){
                        // Set val from lizmap user data
                        fi.val( $('#info-user-' + f).text() )
                        // Set disabled
                     // fi.attr('disabled', 'disabled');
                        fi.hide();
                    }
                }
            }
        }

    }

});

how can we adapt it for ldapdao and multiauth modules?

thanks in advance

sorry, no problems, it works again!

@laurentj

this js script doesn麓t send the user name (login) to the postgresql, it works for local users only:

var formPrefix = 'jforms_view_edition';

// Name of the QGIS vector layer fields which must containt the user info
var userFields = {
    login: 'login',
    firstname: 'lizmap_user_firstname',
    lastname: 'lizmap_user_lastname',
    organization: 'lizmap_user_organization'
};


lizMap.events.on({

    'lizmapeditionformdisplayed': function(e){

        // If user is logged in
        if( $('#info-user-login').length ){
            // Loop through the needed fields
            for( var f in userFields ){
                // If the user has some data for this property
                if( $('#info-user-' + f).text() ){
                    // If the field exists in the form
                    var fi = $('#' + formPrefix + '_' + userFields[f]);
                    if( fi.length ){
                        // Set val from lizmap user data
                        fi.val( $('#info-user-' + f).text() )
                        // Set disabled
                     // fi.attr('disabled', 'disabled');
                      fi.hide();
                    }
                }
            }
        }

    }

});

how can we adapt it for ldapdao and multiauth modules?

thanks in advance

@josemvm It is possible to obtain also the group of the user logged in? Which is the name of the variable?

lizmap_group ????

hi @rmarzocchi84

i don't think so. an user can belong to more than one group...

hi @rmarzocchi84

i don't think so. an user can belong to more than one group...

maybe an array?

I would like to view a custom button created with my javascript code (https://github.com/3liz/lizmap-web-client/issues/712) only for user with edit permission

perhaps view~edition.access.XXX ?

sorry @josemvm and there is a way to obtain the authenticated user using a php code? I try with $_SESSION variables but I do not obtain nothing

sorry @rmarzocchi84
i don麓t know. the script was developed by @mdouchin

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pcav picture pcav  路  12Comments

ea-refit picture ea-refit  路  6Comments

josemvm picture josemvm  路  13Comments

news24lor picture news24lor  路  7Comments

t0xycus picture t0xycus  路  7Comments