If the limit has been reached by the added material, the user is shown the error page 403. This patch adds the ability to choose to display the material in the activation limit.
node_limit_with_arrow.png

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sanchiz’s picture

Initial patch

Liliplanet’s picture

Thank you Sanchiz, I've patched the code correctly and 'select nid' shows up fine, but now the limits are not being respected anymore.

In other words, the 'user of role' can now add more nodes even when restricted. It worked before the patch with access denied.

Have you perhaps discovered the same? Would most most appreciate any updates on your patch please :)

sanchiz’s picture

Issue summary: View changes
FileSize
7.34 KB

Hey there! Sorry for delay, not had enough time for creating new patch.

So here patch what works on one of my projects.

There uses Node Limit and Node Limit User of Role modules. You should apply patch and run update.php for apply changes in database, then this should work.

System Lord’s picture

If I understand correctly

There uses Node Limit and Node Limit User of Role modules.

Patch #3 wont work for Node Limit Content Type?

In other words can this patch work when I need to select "Users of Role" AND "Content Type?" Or, is this patch only for admins that need to check "Users of Role" only.

sillygwailo’s picture

The patch in #3 seems to work if you select "Users of Role" and "Content Type". That is, if you assign a node ID in the config, it redirects to that node instead of showing the Access Denied message. It initially didn't work, but did when I cleared the site's cache.

thoughtcat’s picture

I attempted to install the patch in #3 and got some errors. (See pasted Cygwin dialogue below.) I ignored these and ran update.php and cleared cache. Now in the Node Limits interface I do get the "node if access is denied" box but the limit isn't being respected. My limit is 1 of a particular content type for all authenticated users - whether I also select a role from "role" or "users of role" or leave both of those unticked, the users are still able to create multiple nodes of the content type and never get sent to the "nid" page I've entered.

Here's my Cygwin dialogue. This is actually the first patch I've tried to run using Cygwin so I may have done it wrong - I was following the instructions at https://www.drupal.org/node/620014

$ patch -p0 -b < node_limit-selectnode-2032833-3.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/node_limit.install b/node_limit.install
|index ce01853..6b35683 100644
|--- a/node_limit.install
|+++ b/node_limit.install
--------------------------
File to patch: node_limit.install
patching file node_limit.install
can't find file to patch at input line 41
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/node_limit.module b/node_limit.module
|index 4291c92..c8a32a4 100644
|--- a/node_limit.module
|+++ b/node_limit.module
--------------------------
File to patch: node_limit.module
patching file node_limit.module
Hunk #1 succeeded at 83 (offset -5 lines).
Hunk #2 succeeded at 153 (offset -5 lines).
Hunk #3 succeeded at 187 (offset -5 lines).
Hunk #4 succeeded at 197 (offset -5 lines).
Hunk #5 FAILED at 228.
Hunk #6 succeeded at 236 (offset -5 lines).
Hunk #7 succeeded at 249 (offset -5 lines).
Hunk #8 succeeded at 473 (offset -5 lines).
Hunk #9 succeeded at 501 (offset -5 lines).
Hunk #10 succeeded at 554 (offset -5 lines).
Hunk #11 succeeded at 569 (offset -5 lines).
Hunk #12 succeeded at 598 (offset -5 lines).
Hunk #13 succeeded at 735 (offset -5 lines).
Hunk #14 succeeded at 751 (offset -5 lines).
1 out of 14 hunks FAILED -- saving rejects to file node_limit.module.rej
sillygwailo’s picture

@thoughtcat what happens if you apply the patch to the dev version? I had the same error when trying to patch the official release and corrected it by taking the function declaration from the patch and manually changing it.

Patches should generally be made against the dev versions of modules, and in this case, the patch in #3 applied cleanly to the dev version of Node Limit.

thoughtcat’s picture

@sillygwailo Sorry, I didn't get a notification of your reply! Thanks, I will look into that.

thoughtcat’s picture

Instead of using the module to redirect to a specific node, I created a custom "access denied" page with the following code to display certain messages depending on the URL the user is trying to access when they get "access denied":

<?php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if ($actual_link == "http://www.mysite.com/node/add/form") 
{ echo "You aren't allowed to add more than 3 forms per hour."; }
if ($actual_link == "http://www.mysite.com/node/add/profile")
{ echo "You are only allowed to add one profile. You can edit your existing profile in your account settings."; }
else 
{ echo "Sorry, you aren't permitted to view this page."; }
?>

NB: This isn't perfect PHP ;-) It's only meant to show the last message for all other cases of "access denied" i.e. if the first two tests fail, but instead if the user is coming from /node/add/form they see the first message as well as the last one.

brunomolica’s picture

#3 working fully in dev version

JordanMagnuson’s picture

Patch applied fine to dev release, and seems to work as desired.

sillygwailo’s picture

Status: Needs review » Reviewed & tested by the community
JordanMagnuson’s picture

Status: Reviewed & tested by the community » Needs work

Discovered a problem with this patch: the node limit gets triggered and an ajax error is displayed if the user attempts to remove/upload a file to a fielfield when editing an already existing node. See screenshot: https://c4.staticflickr.com/8/7757/18026420939_60b59beda7_b.jpg

Can be fixed by adding a check for arg(0) != 'file' in _node_limit_violates_limit() in node_limit.module:

      if (!empty($limit['nid']) && arg(2) != 'edit' && arg(0) != 'file') {
        if ($form) {
          drupal_goto('node/' . $limit['nid']);
        }
        return FALSE;
      }
abhinaba9’s picture

This issue has been solved in the dev version. Whenever a limit is reached we are showing an error message. Check out using the node_limit 7.x-1.x-dev version

JordanMagnuson’s picture

The patch that has been applied to dev is not adequate. Custom error message and/or redirect needs to be configurable per limit (as the patch in this issue provides)--not per node type. (Either that, or we need access to more placeholders in the error message: such as the timeframe of the limit, and the actual node limit number for the timeframe).

It's quite possible to have a limit of say 1 forum topic per day, and 10 forum topics per week, and want to show a different message when each of these limits is hit. The patch from https://www.drupal.org/project/node_limit/issues/1364410 does not allow for this.

JordanMagnuson’s picture

The patch in #3 no longer applies cleanly to latest dev.