What I am trying to achieve is:
1) I have a Profile2 field in the user registration form called: "Firm Type"
2) I need to assign the new user a Role based on the selection in this field.
I have tried the following:
Event: After saving a new account
Condition: Data Comparison: account:profile-additional-registration-info:field-profile-firm-type
Action: Add a user role
The above Rule works fine when I remove the condition. As soon as I add the condition the rule does not work.
Digging into this I found out that Rule gets executed after Account is saved and before Profile2 is saved.
I looked online to find these 2 links helpful:
https://www.drupal.org/node/1872384
https://www.drupal.org/node/2009878
1 suggestion was:
Event: After saving a new profile
Condition: Data Comparison: Profile2:field
Action: Heres where the problem is -- I cannot get to the account level because its on a profile event.
Could you please help me figure this out. Any help would be really appreaciated!
Thanks!
Here are the steps:
Rules Event: After adding a new profile After updating an existing profile
Rules Condition: Negate User Has Roles: Check all roles other than a Public Role Data Comparison: profile2:field
Rules Action: Set a Data Value: site:current-user:roles
Related
Currently building a WordPress intranet site, that authenticates users using Auth.0 SSO, against the company's Azure AD. The SSO functions properly, but I'm trying to get more granular with access control using Auth.0's "rules". The ideal result is a rule that specifies (updates) the user's WP Profile with a user role based on their job title from AD. The code below has been modified from one of Auth.0's rule templates, and runs clean. However, it doesn't work - I'm not sure what particular arguments/functions I need to actually update the role in WordPress. I'll be up-front and admit that I'm far from proficient in JS. Any thoughts?
function (user, context, callback) {
if (user.job_title === 'IT/Marketing Coordinator') {
user.vip = true;
}
callback(null, user, context);
}
In the example above, it successfully sets "user.vip" to "true" (which really doesn't prove much except that the rule executes without error.
this rule, as you said, is fine and will add this attribute.
The issue is that you will need to do something from the wordpress side to make it work (that the user has a vip flag doesn't mean anything to WordPress).
What you can do is hook to the auth0_user_login action that is fired each time a user logs in and based on the user profile set/change the user role.
This is how you hook to the action:
add_action( 'auth0_user_login', 'auth0UserLoginAction', 0,5 );
function auth0UserLoginAction($user_id, $user_profile, $is_new, $id_token, $access_token) {
...
}
I think you will find this WP doc useful to update the user role: https://codex.wordpress.org/Function_Reference/wp_update_user
I have a Meteor app where I need to:
Create / update app users including their name, username and password. So I was wondering if first is it possible to do so while login to the app as a Meteor user? In other words is it possible to create / update other app users while logging in as an app user? I've tried to search for an example / how to but couldn't find any so any help will be highly appreciated.
Add custom fields to Meteor.users document (ex. User type(accountant / sales...etc), Phone...etc)? After research couldn't find any example except on how to update Meteor.users profile in update only, but couldn't find how to do so when creating the new user, so any help will be highly appreciated.
Thanks
To add fields to user simply use onCreateUser function
Accounts.onCreateUser(function(user) {
user.type = "customer";
user.phone = "123456789";
//etc
return user;
});
And I didn't understand first question, but you can update user data by making query, such as:
Meteor.users.update({_id:this._id},{$addToSet~});
I am using symfony 2.5 and trying to check if a user has a specific role. The tables are set up correctly in the database and the data is correct inserted:
In the database exists a user test#example.com with a mapped group admin which has defined the roles a:1:{i:0;s:10:"ROLE_ADMIN";}
I don't know why the roles aren't read correct. The debug-toolbar tells me, that i am only authenticated as ROLE_USER.
Code:
$securityContext = $this->container->get('security.context');
$securityContext->isGranted('ROLE_ADMIN');
if ($securityContext->isGranted('ROLE_ADMIN')) {
echo 'crazy coding magic happens here';
}
I have found this question (Symfony 2 FOS UserBundle users doesn't get group's role) which seems to be related to my question, but i am not satisfied with the answer, because i don't want to check the group-access but the role-access. In my case group permissions could change in the future.
Thanks for your help!
Okay - it seems i have found the solution by myself.
The problem is that you have to sign off the logged in user and sign in again to recognize changes in the group-role-mapping.
The code above is correct and after the is user is logged in again the correct roles are assigned.
In my Synfony2 wep application, there is two different role that the same user can have. He can whether be an employee or a boss. So, I want to have a switch button the change role so the user have a different view on data. For example, has a Boss the user would see the progress of the work in a project and as a Employee he would see the work to be done from each member of the team in the same project. So basically, the boss would have privilege on some action and the employee on some others.
How should I do the switch between the roles? I was planning to have two different url for each roles /boss/todesand employee/todos. In some case, I would use the same twigs template (e.g. the listing of the todos). How do I do when I need to generate a URL such as /boss/todos/{id} by always specifying the same route_name path('todo_show', {'id': id}).
I think it is pretty similar to the _locale parameter. Is it possible to create a custom parameter similar to _locale in Symfony 2.3?
Thanks in advance !
IMO you think too complex. Create one route for both users, say /todo/{id} which will redirect user based on their role to the user specific route /boss/todo/{id} or /employee/todo/{id}.
setting a default parameter in your routing config file is not enought?
todo_show:
pattern: /{_user}/todos/{id}
defaults: { _controller: YourAppBundle:Default:getTodos, _user: boss }
requirements:
_user: boss|employee
methods: [GET]
and then:
path('todo_show', {'id': id, '_user': 'employee'}); // for boss there is no need to specify _user
I am trying to change the filters in the display of the current user in the Defects module.
I have set the "tdc.BUGFactory.Filter" object with my filter and i can access the data, but i cannot force it to be displayed to the user! any idea on how to do that?
If i use a SQL command to store it in the common settings table, would it be possible to call an action to load the "Favorites" view i created to the user?
Thanks,
Achraf
================================================================
I found the answer, however stackoverflow doesn't allow me to post it:
I fonud the answer through SQA Forums, to force a filter you use the following
Set defectFilter = tDConenction.BugFactory.Filter ' Example to set a filter criteria
defectFilter.Field ("BG_DETECION_DATE") = "[Today]"
SetDefectsFilter defectFilter.Text
Set defectFilter = Nothing
There is also a function called GetDefectsFilter() which gets the current filter