[SOLVED] Question on using auto action with User

5 years 6 months ago - 5 years 6 months ago #307622 by rgarderet
Hello,
I have resolved most of the issues (some quite basic) in my original post using trial and error but have lingering questions.

1. When I trigger the User External trigger, and append "&user=70" to the long URL, I thought it would just run the action on user 70, but it seems to run on all of my users anyway. The only way I have found to actually limit it to take Action on user 70 is to set the condition as: [user_id] equals [get_users]. It seems to work, and the action successfully appends the user id of #me (the viewer) into a field in user 70 (so I can then see a list that filters using that - the whole goal here)

Is there a better way to do this? My action is
Trigger: Users
Type: Field
User: Automatic
Access: Everybody

The condition is: [user_id] equal to [get_users] <-- this is the part I thought it automatically did, when you pass &users=X through the URL


2. The thing works if I am logged in as a super administrator. I get access issues when I am someone else. I've tried to set access to 1) Everyone 2) the target user's one, 3) the viewers one 5) both, but nothing works. Could this be something to do with permissions? I have some new user groups set up after I installed CB. Any guidance would be very welcome.

3. Lastly, after the hyperlink containing the cbautoaction link has been clicked, is there a way to redirect the user back to another page. I am left on a blank page.

Thanks very much in advance

Please Log in to join the conversation.

5 years 6 months ago #307637 by krileon
Replied by krileon on topic Question on using auto action with User

1. When I trigger the User External trigger, and append "&user=70" to the long URL, I thought it would just run the action on user 70, but it seems to run on all of my users anyway. The only way I have found to actually limit it to take Action on user 70 is to set the condition as: [user_id] equals [get_users]. It seems to work, and the action successfully appends the user id of #me (the viewer) into a field in user 70 (so I can then see a list that filters using that - the whole goal here)

The users parameter doesn't apply to Internal Users or Internal General usages. It is only applied to the direct execution of an auto action. If you set Triggers to None you should see the URL to directly execute the auto action under the same Global tab. That you can add &users=COMMA_LIST_OF_USER_IDS to (e.g. &users=70 or &users=70,71,72).

2. The thing works if I am logged in as a super administrator. I get access issues when I am someone else. I've tried to set access to 1) Everyone 2) the target user's one, 3) the viewers one 5) both, but nothing works. Could this be something to do with permissions? I have some new user groups set up after I installed CB. Any guidance would be very welcome.

The only access checks applied are the Access parameter and the access to the CB Auto Action plugin it self which should be set to Public in CB > Plugin Management already. The Access parameter of the CB Auto Action is applied to the User of the action which isn't always the person who is executing the action. Your issue is likely just due to using &user instead of &users.

3. Lastly, after the hyperlink containing the cbautoaction link has been clicked, is there a way to redirect the user back to another page. I am left on a blank page.

Yes, you can actually chain auto actions. Create a Redirect auto action acting on the autoactions_onAction trigger. Next under Conditions use the below to limit its execution to be after your previous auto action.

[var2_id] Equal To AUTO_ACTION_ID_HERE

The alternative is to use the Output parameters by setting Display to Silent, adding the necessary PHP to redirect to the Layout parameter, then set Method to PHP.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: nant, rgarderet

Please Log in to join the conversation.

5 years 6 months ago #307658 by rgarderet
Replied by rgarderet on topic Question on using auto action with User
Thank you very much Kyle. That illuminates a lot - I had mistakenly though that the link without the trigger was for testing purposes only. I'll try your suggestions and hopefully resolve the access issues at the same time.
Much appreciated,
Remy.
The following user(s) said Thank You: krileon

Please Log in to join the conversation.

5 years 6 months ago #307699 by rgarderet
Replied by rgarderet on topic Question on using auto action with User
Hi Kyle,
Could I ask for some additional guidance? I have two auto action needs:
1. insert the active user ID into a field on the user I am viewing. I'm using auto action FIELD and its working

2. Remove the active ID from that same field of the multiple CSV IDs. (They start with a comma: ",52,43,58,120,...)

Reading your forum responses, I think I learned that I cannot do that with a field action, but should instead do it with a QUERY action.

To test it, I have successfully gotten the field to just increase by 1 (with URL manual trigger for the target users)
UPDATE `#__comprofiler` SET `cb_requested_by_currently` = (cb_requested_by_currently +1)

But I can't get the replacement thing to work. To be clear, if I am logged in as user 43, I'd like to remove a ",43," (ID with commas on each side) from the field in the target user (passed through the URL with &users)

Here is what I have come up with, but not knowing SQL or if its OK to mix substitutions in it, am struggling to know where the problem(s) are.

UPDATE `#__comprofiler` SET `cb_requested_by_currently` = (SELECT REPLACE(cb_requested_by_currently, `,[cb:userdata field="Id" user="#me" /],` , `,` ));

By the way, even when I replace the `,[cb:userdata field="Id" user="#me" /],` with a simple `,43,` it doesnt work.

Thanks for any guidance,
Remy.

Please Log in to join the conversation.

5 years 6 months ago #307706 by krileon
Replied by krileon on topic Question on using auto action with User

2. Remove the active ID from that same field of the multiple CSV IDs. (They start with a comma: ",52,43,58,120,...)

This is complicated to do with SQL alone. Check out the below for some examples of how you can remove a value from a CSV stored string.

stackoverflow.com/questions/14642658/the-best-way-to-remove-value-from-set-field
stackoverflow.com/questions/5454610/mysql-remove-the-specific-word-in-comma-seperated-string
stackoverflow.com/questions/7830197/remove-values-in-comma-separated-list-from-database
stackoverflow.com/questions/38619309/how-to-remove-comma-separated-string-of-records-in-mysql

By the way, even when I replace the `,[cb:userdata field="Id" user="#me" /],` with a simple `,43,` it doesnt work.

It's likely using you, the viewing user, as the User of the auto action. You'd need the displayed users user id in the action URL for it to use them as the User for the auto action. If the URL is being made accessible on their profile view Custom HTML for example you should be able to just add &users=[user_id] to it.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

5 years 6 months ago #307715 by rgarderet
Replied by rgarderet on topic Question on using auto action with User
Hi Kyle,
I'm still having permission issues and narrowed it down to having to set the user as "Manager" as well as the access level that I have from my CB subs plan.

ie the auto action fails unless the person has Manager permission, even though all the settings you mentioned in the plugin are open, and the action is set to Everyone? Do you know what might be specific about Manager (I never use it)?

Also, an update on the query, for anyone else trying to do a similar thing.

The solution seems to be that you need to use double quotes inside the replace function (as well as not use SELECT in addition to UPDATE):
This now works for me, when called using the URL with the &users=XX from the website (a field with the fullURL+ &users=[userID] appended.
Field with a button that has a No trigger Action URL + &users=[userID] appended

Action of type Query, with no conditions:
UPDATE `#__comprofiler` SET `thefieldtoupdate` = REPLACE(thefieldtoupdate, ",[cb:userdata field="Id" user="#me" /],", ",") WHERE `id` = [user_id];

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.243 seconds

Facebook Twitter LinkedIn