Update:Remora Vanilla Integration

From MozillaWiki
Revision as of 16:38, 1 November 2006 by Navvywavvy (talk | contribs) (Creating Page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Remora Vanilla Integration

This document is intended as a brief guide for the Remora team on how to integrate the add-on discussion pages (programmed with Lussumo Vanilla) with the rest of the application.

Integration Points

Currently you can review the discussions for an add-on with the following url:

http://site.url/discussions/?AddOnID=1234

I'm sure we'll want to change it to use mod_rewrite at some point, but that will work for the time being.

Useful Queries

To review the latest active discussions for an add-on, you can use the following query:

    select d.DiscussionID, 
         d.FirstCommentID, 
         d.AuthUserID, 
         d.Closed, 
         d.Sticky, 
         d.Sink, 
         d.Name, 
         d.DateCreated, 
         d.LastUserID, 
         d.DateLastActive, 
         d.CountComments, 
         d.addon_id as AddOnID, 
         u.nickname as AuthUsername, 
         lu.nickname as LastUsername, 
         b.DiscussionID is not null as Bookmarked, 
         utw.LastViewed as LastViewed, 
         coalesce(utw.CountComments, 0) as LastViewCountComments 
    from LUM_Discussion d 
    left join users u 
         on d.AuthUserID = u.id 
    left join users lu 
         on d.LastUserID = lu.id 
    left join LUM_UserBookmark b 
         on d.DiscussionID = b.DiscussionID 
         and b.UserID = $CurrentUserID
    left join LUM_UserDiscussionWatch utw 
         on d.DiscussionID = utw.DiscussionID 
         and utw.UserID = $CurrentUserID 
    where d.Active = '1' 
         and d.addon_id = $AddOnID 
    order by d.DateLastActive desc 
    limit 0, 5

Accessing Vanilla Permissions

Originally in Vanilla, permissions were done with the standard method: each column in the role table was another enum('1','0') permission. When extensions were added to Vanilla, it became apparent that extension authors needed to be able to add permissions quickly and easily for their own purposes. Adding a new column is a cumbersome process to automate. That was when the idea of putting all permissions into a single column came into effect. It allows extension authors to easily add their own permissions on a user-by-user basis with only two lines of code.

Vanilla permissions are stored in a single field in the LUM_Role table as a serialized array. Whenever a Vanilla page is loaded, the user's identity is retrieved and a set of Vanilla "session" information is pulled from the database. This information includes the User's ID, Role, Preferences, and Permissions. You can retrieve a user's Vanilla permissions with the following query:

    select r.Permissions 
    from users u 
    left join LUM_Role r 
         on u.vanilla_role_id = r.RoleID 
    where u.id = $UserID

Once you've retrieved the field, you can unserialize it with Vanilla's UnserializeAssociativeArray function:

    function UnserializeAssociativeArray($InSerialArray) {
         $aReturn = array();
         if ($InSerialArray !=  && !is_array($InSerialArray)) {
              $aReturn = @unserialize($InSerialArray);
              if (!is_array($aReturn)) $aReturn = array();
         }
         return $aReturn;
    }

Vanilla permissions have "default" values. These values are typically false, but sometimes they need to be true. The permissions are stored in Vanilla's $Configuration array, which can be found in /path/to/webroot/discussions/appg/settings.php

The configuration array contains *all* configuration settings for Vanilla. The default permission values are the array entries that begin with "PERMISSION_". The following is a list of permissions in Vanilla. You can include this file to get them, or you can add them to your own file. They will not be changing in our installation of Vanilla:

    // Default values for role permissions
    // Standard Permissions
    $Configuration['PERMISSION_SIGN_IN'] = '0';
    $Configuration['PERMISSION_ADD_COMMENTS'] = '0';
    $Configuration['PERMISSION_START_DISCUSSION'] = '0';
    $Configuration['PERMISSION_HTML_ALLOWED'] = '0';
    // Discussion Moderator Permissions
    $Configuration['PERMISSION_SINK_DISCUSSIONS'] = '0';
    $Configuration['PERMISSION_STICK_DISCUSSIONS'] = '0';
    $Configuration['PERMISSION_HIDE_DISCUSSIONS'] = '0';
    $Configuration['PERMISSION_CLOSE_DISCUSSIONS'] = '0';
    $Configuration['PERMISSION_EDIT_DISCUSSIONS'] = '0';
    $Configuration['PERMISSION_VIEW_HIDDEN_DISCUSSIONS'] = '0';
    $Configuration['PERMISSION_EDIT_COMMENTS'] = '0';
    $Configuration['PERMISSION_HIDE_COMMENTS'] = '0';
    $Configuration['PERMISSION_VIEW_HIDDEN_COMMENTS'] = '0';
    $Configuration['PERMISSION_ADD_COMMENTS_TO_CLOSED_DISCUSSION'] = '0';
    $Configuration['PERMISSION_ADD_CATEGORIES'] = '0';
    $Configuration['PERMISSION_EDIT_CATEGORIES'] = '0';
    $Configuration['PERMISSION_REMOVE_CATEGORIES'] = '0';
    $Configuration['PERMISSION_SORT_CATEGORIES'] = '0';
    $Configuration['PERMISSION_VIEW_ALL_WHISPERS'] = '0';
    // User Moderator Permissions
    $Configuration['PERMISSION_APPROVE_APPLICANTS'] = '0';
    $Configuration['PERMISSION_RECEIVE_APPLICATION_NOTIFICATION'] = '0';
    $Configuration['PERMISSION_CHANGE_USER_ROLE'] = '0';
    $Configuration['PERMISSION_EDIT_USERS'] = '0';
    $Configuration['PERMISSION_IP_ADDRESSES_VISIBLE'] = '0';
    $Configuration['PERMISSION_MANAGE_REGISTRATION'] = '0';
    $Configuration['PERMISSION_SORT_ROLES'] = '0';
    $Configuration['PERMISSION_ADD_ROLES'] = '0';
    $Configuration['PERMISSION_EDIT_ROLES'] = '0';
    $Configuration['PERMISSION_REMOVE_ROLES'] = '0';
    // Administrative Permissions
    $Configuration['PERMISSION_CHECK_FOR_UPDATES'] = '0';
    $Configuration['PERMISSION_CHANGE_APPLICATION_SETTINGS'] = '0';
    $Configuration['PERMISSION_MANAGE_EXTENSIONS'] = '0';
    $Configuration['PERMISSION_MANAGE_LANGUAGE'] = '0';
    $Configuration['PERMISSION_MANAGE_THEMES'] = '0';
    $Configuration['PERMISSION_MANAGE_STYLES'] = '0';
    $Configuration['PERMISSION_ALLOW_DEBUG_INFO'] = '0';

Finally, you can check a permission with a function like this:

    function CheckPermission($PermissionName, &$Permissions, &$Configuration) {
         $Default = 0;
         if (is_array($Configuration) && array_key_exists($PermissionName, $Configuration)) {
              $Default = $Configuration[$PermissionName];
         }
         if (array_key_exists($PermissionName, $Permissions)) {
              return $Permissions[$PermissionName];
         } else {
              return $Default;
         }
    }