Login  Register

Re: Permission and usergroup changes failing silently

Posted by DavidJCobb on Jan 06, 2012; 10:58pm
URL: https://support.nabble.com/Permission-and-usergroup-changes-failing-silently-tp7157335p7160266.html

I did more tweaking and narrowed down the problem. I rename the node and modify the user's groups in "update_portfolio_name", which works properly... However, when "update_portfolio_perms" is called immediately afterward, it doesn't seem to notice the node's new name, and so it re-adds the old usergroup.

Okay, so "update_portfolio" requires a node, and calls "update_portfolio_name" and then "update_portfolio_perms". I think that when "update_portfolio_name" runs, it modifies that node, but the macros' reference to the node remains unchanged and does not update. So when "update_portfolio_perms" runs, it still sees all of the old values. For the permission edit, I was able to force one line of code to use an updated reference, by getting a "node_editor" and referring to "edited_node"; however, I can't get that to work in the specific way I need it to.

Somehow, I need to get "update_portfolio_perms" to see the changes to the node that were made by "update_portfolio_name"... I'll keep looking for something.

EDIT: Found a solution, and figured out the nature of the problem.

Basically, if: we have three macros A, B, and C, which all require "node"; and A calls B, and then C; and B makes changes to the node... Then C won't see the changes at all unless it grabs a new reference to the node, because the node reference C receives from A isn't updated. For example, <n.subject/> inside of C would yield the old value, but <n.get_node_from_id node_id="[n.id/]" do="[n.subject/]"> should yield the new value.

So basically, to avoid this problem, one can create a macro like:

<macro name="ensure_updated_reference" requires="node" dot_parameter="do" unindent="true">
  <n.get_node_from_id node_id="[n.id/]" do="[n.do/]"/>
</macro>

And then when you need to ensure that a reference is up-to-date for a macro, you can just wrap that macro's contents in
<n.ensure_updated_reference.> ... </n.ensure_updated_reference.>