I added a function to get all the attached acls that were attached to a certain node id
Please review this patch. I think it's useful enough to include it since getting an ACL by name is not always sufficient

Comments

salvis’s picture

Status: Active » Needs work

I don't think this is a good idea. It returns the acl_ids of all modules to the caller, and the caller should never touch ACL records that aren't his own.

Do you need this for anything besides acl_node_clear_acls($nid, $module)? acl_node_clear_acls($nid, $module), BTW, does it the right way, by restricting the query to $modules.

nick_vh’s picture

StatusFileSize
new843 bytes

Ok, you are right about the restricting of the module.
I personally need this function because I have dynamic naming of my ACL's and I do not always know which ACL's are attached to my module (atleast not by name) and I want to know if an ACL is attached to this node and also to an other without knowing the name.

Anyway, here is the updated patch

nick_vh’s picture

StatusFileSize
new923 bytes

Changed the conditions of the query to restrict to the module.
The query got a little bit more complicated but I think it's fine

Also got it through coder and does not report any problem.

salvis’s picture

+++ acl.module	13 Apr 2010 00:42:43 -0000
@@ -92,6 +92,18 @@ function acl_get_id_by_name($module, $na
+  $result = db_query("SELECT acl.acl_id FROM {acl_node} as an, {acl} as acl WHERE acl.module = '%s' AND an.nid = %d AND acl.acl_id = an.acl_id", $module, $nid);

We typically don't use the optional "AS" keyword in SQL. If we did, it would have to be in upper case, but I prefer to not have it at all.

The code looks ok otherwise, but I don't have the time to write a test (module or simpletest) for this new function. Would this be the right occasion to start the series of simpletests for ACL (see #761696: WANTED: SimpleTests for ACL)?

nick_vh’s picture

StatusFileSize
new910 bytes

So here we are without the 'as' keyword.

miro_dietiker’s picture

At least the alias n is typically used for node table only. Use something like na or an.
Also i don't like the notation of your join. Please use a regular INNER or LEFT JOIN syntax with ON condition about the relationship. This makes it much more readable.

Also i think we should return an empty array in case of emptyness. mixing arrays and non-arrays leads to huge problems with array functions and needs pre-checks here and there.

nick_vh’s picture

StatusFileSize
new928 bytes

In attachment the adjusted patch.

I did not change the return type since an other function also uses the same syntax (acl_get_uids) so the maintainer should make a decision if an empty array is better then a NULL value.

Hopefully good enough for the final review ;-)

salvis’s picture

+++ acl.module	18 Jun 2010 12:55:28 -0000
@@ -99,6 +99,18 @@ function acl_get_id_by_name($module, $na
+  $result = db_query("SELECT an.acl_id AS gid FROM {acl_node} an INNER JOIN {acl} a ON an.acl_id = a.acl_id WHERE a.module = '%s' AND nid = %d", $module, $nid);

Hmm, I agree with Miro about the aliases, but renaming acl_id to gid does not improve clarity. Maybe you took this from acl_node_access_records(), where the key needs to be 'gid' for an external reason.

+++ acl.module	18 Jun 2010 12:55:28 -0000
@@ -99,6 +99,18 @@ function acl_get_id_by_name($module, $na
+  return (empty($return) ? ($array = new array()) : $return);

What? We already have an empty array. Why can't we just return $return?

The last paragraph in #4 still applies...

yellek’s picture

+1, I need this for a module I'm writing to copy ACLs between nodes (i.e. Referencing multiple nodes to the same ACL).

salvis’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)