The Goal:
Allow regular users to download a feeds template without the need to give the permission to import or other feeds permissions.

The Solution:
I added a extra permission per feed importer
Changed the access_callback to the new permission

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ikeigenwijs created an issue. See original summary.

MegaChriz’s picture

I'm not so sure about this. What is the point of having access to the Feeds download template, without having access to import a file that can be created using the template?

Code review:

  1. +++ b/feeds.module
    @@ -317,7 +322,7 @@ function feeds_menu() {
    -    'access callback' => 'feeds_access',
    +    'access callback' => 'feeds_template_access',
         'access arguments' => array('import', 1),
    

    This change will cause that users who are allowed to import now can no longer download the Feeds template. Shouldn't the import permission inherit the download template permission? If not, then there should be an update function to add the permission for people who are now allowed to import. Also in this case, the link to the download template should not be shown on the import form if the user is not allowed to download the template.

  2. +++ b/feeds.module
    @@ -477,6 +482,23 @@ function feeds_page_access() {
    +  foreach (feeds_enabled_importers() as $id) {
    +    if (user_access("Access template $id feeds")) {
    +      return TRUE;
    +    }
    +  }
    

    This just checks if an user has access to any importers template, rather than the template of the importer in question.

It sounds like this feature would fit better in a custom module. In that module you could implement hook_menu_alter() to change the access callback.

ikeigenwijs’s picture

Assigned: Unassigned » ikeigenwijs
Status: Needs review » Needs work

Our use case

In our use case the regular users (100 people) fill in the template.
And that user sends the filled in template to one of the curators (4 people)

We are not to keen to allow the regular users to allow the import itself.
We tried that and the errors by the users of filed in fields but in the wrong column ware uncountable.
Even copy past in the same column gave problems for some.
Switch Firstname and last name as basic example. New values are allowed so this is unable to get detected by temper.
This is just an example.
We have some extra reasons to want to limit the actual import permission. But out of scope here.

As a general use case for other sites:

I can imagine a regular user giving input in the form of filled in template. But reviewed by an expert before being imported to assure content quality control.

The feedback

Number 1 is just plane stupid on my part :-s
The goal was to just open up the template and leave al the rest as is.

Number 2
The user that tested has no feeds import rights except the new download permission.

Ill take a look at it.
thx for the feedback

ikeigenwijs’s picture

Assigned: ikeigenwijs » Unassigned
Status: Needs work » Needs review
FileSize
1.35 KB

I reverted to following the current permission structure of feeds what resulted in less extra code.

The consequence of this strategy is that the template permission must be granted, even for users who have the import permission.
This to analogy of the import,clear, unlock permission

So when the patch gets through this should be reported or catched in an _update hook

Issue 1 is fixed
Issue 2 is fixed

ikeigenwijs’s picture

bump

ikeigenwijs’s picture

Title: Extra permission to allow users to download the template » Extra permission to allow users to download the template but no need to grant the general feed permission

Better title.

cpeeters’s picture

I could you this extra permission for my site very well. I have quite some users which are allowed to fill in a template but I do not want to give them the permission to do the import itself, because I want to do this myself after a thorough check of the data. Currently I have to provide the latest template for the feeds importer by downloading and sending it by mail, and it would be very handy of I could provide them the link with the (latest version) template file instead!

MegaChriz’s picture

Thanks for your efforts and explanations, though I still think this feature is an edge case. And it can easily be implemented in a custom module. I also think that an user with permission to import should always be able to download the template; I can't think of any case where one may import but may not download the template.

Custom module example:

/**
 * Implements hook_menu_alter().
 */
function mymodule_menu_alter(&$items) {
  // Change the access callback for the Feeds importer template.
  if (isset($items['import/%feeds_importer/template'])) {
    $items['import/%feeds_importer/template']['access callback'] = 'mymodule_importer_template_access';
    $items['import/%feeds_importer/template']['access arguments'] = array(1);
  }
}

/**
 * Menu access callback for generating the importer template.
 *
 * @param FeedsImporter $importer
 *   The importer to check access for.
 *
 * @return bool
 *   TRUE if access should be granted.
 *   FALSE otherwise.
 */
function mymodule_importer_template_access(FeedsImporter $importer) {
  // (your logic here)
}
ikeigenwijs’s picture

I also think that an user with permission to import should always be able to download the template;

I agree, but not the other way around which is our use case, a user allowed to download and fill in the template should not always be allowed to do the actual import.
This is always the case when there are curators that safeguard the data quality.

I ll look in to the custom module approach and post the result here.

ikeigenwijs’s picture

The custom module solution files added for other drupal users.

This works for our situation but is very crude( just a roll check).
Is less flexible and a less clean than the previous solution.
It will need code change when the situations changes.

Not as flexible and integrated with feeds, users, rolls and permissions as the previous patch.

twistor’s picture

I agree with MegaChriz. It's a nice idea, but works perfectly fine in a separate module.

MegaChriz’s picture

Status: Needs review » Closed (won't fix)

@ikeigenwijs
To make the custom module approach more flexible, you could implement permissions in there.

/**
 * Implements hook_permission().
 */
function mymodule_permission() {
  foreach (feeds_importer_load_all() as $importer) {
    $perms["template $importer->id feeds"] = array(
      'title' => t('Download template from @name feeds', array('@name' => $importer->config['name'])),
      'description' => t('Users with this permission can get the template to fill in.')
    );
  }
  return $perms;
}