This module is great, but I have a special needing and I need a little help :-)

I have a single view, listing documents of single users. Something like:

/documentsof/john
/documentsof/jack
/documentsof/...

which will show a list of documents created by john, a list of documents created by jack, etc. The view must be "public" (all lists are public, including anonymous).

John should be able to arrange the view of his documents, as well as jack, etc. So I gave those users' role the "access draggableviews" permission, and it works.

But, since the view is unique in all the website, now John can also sort jack's view, and viceversa. I plan to have several users, so this is not acceptable. So I realized that I had to write a little custom module - to customize the permission of each users. The logic should be: if I am Jack and I am watchin /documentsof/jack (my documents) i should be able to drag into the view. But if i'm watching /documentsof/john I should only watch it, and I shouldn't be able to "drag".

I tried several different approaches to solve this problem, including assigning temporary roles, but nothing worked as I wanted. The only way I found was: writing a function mymodule_form_alter, checking current user, arg(0) and arg(1), and if they don't match, remove both the "submit" button and the draggableviews_list.js; something like

  if ($form_id == "views_form_draggable_page") {
     global $user;
     $javascript = &drupal_static('drupal_add_js', array());

    if ((arg(0) == "documentsof") && (arg(1) == $user->name)) {
	 //do something
      } else {
	     drupal_set_message("should disable");
         $form['actions']['submit']['#access'] = FALSE;
        unset($javascript['sites/all/modules/draggableviews/js/draggableviews_list.js']);
        }
	 }

And it works! I just wonder if this is a correct approach, it there's something else that I should remove/modify, or maybe if there's a... simpler way? :-)

thanks for your great job!

fb

Comments

francoud’s picture

Issue summary: View changes
jay.lee.bio’s picture

Francoud, were you able to finish the custom module? Unfortunately permissions still don't work on this module, so your solution is the best we have at the moment. Thanks for any help.

iStryker’s picture

Status: Active » Postponed (maintainer needs more info)

@wwjaylee permission do work, at least with my test #2065111: Permissions don't work properly.

Your method is not bad, but I can think of another. The best method I can think of is with path access and tokens. User will only have access to /documentof/draggabledocuments/[current:user]. Where /documentof/draggabledocuments is the path to the view and [current:user] is the token and the contextual argument/filter of the draggableview. Then only the current user can view their own documents.

kyleheney’s picture

The ability to grant reordering permission per view is something I'd really make use of. For example, I have several "administrative" lists that I want to reorder, but that I don't want others to be able to modify. However, I also have other lists that I would like others to be able to modify. It would be great to have a permission per view that allows certain users (or roles) to have access to the reordering for that view, while preventing them from reordering lists that should only be edited by admin users.

iStryker’s picture

@kyleheney I think your needs are different from @wwwjaylee. You can use views build in permission. All you have to do is set the reorder display to X role, while the non-reordering to Y role.

kyleheney’s picture

@iStryker I don't think I understand how to set the reordering role... is that in the Views Access settings? Or is it done through the Draggable Field? Or some other setting?

Or are you saying I should create two views displays for one list? One list with access for draggable users, the other display with no draggable access?

iStryker’s picture

Yes 2 separate displays.

Technical speaking you can have 1 view display with reordering. The draggable option only shows if you have the draggableviews permission. This is not the best solution. It is better to have 2 display, where the 1 display uses the sort order from the reorder displaying.

kyleheney’s picture

What I'm not understanding is that I need Role A to drag View A; Role B to drag View B... from what I can tell, I can only grant the Draggable permission on a "global" basis to both Roles.

If I set the access to View A to be only for those with the Draggable permission, then both Role A and B will be able to modify it. Same goes for View B...

Am I missing something here? This doesn't seem to accomplish anything...?

iStryker’s picture

You set access to reorder display to Role A under Access. Then in the other display you Set access to Role B, or to no Role at all, so all can view it.

kyleheney’s picture

Oh okay, sorry, was only thinking of Access in terms of the Drag permission, not in terms of access to that particular view. This makes sense now. Thanks for the tip.