I have a rule to send an html mail when new content is created, but is not respecting the user permission to access content.
Is an Open Atrium site that works with OG. I have a space with 7 teams and only team members can view team contents (7 sections asociated to 7 teams). All users have the same role (filter by role is not a solution for me).
The content type in question have two entity reference fields: group audience and section (one per team).
In the rule I have an action to "Get group members" but I do not find the way to get only team members. If the solution is not with the teams may be something like filter or validate the value item-list:mail with the permission of the user to access to the content? It is possible to do something like that?
I tried with flags and notifications in the node/add form but only works when I manually add users or teams there, I need an automatic solution, not that the user manually complete that field.
Any help is very apreciated, thanks!
| Attachment | Size |
|---|---|
| rules-notification.png | 65.13 KB |
Comments
In OA, a Team is a node that
In OA, a Team is a node that is referenced in a Section by 'field_oa_team_ref' (by default: unlimited values).
And the users associated to the Team are referenced by 'field_oa_team_users' (by default: unlimited values). in the Team content type.
The 'created node' is referencing the Section with 'oa_section_ref' (by default: only 1 value).
So we have: 'created node' -> 'oa_section_ref' -> 'field_oa_team_ref' -> 'field_oa_team_users' -> 'user'
'field_oa_team_ref' and 'field_oa_team_users' will have to be treated as lists in rules.
So one way to accomplish your goal is with a rule to get the teams and a rule component to get the users in the each team.
Here are the exports of such rules to give you an idea (they only send messages, not emails):
1o a Rule that reacts on creation of a oa_discussion_post
{ "rules_test_team" : {"LABEL" : "test team",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "test" ],
"REQUIRES" : [ "rules" ],
"ON" : { "node_insert--oa_discussion_post" : { "bundle" : "oa_discussion_post" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node:oa-section-ref" ], "field" : "field_oa_team_ref" } }
],
"DO" : [
{ "variable_add" : {
"USING" : {
"type" : "list\u003Cnode\u003E",
"value" : [ "node:oa-section-ref:field-oa-team-ref" ]
},
"PROVIDE" : { "variable_added" : { "teams" : "teams" } }
}
},
{ "drupal_message" : { "message" : [ "teams:0:nid" ] } },
{ "LOOP" : {
"USING" : { "list" : [ "teams" ] },
"ITEM" : { "team_item" : "team item" },
"DO" : [ { "component_rules_test_loop" : { "team" : [ "team-item" ] } } ]
}
}
]
}
}
2o a rules component where you can send the emails
{ "rules_test_loop" : {"LABEL" : "test loop",
"PLUGIN" : "rule",
"OWNER" : "rules",
"TAGS" : [ "test" ],
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "team" : { "label" : "team", "type" : "node" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "team" ], "field" : "field_oa_team_users" } }
],
"DO" : [
{ "variable_add" : {
"USING" : {
"type" : "list\u003Cuser\u003E",
"value" : [ "team:field-oa-team-users" ]
},
"PROVIDE" : { "variable_added" : { "users" : "users" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "users" ] },
"ITEM" : { "user_item" : "user item" },
"DO" : [ { "drupal_message" : { "message" : [ "user-item:name" ] } } ]
}
}
]
}
}
Note that the creation of the two variables are optional.
Here is a print screen of the
Here is a print screen of the two rules. It might be an easier read.
1o http://pasteboard.co/BSM1vdrnL.png
2o http://pasteboard.co/BSPqanqL0.png
Sorry for the external and temporary image hosting, but it seems that i can't upload attachments in here...
Excellent, thanks!
Thank you very much! your explication helped me a lot.
I have only one problem, the value in "Add a variable" in rule (not the component) cant set in "node:oa-section-ref:field-oa-team-ref" it says: "The data type of the configured argument does not match the parameter's value requirement." No value sound to me like the correct one, what value should be set?
First: i didn't tried it, but
First: i didn't tried it, but i think that the variables are not really necessary, i put them in, just because of habit. A variable gives more ease-of-handling in a more complex process.
You can just directly use the field, referenced in the variable, in the loop without using the variable.
On another hand, if you are getting error in referencing the field 'field-oa-team-ref' in the variable (not component, but in truth, it is irrelevant for our problem, i think), it can suggest two different ideas:
Did you specified the condition?
That is the real reason why i used a Rules component. To gain access to the field 'field_oa_team_users' by using a Condition another time.
This schema should be sufficient to solve your kind of problem. What i would first do is to confirm my relationship structure. ie i would go and see how my content types are related and if they are different from the ones, i, paean, mentioned to you earlier: 'created node' -> 'oa_section_ref' -> 'field_oa_team_ref' -> 'field_oa_team_users' -> 'user'
Here the entity reference fields are of utmost importance.
Is your OA site different from what paean is assuming? How are defined your teams in relation to the section?
Are they using the default fields?
Are they using the default unlimited value? More than one value in a field do influence if you are using a list or not i rules.
Here is probably the solution to your problem: Did you choose the correct type of variable? You have to choose 'List of node items'.
Go to '/admin/structure/types' and check the relations between the entity/content types. In particular the sections and the teams. ie if you are not using a too strange type of team. Of course, just adding or changing the fields in the default team shouldn't be relevant to this problem. You just have to control the ''field_oa_team_users' in the team bundle and just because of possible problems in the component.
This should be sufficient for the rules modules by default, but you could check the versions of the modules and distributions that i used for this example to yours:
(i do have others modules in the test site that i used, but i think that the behavior demonstrated in the example is normal in term of the rules modules)
Do give more feedback on this problem, as you did in another issue. It is an interesting and practical topic to me. All the solutions are stimulating.
Thank you again for your
Thank you again for your dedication and help Paean!
I have the condition set for "Entity has field": Parameter: Entity: [node:oa-section-ref], Field: field_oa_team_ref.
The "show message" action works fine, I think the problem is to collect the users e-mails to send the email...
I found an error, I dont know if is relationed, is with Sorl, when I add new post the error appear in logs:
SearchApiException while deleting items from server Solr Server: "0" Status: Request failed: Connection refused in SearchApiSolrConnection->checkResponse() (line 544 of profiles/openatrium/modules/contrib/search_api_solr/includes/solr_connection.inc).
SearchApiException while removing index Solr User Index from server Solr Server: "0" Status: Request failed: Connection refused in SearchApiSolrConnection->checkResponse() (line 544 of profiles/openatrium/modules/contrib/search_api_solr/includes/solr_connection.inc).
SearchApiException: Could not index items since important pending server tasks could not be performed. in search_api_index_specific_items() (line 1614 of profiles/openatrium/modules/contrib/search_api/search_api.module).
SearchApiException while removing index Solr Node Index from server Solr Server: "0" Status: Request failed: Connection refused in SearchApiSolrConnection->checkResponse() (line 544 of profiles/openatrium/modules/contrib/search_api_solr/includes/solr_connection.inc).
You think this is relationed with my notification rule problem?
More details: The content type I am working is custom (team meeting), It have the section ref field and the space ref of course. I create a section type "My Team" who have teams content (Team meeting). The "Team" content type is the default, have the space ref and the "add users" field.
The search api shouln't be
The search api shouln't be involved with this rules and 'field_oa_team_ref' unless the 'entity selection' mode that is at 'admin/structure/types/manage/oa-section/fields/field_oa_team_ref' has been changed.
The default in my test site is 'Open Atrium Teams (includes inherited Teams)'.
Have you tried the rules in a simpler test site without solr?
You might have to re-index your site at admin/config/search/settings.
The error mentioned earlier: "The data type of the configured argument does not match the parameter's value requirement." indicates that the variable type is not the correct one for the field referenced.
If 'field_oa_team_ref' is multi-value (default in OA) then the variable should be a list. In the other case you should choose just the node type and you have no need for a loop in the teams.
Check it at admin/structure/types/manage/oa-section/fields/field_oa_team_ref.