Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By higgledy
#813667
I am creating a new user via the REST API. Is there a way to set the user's Default Main Menu Option when creating the user in REST? Thanks.
User avatar
By amosbatto
#813693
I have created a custom REST plugin for this:
(33 KiB) Downloaded 253 times
You can call it this way in PHP:
Code: Select all
$userId = '92729925059e5652bebac55017512865';
$defaultMenu = 'PM_CASES';
$defaultCasesMenu = 'CASES_SENT';
$url = "/api/1.0/workflow/extrarest/user/$userId/config";
    
$aVars = array(
  'default_lang'       => 'el',
  'default_menu'       => $defaultMenu,
  'default_cases_menu' => $defaultCasesMenu
);
$oRet = pmRestRequest('PUT', $url, $aVars, $oToken->access_token);
var_dump($oRet); 
Here is the code in the plugin to explain the POST parameters:
Code: Select all
    /** 
     * Update user configuration stored in a serialized array in CONFIGURATION.CFG_VALUE. 
     * 
     * @url PUT /user/:usr_uid/config
     * @access protected
     * 
     * @param string $usr_uid User's unique ID. {@from path}{@min 32}{@max 32}
     * @param string $default_lang Default interface language in 'xx' or 'xx-CC' format. 
     *    {@from body} {@pattern /^[a-z]{2,3}([\-_][A-Z]{2})?$/}
     * @param string $default_menu Default main menu: '' (default for role), PM_CASES=Home, PM_FACTORY=Designer, PM_SETUP=Admin 
     *    {@from body} {@choice PM_CASES,PM_FACTORY,PM_SETUP,PM_DASHBOARD,} 
     * @param string $default_cases_menu Default Cases submenu: ''=default Inbox, CASES_SENT=participated, CASES_SELFSERVICE=unassigned, CASES_SEARCH=advanced search, CASES_TO_REVISE=review, CASES_FOLDERS=Documents 
     *    {@from body} {@choice CASES_START_CASE,CASES_INBOX,CASES_DRAFT,CASES_SENT,CASES_SELFSERVICE,CASES_PAUSED,CASES_SEARCH,CASES_TO_REVISE,CASES_TO_REASSIGN,CASES_FOLDERS,} 
     * 
     * @return array An array holding the updated user configuration.
     * 
     * @author Amos Batto <amos@processmaker.com>
     * @copyright Public Domain
     */
    public function putUserConfig($usr_uid, $default_lang=null, $default_menu=null, $default_cases_menu=null)
    {  
        try {
            $rbac = \RBAC::getSingleton();
            $rbac->initRBAC();
            
            if ($rbac->verifyUserId($usr_uid) != 1) {
                throw new \Exception("User with ID '$usr_uid' does not exist.");
            }
            
            if ($this->userCanAccess('PM_USERS') == 0) {
                throw new \Exception("Logged-in user lacks the PM_USERS permission in role.");
            }
            
            $g = new \G();
            $g->loadClass('configuration');
            $oConf = new \Configurations();
            $oConf->loadConfig($x, 'USER_PREFERENCES', '', '', $usr_uid, '' );
            
            //set user configuration:
            if (isset($default_lang)) {
                $oConf->aConfig['DEFAULT_LANG'] = $default_lang;
            }
            if (isset($default_menu)) {
                $oConf->aConfig['DEFAULT_MENU'] = $default_menu;
            }
            if (isset($default_cases_menu)) {
                $oConf->aConfig['DEFAULT_CASES_MENU'] = $default_cases_menu;
            }
            
            //update configuration:
            $oConf->saveConfig('USER_PREFERENCES', '', '', $usr_uid);
            
            $oConf->loadConfig($y, 'USER_PREFERENCES', '', '', $usr_uid, '');
            return $oConf->aConfig;
        } 
        catch (\Exception $e) {
            throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
        }
    } 
    
    /**
     * Get user configuration stored in a serialized array in CONFIGURATION.CFG_VALUE. 
     * 
     * @url GET /user/:usr_uid/config
     * @access protected
     * 
     * @param string $usr_uid User's unique ID. {@from path}{@min 32}{@max 32}
     * 
     * @return array An array holding the user configuration.
     * 
     * @author Amos Batto <amos@processmaker.com>
     * @copyright Public Domain
     */
    public function getUserConfig($usr_uid) {  
        try {
            $rbac = \RBAC::getSingleton();
            $rbac->initRBAC();
            
            if ($rbac->verifyUserId($usr_uid) != 1) {
                throw new \Exception("User with ID '$usr_uid' does not exist.");
            }
            
            if ($this->userCanAccess('PM_USERS') == 0) {
                throw new \Exception("Logged-in user lacks the PM_USERS permission in role.");
            }
            
            $g = new \G();
            $g->loadClass('configuration');
            $oConf = new \Configurations();
            $oConf->loadConfig($x, 'USER_PREFERENCES', '', '', $usr_uid, '' );
            
            return $oConf->aConfig;
        } 
        catch (\Exception $e) {
            throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
        }
    } 
 
By higgledy
#813759
Will this new plugin maintain the same functionality as the previous version, plus the user account config functionality?
User avatar
By amosbatto
#813764
It still has the endpoints from the previous plugin, but I have added some extra ones. I added some code to verify that users have the correct permissions in their roles to be able to use the endpoints.
You can untar the two plugins and examine the differences in the extraRest/extraRest/src/Services/Api/ExtraRest/Extra.php file.

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]