Show particular data in dropdown - laravel

How to exclude database row from the select menu ? For example: The admin can create user and append roles to them. The available roles are dev, admin, normal user. But the admin user have to see only the admin and normal user roles. I know I can add them in the BREAD menu but I want to restrict the vision on dev role and when another roles are added to show them automaticaly and not to add them on by one in the BREAD menu.

The simplest solution is to filter the set of roles pulled from the database. Since I am not familiar with your database schema, here is a rough solution that you should be able to tweak to your needs
$rolesQuery = Role::newQuery();
if (Auth::user()->is_admin) {
$rolesQuery->where('role', '!=', 'dev');
}
$roles = $rolesQuery->get();
You can cache this result for admins for future use.

Related

Laravel scope query only for users - exclude result for admin

I am very new into programming and trying to make some work on Laravel / Voyager.
I have a Customers table and on this table there is also Customer_Representative field where I can select / assign customer representatives from dropdown list.
What I am trying to achieve is I want each users with their assigned roles (Customer Representative) to list customers only assigned for them.
I am using this below code, but I am not able to see list of customers that other users created. I can only see the customers I / Admin created but If I login with their details I can see their assigned customers.
So as an admin I want to be able to see all customers, so I can also edit them with my login credentials.
public function scopeCurrentUser($query)
{
return $query->where('Customer_Representative', Auth::user()->id);
}
I saw many suggested to use if but I couldn't figure out how to do it.
Appreciate your supports !
If I understand correctly, you want to display:
admin users - all users
non-admin users - only assigned users
You can either change the query in controller, but if you want to do it in scope I suggest something like this:
public function scopeCurrentUser($query)
{
return $query->when(auth()->user()->is_not_admin, function ($q) {
$q->where('Customer_Representative', auth()->user()->id)
});
}
You change the auth()->user()->is_not_admin to your condition for non-admin validation. The scope utilizes the ->when() function to append the condition to query only if the condition (in this case if authenticated user is not an admin) is true.
So if authenticated user is not an admin, his query will be filtered by Customer_Representative.

How to display record in custom created related list of all users having same manager in servicenow

I want to display the record in custom created related list of all users having saming manager in servicenow. For e.g. Abel, Jack has manager Adel, so when I open Adel record I should be able to see the Abel user and Jack user.
This is the script I used and don't know how it will execute in related list:
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name','abel');
gr.query();
gr.next();
gs.print(gr.getDisplayValue('manager'));
I tried this is in Scripts Background option in Application Navigator
You shouldn't need to code for this. If you want to add a related list of user's the current user manages. It will list as "Users" but you can change that label in the related list configuration.
If you meant to do this by code, you'd need to a scripted relationship the data. Here's some information on that. https://docs.servicenow.com/bundle/newyork-platform-user-interface/page/administer/form-administration/task/t_CreateDefinedRelatedLists.html

How to hide default list view dashlet based on user roles in sugar crm?

How to hide default list view dashlet based on user roles in sugar crm ? OR
How can i restrist user from adding list view dashlet based on user role ?
Disclaimer: I have SuiteCRM 7.10.7, might not apply to newer, and this change is not upgrade safe.
You could modify getDashlets function in DashletDialog
include/MySugar/DashletsDialog/DashletsDialog.php
It has the loop which loads in all dashlets to choose. You could put some limitations in there (get $current_user groups, check if they're ok and if particular dashlet should(n't) be allowed for them).

Make a form View read-only for specific user groups from front-end in Odoo 8

Is it possible to change the attributes of form view for specific user groups in form view tag, like in form tag, readonly="{('user_group','=','some_group')}">
I need to make a form view read-only for s specific user group but only from front-end. Records are updated from code by that user belonging to that specific user group from back-end. and if i disable updating the records of that model by that user group in my security file, that user is not able to modify the records even from back-end.
Best way to do this is by defining a new group that have only read access on that model and add to that user you will save a lot of typing and a lot of your time.
Because what you really asking is to remove edit write for a specific user.

permission of associated subgrid in crm

I have a (CRM) grid that has associated view (a) I need to add another associated view (b) to the same grid and to give different view permission (some users will see 'a' and some will see 'b') can I control these permissions on my associated grids
Based on your requirement, it looks like you don’t need two views & switch hit.
User A should have a security role A which will filter the data what he can see & cant see.
In security role A modify the Read privilege to BU level - half amber (now it may be full green - Org level)
The same security role A to User B (if they are from different BU) will work as it is. Basically role A has to be there in all BUs individually.

Resources