First of all, I want to say that I find this module excellent.
I'm building an eLearning portal and I'm using the Outline Designer already quite a lot.
I organized some testing sessions on an early version of my portal with the future users and I had quite a lot interesting feedback, some of them concerning the Outline Designer.
One thing we would like to be able to do is to customize a bit more the Context menu, like removing some of the actions offered in the menu (like "Change type" which might be "dangerous" for a novice user who doesn't understand well enough what it involves).
Anyway, I took it on me to implement this feature and submit a patch in case you would be interested in adding this functionality more permanently into the Outline Designer.
To summarize the functionality added by this patch: it gives you a series of checkboxes in admin/content/book/outline_designer to turn on/off items in the Context Menu (see screenshot attached).

Comments

btopro’s picture

I like the idea but would it possibly be better to make the ability to access different context menus in outline designer a permission based structure instead of a global add/remove? In the future I'd like to add a hook system so that other modules could add contextual functionality to the outline designer context menu.

I could see an admin wanting all functionality while giving a copy editor just the ability to edit / view material without being able to add new. While OD does respect permissions of the system it doesn't remove buttons from the context menu (it'll just throw an error).

Again, love the idea, thoughts on making it permission based instead of a global setting?

tlaurent’s picture

I agree that my implementation lacks flexibility. I was telling myself the same thing. As an administrator, I'd like to have all the options available in my Context menu, but I'd like to hide some of them for the trainers/teachers.
The settings screen would need to look like the Drupal permission one, with a matrix user role/visible items.
But, I don't think that the settings should be moved to the permission page, as they are not really permissions per se.
Correct me if I'm wrong, but the permissions for the Context menu actions are already on the permission page:
- Add content -> (Context menu) => create permission (Permissions page)
- Rename (Context menu) => edit any/own permission (Permissions page)
- Edit (Context menu) => edit any/own permission (Permissions page)
- View (Context menu) => access content (Permissions page)
- Delete (Context menu) => delete any/own permission (Permissions page)
- Duplicate (Context menu) => create permission (Permissions page)
- Change type (Context menu) => edit any/own permission (Permissions page)

So, we shouldn't duplicate these permissions.
I think the best way would be to extend the Context menu settings from my patch into a matrix to move from my rigid global add/remove to a per role more flexible one (I'm a bit concerned about the look of it if there are many roles defined on the site... mind you, some other modules do it that way, e.g. delegate_menu_admin, http://drupal.org/node/478596).

One other thing which would be nice would be to check the permissions when opening the Context menu to see what the user can do with it and disable the items he can't use. But I'm not sure what would be the impact of this extra call on the speed to open the menu...
But that's a bit more complex, and I'm not sure I'd have the time to investigate this one at the moment.

So, what are your thoughts about changing the global settings into a more flexible matrix ? Do you want me to have a crack and release a patch or you're not keen on the idea ?

btopro’s picture

Status: Needs review » Needs work

I like idea of a matrix, that makes sense and I understand why you're saying it should happen outside of the permissions page. We can't map permissions directly to items because of the complexity of what it opens up. You'd need to do an on the fly node_access call for each operation every time you loaded a node and clicked the edit button. If you made assumptions otherwise, you'd be removing any other modules that mod permissions like og, TAC, node access and node permission by role. So I think the hit wouldn't be worth it. Throw up the operations and block people from performing them on the grid you're talking about. If there's 9 nodes you have the ability to do all those operations to and 1 you can't then it's better to just say 'access denied' in the pop up message returned then do the call every time.

Matrix it up if you like, love the idea and I think this would be a great addition. As a heads up, I have the following two features on my list of things to do over the next month or so to add to this project:

• Come up with a way of duplicating from one branch to another
o duplicate to another branch you have permissions on the duplicate menu item
• Iterative duplicate
o Duplicate branch X, N number of times, iteratively based on a convention
• Fields: number of duplicates, convention (A,B,C, 1,2,3, I,II,III)

That said, I'll probably roll another version with this patch and others in a month.

tlaurent’s picture

Hi btopro,

I finally found some time to rework my patch and create a more flexible matrix-like interface to select visible context menu items.
Here's a little summary of what the patch do:
- find roles with the permission 'administer book outlines'
- display a table with roles as columns and a list of checkboxes underneath (1 per menu item)
- if a user has several roles, he'll get the combination of the roles settings (for example, "Role1" can "View" and "Role2" can "Edit" and "Add Content". If a user has "Role1" and "Role2", he can "View", "Edit" and "Add Content")

Some side notes: I wanted to keep the current OD behaviour regarding the default context menu content (e.g by default, you get all items), so that if the administrator who installed OD doesn't go to the OD administration page, he'll get the current OD settings (e.g. all items available in the context menu, as in 6.x-1.2).
So, to achieve that, I'm storing the menu items NOT available per role, so, as a result:
- when the module is first installed, by default, all roles with the permission 'administer book outlines' will have the complete context menu
- when a new role get the 'administer book outlines' permission, it'll also get a complete context menu (all checkboxes ticked)
On top of that, if you remove the 'administer book outlines' permission from a role, the stored settings for this role will be ignored, and won't affect how the context menu is displayed for a user with this role in addition to a role with different settings for OD.

In addition, user1 will always get the complete context menu.

I tried to cover all the use cases I could think of (it took me quite a few rewrites to achieve that in fact !) to be sure it wouldn't affect the current behaviour of OD, while adding this new functionality.
I have tried to comment my code as much as possible and keep it tidy so that you could modify it easily if you need to.

btopro’s picture

Status: Needs work » Needs review

Awesome! I'm right in the middle of something but I'll have to try this out soon. In reading through what you've put forth makes sense. A few thoughts...

* If the admin module is installed you could look and see what that role is considered and check all those boxes by default
* Why not set all to see everything by default? This way people who install / upgrade to this project will be saying "by default I want the same functionality but let's make some changes"
* It seems like it would be possible to give a role NO permission to use the context menu (in which case they could just drag and drop reorder items and change titles)

Ultimately a goal of this project is to allow end users to use the outline designer in varying degrees. Right now my thinking is that if you created a book and you have the "create new books" as well as "add content to books" that the combination of those two permissions should be enough to say "you're responsible enough to use the outline designer on content that you created / own". I think that you're patch fits in with that vision very well. If others could test / add thoughts on this topic that'd be great so we can build some consensus on the project setting up for this direction.

tlaurent’s picture

I think we are on the same wavelength here :-)

Until you can test it in person and make up your mind about it, here's a few precisions about your questions:

"* If the admin module is installed you could look and see what that role is considered and check all those boxes by default"
Are you talking about this module (http://drupal.org/project/admin) ? I have never used it, so I can't really comment on that.
I'm not sure what you mean by "what that role is considered". All roles with "administer book outlines" permission will appear in the matrix.

"* Why not set all to see everything by default?"
Yes, this is indeed the default. All roles who can see the OD page (e.g. with "administer book outlines" permission) can see everything by default.

"* It seems like it would be possible to give a role NO permission to use the context menu (in which case they could just drag and drop reorder items and change titles)"
Yes, if you untick all the boxes that'll be the case. But this usage is pretty limited, the user just need to turn off javascript and he'll have access to view/edit/delete again ;-) This patch just add extra customization of OD, but doesn't change the real permissions.

btopro’s picture

Cool. Ok, I just misunderstood your descriptions in the patch. I'll chuck it on and see how it works on a fresh install. Definitely looking forward to it. It might be a good idea just to have all the roles there on the matrix with all set to do everything by default, then a help message saying only those with permission 'administer book outlines' will be able to utilize these settings. Only reason for this change is that in the future I plan on changing things a bit permission wise like I said for the show interface to non-admins / people without the administer book outlines. This way when that change happens it won't completely fudge the checkbox maxtrix (and I'm hoping to add this functionality to 1.3 anyway).

tlaurent’s picture

"show interface to non-admins / people without the administer book outlines"

I'm not sure I quite understand what you mean.
How will you be able to do that ? I thought that unless you had the "administer book outlines" permission, you couldn't even access the /admin/content/book/[book-number] page at all ?
Are you planning on duplicating this page to bypass the need for this permission ?

btopro’s picture

the included outline designer OG module in 1.2 allows for the editing of books by group admins / creators without accessing the admin/content/book page. the goal is to add the ability to edit your own books (not all hence no admin book outlines permission) that you create or have access to edit. This way users could make their own books and leverage the power of the outline designer without being able to royally screw up all / other books. Check out http://drupal.org/node/1016248 as it starts to go in this direction too.

tlaurent’s picture

I think I need to have a look at the OD-OG integration because it sounds exactly like something I desperately need for my project. I never took the time the investigate OG properly even though I had the feeling that might be the way to go...
Anyway, I see that you did a screencast for OD-OG (great idea !), I'll have a look at it and I'll have a clearer idea after that.

tlaurent’s picture

Ok, I finally had the time to check out the outline designer OG module and understood why restricting to roles with "administer book outlines" was a bad idea.
So, I've re-created the patch without this restriction (the only restriction is now on "anonymous user", which is removed from the list).

btopro’s picture

Status: Needs review » Reviewed & tested by the community

good call, I'll work this into 1.3, thanks for all your work on this!

btopro’s picture

getting the following warning which is making the table / matrix render incorrectly -- warning: Parameter 1 to theme_outline_designer_context_menu_items_matrix() expected to be a reference, value given in /var/www/html/includes/theme.inc on line 656.

Know what could cause this?

btopro’s picture

this warning also gets thrown if you don't check anything; warning: array_filter() expects parameter 1 to be array, null given in /var/www/html/sites/all/modules/outline_designer/outline_designer.module on line 414. set the variable to array if the values don't get checked

btopro’s picture

fixed both issues; remove the by reference call to the form object (it's unnecessary) so the function call should read:

function theme_outline_designer_context_menu_items_matrix($form) {

To fix the other array issue with no checkboxes being unchecked in function _outline_designer_settings_submit add the following line to the function

function _outline_designer_settings_submit($form, &$form_state) {
  $items_unchecked = array();

Haven't gotten to test the patch for respecting the settings based on role as my dev system hasn't gotten into roles much but looks good so far!

tlaurent’s picture

Oops, very sorry for that !
i'll put your fixes in tomorrow morning and test on my build. If everything is ok, i'll regenerate the patch.

btopro’s picture

cool; and I'm going to start playing with the permission side tomorrow to make sure it's ok (though from a quick glance it is). Then I'll start working on the 1.3 release and hopefully can get it out by the end of the week (day if nothing comes up tomorrow). Next in my queue is #1016248: outline designer integration but I've already got you're current fix in. If you notice anything else I'll roll a new patch on my working copy but atm I think it's pretty good.

tlaurent’s picture

Ok, I've tested your fixes and they're working well, but I found another of my sloppy piece of programming :-(
Another non initialized variable...
So, here's the latest version of the patch with your fixes and the additional fix for the latest non initialized variable.
Sorry again for these mistakes.

btopro’s picture

is this in the scripts file the only new var instantiated? var contextMenuItems = new Array(); Sorry, applied a bunch of different patches so if you could do a diff from between your two patches that'd really help me on this one.

No worries, you're adding a great new feature to the project!

tlaurent’s picture

It was in
_outline_designer_settings_submit($form, &$form_state)
were you already found that $items_unchecked was not properly initialized, but this time it was $checkboxes (initialized only under certain conditions... doh !)

No problem for the diff between the 2 patches, here it is. I hope the patch process will work despite your additional changes on your local copy. Let me know.

btopro’s picture

Version: 6.x-1.2 » 6.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

perfect, thank you! I apply most patches by hand cause I'm a control freak :p

btopro’s picture

hmm.. found a biggy...

Based on the way things are structured (an array of what shouldn't be there) it's very difficult to do array merges correctly. Especially when authenticated user is an allowable choice because EVERYONE is ALWAYS an authenticated user as well as another role. Hmm... still working through it but it's a bit tricky. Essentially whatever the lowest level of perms is in the roles someone has is what shows (for non user 1 obviously since that skips the test in your patch).

so, authenticated users will presumably always have less permissions then people with roles, hence auth user's array always "wins"

Array
(
    [2] => Array
        (
            [nid] => Array
                (
                    [unchecked] => 1
                )
 
            [add_content] => Array
                (
                    [unchecked] => 1
                )
 
            [delete] => Array
                (
                    [unchecked] => 1
                )
 
            [duplicate] => Array
                (
                    [unchecked] => 1
                )
 
            [change_type] => Array
                (
                    [unchecked] => 1
                )
 
        )
 
    [4] => Array
        (
            [nid] => Array
                (
                    [unchecked] => 1
                )
 
            [change_type] => Array
                (
                    [unchecked] => 1
                )
 
        )
 
)

That's the output of the array matrix for the 2 roles I have, the one with the least stuff is the auth user, the other is an admin role

btopro’s picture

Status: Patch (to be ported) » Needs work
btopro’s picture

Status: Needs work » Fixed

nm, it's working, logical goof on my part with some other patch. Looks great, working it into 1.3 as we speak

btopro’s picture

for your patch in case you're working off your version right now that's modified here's the logical issue that the current patch ran into:

if($saved_unchecked_items[$rid] != null) {

When you do the grid if ALL checkboxes are selected then it doesn't save the array. This is a problem because if you select everything you're basically saying that if they have that role they can use the outline designer normally. So...

user = authenticated user and admin (where admin has ALL checkboxes marked)

It will give them the menu of an auth user because the null value is ignored when really it should automatically invalidate the permission process cause if a role isn't set (as per the default behavior) they should see everything. I'm adding a flag that if a role isn't in the matrix that we assume all permissions to view context menu items.

btopro’s picture

Version: 6.x-1.x-dev » 6.x-1.3

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.