Archive 1.x:Use of Organic Groups in OSF-Drupal

This document explains the usage of the Organic Group module into the OSF-Drupal modules for Drupal 7. The goal of this document is to explains where the OG module has been used in OSF-Drupal, and what for. This should instruct the PNX theme on the things to consider when they will remove the usage, and dependency, of OG for the version of OSF-Drupal that will work on Drupal 7.

Introduction
Organic Groups has been used in OSF-Drupal as a way to represent and manage datasets. This choice has been made years ago when our Drupal knowledge was lacking, so the decision to use it was not necessarily the good one (or overkill for the needs we had). It is the reason why we want to get rid of this dependency for the next version of OSF-Drupal that will work on Drupal 7.

In OSF-Drupal for Drupal 6, a Dataset content type was a group node. This node was used to manage interaction between users and the Datasets that were hosted on remote structWSF instances. In this context, OG was used to manage the users "subscriptions" to the dataset. A user could "join" a dataset, could be removed from a dataset, etc. OG, and more particularly the hook_og hook was used to manage this interaction between the datasets and the users. Each time a user was joining a dataset, or was leaving a dataset, its permissions were updated in structWSF by using the Auth: Registrar Access web service endpoint.

In the structDataset module, if the user didn't have the proper rights to manage a dataset, the structDataset module was giving the option to the user to "join" the dataset. When the user was joining the dataset, depending on its role (administer, data curator, etc), then different default permissions were defined for that user. These additional permissions that he was gaining depending on its role could enable him to perform different kind of actions on the dataset (changing the title, etc).

The subscription/un-subscriptions of the users to a dataset is used to manage the remote permissions of that user, on the linked, remote, structWSF instances. That way, when a user is joining a dataset, it is also setting its permissions on the remote structWSF instance. This means that that user will be able to query the different endpoints to get data within that dataset (if he has the permissions) from anywhere, and not only via the Drupal portal.

At this point, the goal should be to replicate the OG's few used behaviors to migrate OSF-Drupal on Drupal 7 as soon as possible. In the future, this mechanism may change based on the HPP needs, and the new feature that we will get from the Security Service.

Implemented Hooks
These are the few hooks that have been implemented to deal with dataset creation, deletion, updating and management.

hook_nodeapi (conStruct_nodeapi, conStruct.module line 1117)
The implementation of this hook deals with the creation/deletation/update of the datasets.

Used OG API calls
OG is related to this hook because we use its API call  to see if the currently manipulated node is a OG group type. It is used that way:

What needs to be done here is simply to rely on the fact that the type of the node is. We can drop that check all-together like this:

This API call is used on the following lines:,  ,   and.

SQL Queries
OG is also related to this hook because we do send SQL queries to different OG tables to perform a few actions.

The first SQL query that is used is to get the description of the group, and to use it as the description of the dataset. This description is used as the descrioption of the dataset into structWSF.

Get Description (conStruct.module line 1477)

The second SQL query that is used is to get the users ID related to a group. These IDs should be the IDs of the users that joined that dataset (group).

Get UID (conStruct.module line 1686) hook_og (conStruct_og, conStruct.module line 800)

The implementation of this hook deals with the user subscription/un-subscription to the datasets.

This hook handle 3 different operations performed by OG:



These three OG operations are triggered when the user join or leave a group, or when its role change. This  should be replaced by a new one that would reside in OSF-Drupal. Then, the only think that would be needed to update in the code is to implement that hook, along with these three operations, using exactly the same code that we have with.

What will need to be developed are the UIs discussed at the bottom of this document, and to create the new hook that will get triggered when these different actions will be performed.

SQL Queries
There are other SQL queries that are used elsewhere in the suite of OSF-Drupal modules.

Get Description (structDataset.module line 1058)

The SQL query above is used by the structDataset module to get the description of a linked dataset from the OG's description. This information should now be retrieved from the new Dataset's fields.

Form State
OG is also used to generate a form state that is used to create a new node on Drupal (of content type Dataset).

Add Group Description on Dataset Creation (structImport.module line 438)

This is what is demonstrated with the code snippet above. The  field's value is populated with some description that has been entered by the user when he created the new dataset. This field should be replaced by a new  field created for the updated Dataset content type (or use the body of the node as the description field; whatever is best).

Dataset Creation
Right now, when a dataset is being created, we use a custom content type with custom fields. However, in Drupal 6 it doesn't seem to be possible to change the default fields that are really not needed when creating a new dataset (such as comments settings, url path settings, etc). I think it is now possible to modify these in Drupal 7. The new dataset creation form should be cleaned to only have the necessary fields for creating a new dataset.

Dataset Deletion UI
Right now, when we delete a dataset, we use the Node's delete action (i.e. . However, due to the fact that the Dataset CCK is related to OG (so, it is a group node), then we have unnecessary options when deleting a dataset. A new user interface should be presented to the user asking them if they really want to delete the dataset (and not having a "Delete group" button which is confusing).

Dataset Join UI
We currently use OG's subscription mechanism to join a dataset (i.e. ). This mechanism should be replaced by a new user interface that ask a user if he really want to join a dataset. This new feature that would replace OG's subscriptions should be built into the structDataset module.

Conclusion
As we can see, the OG's features used in OSF-Drupal are simple and frankly minimal. The goal of the task HTS-105 is to remove these few OG dependencies, and to create the few hooks, and UIs that will replace OG. These things should be implemented in the next version of OSF-Drupal (for Drupal 7). The goal is really to remove the OG dependency without impacting the current features and behaviors of OSF-Drupal. Then, once this goal is reached, we will be able to fully migrate OSF-Drupal for Drupal 6 to Drupal 7. And once this story is done, we will then be able to take that as a starting basis to change some of the behaviors, add new features, etc.