Update:Remora Vanilla Integration

From MozillaWiki
Jump to: navigation, search

« Back to Update:Remora

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;
         }
    }

Vanilla Administration

In order to have access to the Vanilla administration pages, you will need to be assigned to Vanilla's Administrative role. By default that RoleID is 4. If you go into the users table and change vanilla_role_id to 4 on your user record, you will immediately have access. There are no new links that appear on the forum pages (yet, at least). To access the administrative page, enter the following into your url:

http://site.url/discussions/settings.php

If you have granted yourself access properly, you will see the admin pages. If not, you will be redirected back to the discussions index.

There are currently only two administrative sections available to you. All other admin screens have been removed because they do not apply to the Mozilla installation of Vanilla. The two sections you do have access to are category management and role management.

Categories & Add-ons

Shaver requested that the ability to create a discussion related to a category OR an add-on be available in Vanilla. I have made this possible. I changed the new discussion form to also have a category dropdown. This means that currently if a user is adding a discussion to an add-on, they also must select which category it goes into. If this is not the desired functionality, please let me know so I can change it. It might make more sense to have all add-on related discussions default to a "general" category when being added and only display the category dropdown if no add-on id was provided when creating the discussion.

There is currently no way to relate a category-specific discussion to an add-on id (assuming that a discussion was added to a category and NOT an add-on). This will currently have to be accomplished through the database by specifying the add-on id in the discussion table manually - until we come up with some kind of "lookup" function to identify an add-on to relate. I am assuming that there will be far too many add-ons to place in a simple dropdown list.

Category Related Discussions

The current way to review all discussions related to a particular category is to use a url like so:

http://site.url/discussions/?CategoryID=1

There is also a "categories" page at:

http://site.url/discussions/categories.php

The categories page has not had any css applied to it yet. I wasn't sure exactly how you guys might want it laid out - I received no mock-up for this type of page.

Personally I don't like that page and I think a different page might be more useful. Recently an add-on was created for Vanilla which displayed all categories - underneath each category it displayed X number of new discussions. It was a much more useful screen and I think it might be much preferable here as well. You can get a peek at the add-on here:

http://lussumo.com/addons/?PostBackAction=AddOn&AddOnID=189

We could alter the categories page to work this way if you wish. This would give non-add-on-related-discussions a much more comfortable home.