(function(App) {
App.events.on("App:sync:complete", function(){
App.api.call('GET', App.api.buildURL('userRole'), null, {
success: function(userRoleArray) {
console.log(_.indexOf(userRoleArray,"1ffe6d3f-897e-8a2d-1b00-558969e06287") );
if (_.indexOf(userRoleArray,"1ffe6d3f-897e-8a2d-1b00-558969e06287") > -1) {
console.log(userRoleArray);
var acls = App.user.getAcls();
acls.Accounts.create = 'no';
App.user.set("acls", acls);
}else{
console.log("not inarray");
}
},
});
});
})(SUGAR.App);When i test it in console, i get a "undefined", even if i connect with a user which has the role set to "standard user" ... nothing is fired in the console...
App Ecosystem @ SugarCRM
<?phpif(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class getCurrentUserRoleApi extends SugarApi{
public function registerApiRest(){
return array(
'userRole' => array(
'reqType' => 'GET',
'path' => array('userRole'),
'pathVars' => array(),
'method' => 'getCurrentUserRole',
'shortHelp' => 'Custom Api to get the current user role',
'longHelp' => '',
),
);
}
public function getCurrentUserRole($api,$args){
global $current_user;global $db;
$query = "SELECT acl_roles.id ".
"FROM acl_roles ".
"INNER JOIN acl_roles_users ON acl_roles_users.user_id = '".$current_user->id."' ".
"AND acl_roles_users.role_id = acl_roles.id AND acl_roles_users.deleted = '0' ".
"WHERE acl_roles.deleted = '0' ";
$result = $db->query($query);
$user_roles=array();
while($row = $db->fetchByAssoc($result) ){
$user_roles[] = $row['id'];
}
return $user_roles;
}
}
(function(app) {
app.events.on("app:sync:complete", function(){
/*call to the custom api to disallow create for Standard Users.*/
app.api.call('GET', app.api.buildURL('userRole'), null, {
success: function(userRoleArray) {
if (_.indexOf(userRoleArray,"<YourRoleID>") > -1) {
console.log(userRoleArray);
var acls = app.user.getAcls();
acls.Accounts.create = 'no';
app.user.set("acls", acls);
}else{
console.log("not inarray");
}
},
});
});
})(SUGAR.App);
<?php
foreach ($js_groupings as $key => $groupings) {
foreach ($groupings as $file => $target) {
if ($target == 'include/javascript/sugar_grp7.min.js') {
$js_groupings[$key]['custom/javascript/acl_hide_create.js'] = 'include/javascript/sugar_grp7.min.js';
}
break;
}
}
Hello Everyone,
This development is work for the Mobile App ?
Because I have check this code in to my development instance but in mobile-app that is not working.
Hi Bavesh,
Current implementation of Sugar Mobile App won't support custom js like record.js, create-action.js etc.
Hello shijin Krishna,
Does any way there I can restrict record's creation using mobile app.
You would have to attempt to restrict it from Mobile REST APIs. You could update User APIs to return ACLs that restrict 'create' action for modules you do not want the user to be able to create on Mobile. Sidecar clients (like Mobile) obey a 'create' ACL that is not yet supported in backend. I haven't experimented with this yet, so I couldn't say for sure how well it would work. But what I have in mind would not require a lot of code changes.
See this blog post for example of how you can override REST API endpoints for Mobile clients. In this case, you would want to override the API that returns client side ACLs to include additional ACL rules.
Using server side changes to customize SugarCRM Mobile « Sugar Developer Blog – SugarCRM
App Ecosystem @ SugarCRM