Short description

This module creates new settings for each FileField field to define different file upload max size limit for each user role (the limit can apply to single file or to the whole node's files).

Module full description

The Filefield Role Limit module is an extension of CCK FileField module and adds the capability to limit the max upload file size for each different user role.

This module creates new settings for each FileField field to define different file upload max size limit for each user role (the limit can apply to single file or to the whole node's files).
Different limit values can be provided for each user role and the module will automatically switch to default FileField max upload size behavior if no settings per user role are provided.

The Filefield Role Limit module works also with ImageField module.

Dependencies

FileField

Sandbox project

http://drupal.org/sandbox/kongoji/1445696

Core version

6.x

Git access

git clone --branch 6.x-1.x http://git.drupal.org/sandbox/kongoji/1445696.git filefield_role_limit

PAReview

http://ventral.org/pareview/httpgitdrupalorgsandboxkongoji1445696git-6x-1x

Screenshot

See attached file.

Author's note

This module was born from the need to have separate max upload size both for each role and node. I searched for long time a module who could extend FileField in that way, but I couldn't fine anything fitting my needs.

Reviews of other projects

http://drupal.org/node/1454106#comment-5650010
http://drupal.org/node/1454042#comment-5650160
http://drupal.org/node/1390524#comment-5652088

Reviews of other projects #2

http://drupal.org/node/1458772#comment-5661178
http://drupal.org/node/1457398#comment-5666114
http://drupal.org/node/1458858#comment-5666502

Reviews of other projects #3

http://drupal.org/node/1463358#comment-5681276
http://drupal.org/node/1434388#comment-5683354
http://drupal.org/node/1429208#comment-5683408

Comments

kongoji’s picture

Issue summary: View changes

made a sentence more clear to understand

kongoji’s picture

Issue summary: View changes

Made module short description clearer

wilmar81’s picture

Status: Needs review » Needs work
StatusFileSize
new23.85 KB
new41.08 KB

Hi!

I just tested your module and noticed a bug: although I set a maximum file size for "authenticated" role, I could upload a file with a greater size.

Here's how you can recreate the bug:
1- I created a user with role "authenticated"
2- I created a content type and added a new field as you suggested in README.txt
3- The field settings are as follow:
- Permitted upload file extensions: pdf
- I didn't configure 'Maximum upload size per file', but configured 'Maximum upload size per file per role' and set it to '10K' for authenticated users.

The file I uploaded has 1.5M.

Even when I set 'Maximum upload size per file' (2M) and 'Maximum upload size per file per role' (10K), I'm still able to upload my file (1.5M).

You can see attached files.

kongoji’s picture

Status: Needs work » Needs review

Thank you wilmar81 for your review!
I reproduced the bug and I'm sorry about it, I missed some checks in the module and it worked anyway for me because of other developing I did to other modules.
Now I did a new drupal clean install and I corrected the bug (or at least now it works for me).
I took the chance to refactor the code a little bit using hook_form_alter to change the max file size dinamically,
moreover I modified .install file to make sure this module is always weighter than FileField module.

Right now ventral.org online tool is not working, so I made code checks on my local installation. As soon as it will be back online, I'll check with the online tool too.

Wait for your feedbacks again!

mkadin’s picture

Status: Needs review » Needs work

Good work on this module. I've test it it and it works pretty darn well. A few notes from my review:

1) I was able to run the PAReview.sh script on your work, and it passes without issue.

2) There are a few places in your code where you have commented out code sections. I think the convention is to avoid this type of stuff...comments should be for just that...comments. :)

3) It's great that you provide some information to the user when they install the module via drush. The text is escaped funkily though. it's outputted with some HTML entity encoding:
FileField Role Limit settings are available for FileField fields under Administer > Content management > Content types or Administer > Content management > Content types > Fields.

4) Lastly, I think the descriptions for the text fields that take the maxmimum upload sizes could be a little overwhelming, and they all say pretty much the same thing. Imagine a site with 10 or 20 roles, that page could become a little crazy. Maybe there's some way to explain what should be put into each textfield more generally? Core does seem to have its explanation twice, but having it 40 times might be a bit much.

Other than that it looks pretty great to me! I could definitely see a use case for this in my work.

kongoji’s picture

Status: Needs work » Needs review

Thank you for your review mkadin!

You pointed out very good points, I think I fixed all of them:
2) I removed commented code, it was there because of the previous fix from wilmar81's review.
3) I totally forgot about drush! I changed ">" html entity with the char ">", now it should work fine even on Drush.
4) That's a very interesting point, thank you for your suggestion. I moved description from every field to the parent fieldsets only: you were right, it looks a lot better now! I also tried to semplified a little bit the sentences. They are a copy of the FileField max upload size description for the original fields, so I tried to not change them too much.

Turn this issue to "needs review" again, hope to have new feedback soon!

kongoji’s picture

Issue summary: View changes

Corrected a sentence grammar mistake

kongoji’s picture

Issue summary: View changes

Added a review of other application

jpontani’s picture

Just being kinda nitpicky design-wise, but let's say I want to use this on my live site. My live site has 18 roles currently, fieldset is going to be HUGE with that many roles. Why not just switch to an addition style where you choose the role in a drop down and have a textbox next to it, and clicking Add actually adds that role/limit check instead of having it save blanks initially?

Just a thought...now on to manual review.

- You still have some commented out code (lines 106, 108, 122) in your .module file.
- You have a few code lines that are LOONNNGGG. Try spanning them across multiple lines (lines 53, 60, 255, 276)
- You have quite a few occurrences of "[some boolean] === TRUE", this is unnecessary. For example line 35 has

if (empty($roles) === FALSE) { // Will equate to TRUE when $roles is not empty
}
// Simplified form
if (!empty($roles)) { // NOT empty($roles)
}
kongoji’s picture

Hi jpontani, thank you for your review!
I implemented mkadin's suggestion about interface (comment #3) moving every field description to a single fieldset description in the top. I believe his solution is a good halfway between compact and simple interface, but I'm seriously taken your suggestion for a new version of the module to be realized after it will become a full project.

I fixed all other points you wrote, deleting commentend code, concatenating long strings in multiple rows and simplifying "if" structures.

Hope to get new feedbacks soon!

kongoji’s picture

Issue summary: View changes

Added a new review of other applications

kongoji’s picture

Issue tags: +PAreview: review bonus
klausi’s picture

Status: Needs review » Needs work
Issue tags: -PAreview: review bonus

Review of the 6.x-1.x branch:

  • Drupal Code Sniffer has found some issues with your code (please check the Drupal coding standards).
    FILE: ...es/all/modules/pareview_temp/test_candidate/filefield_role_limit.module
    --------------------------------------------------------------------------------
    FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
    --------------------------------------------------------------------------------
     73 | ERROR | BREAK statements must be followed by a single blank line
    --------------------------------------------------------------------------------

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.

manaul review:

  • "$message = st("The %name module installed successfully.",": %name is not a dynamic value, so no placeholder needed. You can just add the emphasize tags in the string if you want them.
  • filefield_role_limit_install(): why do you need to increase the weight of your module? please add a comment about that.
  • filefield_role_limit_widget_settings_alter(): do not pass variables to t(), use literal strings where possible. Otherwise translation tools cannot extract the text from the source code. Also elsewhere.

Otherwise I think this is nearly ready. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

kongoji’s picture

Status: Needs work » Needs review

Hi klausi, thank you for your review!

I fixed all points you said, I only have some concern about

"$message = st("The %name module installed successfully.",": %name is not a dynamic value, so no placeholder needed. You can just add the emphasize tags in the string if you want them.

isn't more simple for translators to have a single sentence to translate rather than having N identical sentences except the module's name?

I mean, look at how many strings have to be translated, when it would be a lot simpler to have a standard like The %name module installed successfully.

It's just my opinion (I changed the sentence the way you told in my module), but I think that localization work should be standardized a little bit more.

Changed to "needs review" again, wait for your feedbacks and reviews!

kongoji’s picture

Issue summary: View changes

Added a review of other project

kongoji’s picture

Issue summary: View changes

Added a new project review

kongoji’s picture

Issue summary: View changes

Added a new review link

kongoji’s picture

Issue tags: +PAreview: review bonus

New Reviews of other projects (Reviews of other projects #2) added.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

manual review:

  • filefield_role_limit_install(): filter_xss() is not needed, no user provided input involved.
  • filefield_role_limit_widget_settings_alter(): $perfile_description does not have to be an array, use ".=" to append to an existing string. Same for $pernode_description, then you also don't need the implode().

But that are just minor issues, otherwise I think this is RTBC. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

klausi’s picture

Issue tags: -PAreview: review bonus

Forgot to remove the tag.

klausi’s picture

Issue summary: View changes

Added a new review

kongoji’s picture

Issue summary: View changes

Added new project review

kongoji’s picture

Issue summary: View changes

Added new review of other project

kongoji’s picture

Issue tags: +PAreview: review bonus

Hi klausi,
thank you for reviewing my project!
I think I've been able to fix all the things you noticed, removing filter_xss() from .install file and concatenating the field description strings.

I added 3 new reviews (see "Reviews of other projects #3"), so I add a bonus tag.

patrickd’s picture

Assigned: kongoji » Unassigned

Please don't assign the issue to your self, only the current reviewer should do this.

klausi’s picture

Assigned: Unassigned » tim.plunkett

Assigning to tim.plunkett, as he said he might have time to review this.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Fixed

The module looks great, and welcome to the community of project contributors on drupal.org.

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

As you continue to work on your module, keep in mind: Commit messages - providing history and credit and Release naming conventions.

kongoji’s picture

Wow! Thank you tim.plunkett and everybody else who spent time reviewing this project (wilmar81, mkadin, jpontani and klausi, thank you!)
The review project gave me the chance to learn a lot more about coding drupal modules, I'll keep an eye on projects waiting for reviews queue.

Project page is now available here:
http://drupal.org/project/filefield_role_limit

Thank you all!!!

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

Anonymous’s picture

Issue summary: View changes

Added new other project review