Posted by theurso on September 3, 2010 at 5:29pm
I've done extensive searching within the drupal.org site as well as internet at large, I am looking for a way to make all organic groups and all their posts private to any anonymous users on my site.
How can this be done?
Also is it possible to still have the directory view of all the groups visible to anonymous users?
Thanks for any help, anyone can give.
--edit--
Just found http://drupal.org/node/200631
I think this may be my solution, unless their is a better way..
Comments
There's an article here that
There's an article here that may be of use to you: http://www.sthlmconnection.se/tips-and-tweaks/organic-groups-your-defini.... I created a module (which I can't seem to find now) using the code described and it did work as advertised.
Alright, it looks like it is
Alright, it looks like it is deff what i'm looking for, so i guess i'll put together my first module..
--The Urso
You may also want to look at:
You may also want to look at: http://drupal.org/project/og_access_roles, which has similar functionality.
i looked at that, except it
i looked at that, except it seems to only create access in regards to posts, but not the group itself
also i put together that other module as such:
/**
* Implementation of hook_node_access_explain().
*/
function mymodule_node_access_explain($row) {
if ($row->realm == 'mymodule_authenticated') {
return t('All authenticated users may view this node.');
}
}
/**
* Implementation of hook_node_access_records.
*/
function mymodule_node_access_records($node) {
// The 'authenticated' grant that will be set on public OG content.
$grant = array (
'realm' => 'mymodule_authenticated',
'gid' => 0,
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 0,
);
// Non-private groups.
if (og_is_group_type($node->type) && !$node->og_private) {
return array($grant);
}
// Public group posts.
elseif (!empty($node->og_groups) && $node->og_public) {
return array($grant);
}
return NULL;
}
/**
* Implementation of hook_node_grants().
*/
function mymodule_node_grants($account, $op) {
$grants = array();
// Allow authenticated users to view public group nodes.
if ($op == 'view' && in_array('authenticated user', $account->roles)) {
$grants['mymodule_authenticated'][] = 0;
}
return $grants;
}
/**
* Implementation of hook_og_access_grants_alter().
*/
function mymodule_og_access_grants_alter(&$grants, $node) {
// og_access is about to insert grants for this node. Remove any public grants
// so that this node isn't visible to everyone. It will be replaced by our
// own mymodule_authenticated grant.
foreach ($grants as $key => $grant) {
if ($grant['realm'] == 'og_public') {
unset($grants[$key]);
}
}
}
it seems somehow i put the 4 parts of it together wrong as i'm getting errors...
--The Urso
It's been a long time since I
It's been a long time since I played with it, what errors and when?
the code is going across top
the code is going across top of all pages and inside some pages.
http://dl.dropbox.com/u/10311829/screen.png
as seen in pic above
i followed this pages instructions on creating module, http://www.hankpalan.com/blog/drupal/make-custom-drupal-module
--edit--
was missing <?php in code.. i think i'm fine now, just need to test it
--The Urso
Cool
Yeah, it had to be something like that. Good luck.
This all seems to work, also
This all seems to work, also got same effect working with content access module, but anomys users can't see og directory view, how can i solve this...
here is problem again:
need help with og access, for directory type site, looking for a solution to allow all user types except for anyms users to access og pages, but still allow anyms users access to og directory view
--The Urso