1 create or replace function xt.usr_did_change() returns trigger as $$
2 /* Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.
3 See www.xm.ple.com/CPAL for the full text of the software license. */
5 if (typeof XT === 'undefined') {
6 plv8.execute("select xt.js_init();");
9 var sql = "select setUserPreference('" + NEW.usr_username + "', '{name}', $1)";
10 if (TG_OP === 'INSERT') {
11 plv8.execute('select xt.createuser($1, false)', [NEW.usr_username.toLowerCase()]);
14 /* Avoid recursive behavior by only updating from one side */
15 if (!XT.UserPreferencesUpdating) {
16 XT.UserPreferencesUpdating = true;
17 plv8.execute(sql.replace("{name}", 'propername'), [NEW.usr_propername]);
18 plv8.execute(sql.replace("{name}", 'email'), [NEW.usr_email]);
19 plv8.execute(sql.replace("{name}", 'initials'), [NEW.usr_initials]);
20 plv8.execute(sql.replace("{name}", 'locale_id'), [NEW.usr_locale_id + ""]);
21 plv8.execute(sql.replace("{name}", 'active'), [NEW.usr_active ? 't' : 'f'] );
22 plv8.execute(sql.replace("{name}", 'UseEnhancedAuthentication'), [NEW.usr_enhancedauth ? 't' : 'f'] );
23 plv8.execute(sql.replace("{name}", 'DisableExportContents'), [NEW.usr_disable_export ? 't' : 'f'] );
24 plv8.execute(sql.replace("{name}", 'agent'), [NEW.usr_agent ? 't' : 'f'] );
25 XT.UserPreferencesUpdating = false;