Synopsis
This module is build for Drupal 7.
This is unique module which helps user to hide nodes based on Visitor's Country's IP Address.
As per our findings there is no similar module on drupal.org which provides similar functionality.
This module helps to create country specific Node's i.e. Node will be hidden for the selected countries. It detects gets User's country from Ip2Country information and based on this it shows/hides nodes.
Note: This module denies access to node based on the countries selected in the node edit form. It does not hide the displaying/rendering of nodes in listing e.g. Drupal's front page listing of nodes, instead it provides a $node->hidden value to the template and in node_load object to determine whether to display the nodes at template level ot any other custom rendering of nodes. $node->hidden contains 1 for hidden nodes and 0 for non hidden nodes.
Project Page:
Requirements
This module requires following modules as dependencies-
- IP2Country
- Locale.
- Field.
- List.
Installation and Configuration:
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/cmak/2290579.git country_specific_nodes
- Download/Clone and enable module through admin/modules.
- Go to Structure -> Country Specific Nodes, select content types and click Save to attach country selection field to the selected content types, unchecking will remove country selection field from respective content types.
- Go to Structure -> Country Specific Nodes -> Set Default Country to specify
the default/fallback country if the users IP is not been detected by IP2Country (in rare cases). - Add any dummy content to any content type of Entity Node and select country/countries for which the nodes needs to be hidden/access restricted and save it.
- After saving, View the node as normal user, as hook_node_access is not invoked for admin user, we will need to verify node access through any other user roles.
- Also note that this module adds a $node->hidden value to the node object as 0/1 to indicate that this node is hidden or not while rendering a node (0 -> not hidden, 1 -> hidden).
After enabling, this module create a field while installation of the module and after we select content types from the Country Specific Nodes form, it will create instances of the field and attach it to the content type.
This module has a setting option to specify a default country code if the user country is not detected in some case. Default fallback country is India (IN).
$node->hidden is provided in node object to hide the display of node while rendering in custom or theme templates.
Credits
Special thanks to below members for making this module possible-
Comments
Comment #1
cmak commentedComment #2
cmak commentedComment #3
VikrantR commentedComment #4
sandeep.kumbhatil commentedComment #5
cmak commentedComment #6
cmak commentedComment #7
cmak commentedComment #8
cmak commentedComment #9
PA robot commentedWe are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)
Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).
I'm a robot and this is an automated message from Project Applications Scraper.
Comment #10
cmak commentedComment #11
sandeep.kumbhatil commentedComment #12
hemangi.gokhaleAutomated Review
Issues identified by pareview.sh seems to be clean.
Manual Review
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/cmak/2290579.git country_specific_nodesinstead of thisgit clone --branch 7.x-1.x cmak@git.drupal.org:sandbox/cmak/2290579.git country_specific_nodescountry_specific_nodes_content_typeincountry_specific_nodes.modulefile on line number 89 should be incountry_specific_nodes.admin.incfile insidesystem_settings_form()also the function on line number 131 should be incountry_specific_nodes.admin.incfile.The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.
If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.
This review uses the Project Application Review Template.
Comment #13
klausiHaving the menu/form callbacks in the module file are surely not application blockers, anything else that you found or should this be RTBC instead? And anyone can fix the git clone command in the issue summary.
Comment #14
cmak commentedComment #15
ajitsThank you for your contribution!
Automated Review
PAReview doesn't complain about any issues on the module. Good job on taking care of that!
Manual Review
country_specific_nodes_def_cn) value usingsystem_settings_form, but you aren't deleting them on module uninstall. Please make sure to delete the variable from the implementation ofhook_uninstall().Move the comment above the function declaration, after the line
Implements hook_node_load().country_specific_nodes_node_load(), you check if the user has the id 1 to confirm if the user is the administrator. However, there might be many administrators for the site. If this is the intended behavior, add the appropriate behavior, or check for the role in the$userobject.country_specific_nodes_content_type_submit()? Please add a comment. I think only creating the instance of this field should be enough.field_cronfrom inside the if-else loop. Running the cron function even if a field is not created/deleted is an overkill.country_specific_nodes_content_type_submit(), the array$country_instanceis of no use when the user did not select any of the values because it will not go into the if condition where you check the value of$type_val. I would suggest creation of the variable inside the if condition. This will ensure that the code is clean.field_delete_field(), only marks the field to be deleted and does not delete the field directly. Instead the field is deleted on the next cron run. This is okay, just wanted to let you know about this and let you decide how would you want to handle this. Please see this answer for more explanation.country_specific_nodes_default_country(), between another function which returns the formcountry_specific_nodes_content_type()and its submit functioncountry_specific_nodes_content_type_submit(). It makes the code less readable. I would recommend you to move the function somewhere else, so that the form function and form submit function are together. I would think of moving all the configuration related forms to a separate file altogether, country_specific_nodes.admin.inc as suggested earlier as well.The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.
If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.
This review uses the Project Application Review Template.
Also, after making the changes, I would suggest to participate in the Review bonus program and someone from the GIT admin team would look at your application right away!
Comment #16
ajitsAlso, would you comment on why this issue is tagged under "PAReview: Single project promote"? I think this project has code which would qualify you to get the vetted user access as well. Please remove it if this wasn't intentional.
Comment #17
cmak commentedHi Ajit,
Thanks for such a detailed review. I have removed the "PAReview: Single project promote" tag as it wasn't intentional. Also, please find my comments on your points below.
Working on other mentioned points.
Thanks,
Makarand.
Comment #18
cmak commentedHi Ajit,
I have fixed all other points mentioned by you. So marking this as Needs Review. Also for Point 8, I have called
field_cronin if condition to cleanup country table.Thanks,
Makarand.
Comment #19
ajitsAlmost there! Sorry I missed to mention one point earlier. You should consider adding a validate function to the form
country_specific_nodes_default_country(), and check if the user enters a valid country code.I was able to save the value
asdfas the country code.This could be checked by comparison of the value entered with the countries returned by
country_get_list()for the list options.Another option which you could opt for is this, instead of having the user to enter the value in a textfield, you could make a select list for the same with the values of the available countries.
I think this is the only issue which is remaining, which I could find, is a blocker. Other than this looks like RTBC to me.
Comment #20
cmak commentedHi Ajit,
Good catch, I have changed the textbox to a select list for default country selection.
And as per your suggestions, also reviewing other applications :)
Thanks,
Makarand.
Comment #21
ajitsAwesome!
One last thing, the help text for the select list needs to be changed too. Use something like
However, this is not a blocker. So, RTBC from my side!
Time to get a review bonus and let a GIT admin look at this :-)
Comment #22
cmak commentedFixed description.
Comment #23
ajitsCool, one more thing which needs change. You will need to change the screenshot of the configuration screen "Default country code page.png" on the project page. It shows the screenshot of the textfield.
Comment #24
cmak commentedChanged screenshot and updated project page, Thanks.
Comment #25
cmak commentedComment #26
cmak commentedComment #27
cmak commentedComment #28
VikrantR commentedComment #29
mpdonadioAssigning to myself for next review, which will hopefully be tonight or tomorrow.
Comment #30
mpdonadioAutomated Review
Review of the 7.x-1.x branch (commit 1f050cb):
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. You have to get a review bonus to get a review from me.
Manual Review
Avoid markup in strings passed to t(), eg in country_specific_nodes_content_type().
Explicitly running cron from country_specific_nodes_content_type_submit() is probably a bad idea. Just let the cleanup happen when cron runs next. Same for country_specific_nodes_uninstall().
(+) In country_specific_nodes_node_load(), you should check for a permission and not a role.
I think some of your is_object($node) calls may be unneeded, but look at the docs again for hook_node_access as the first parameter can be a string representing the node type to check.
$node->hidden may be too generic; you may want to think of a better name to namespace this to your module.
Views support would be nice.
Not sure if a field is most appropriate here. A custom table that maps to the property you define may be better in the long run.
(+) You probably want a permission to bypass the hook_node_access() check.
The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.
Not seeing any show stoppers. Assigning to @er.pushpinderrana for a second look, if he has time.
If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.
This review uses the Project Application Review Template.
Comment #31
pushpinderchauhan commentedNo commit after `1f050cb`, so same Automated Review.
Manual Review
I gone through the whole code, didn't see anything major.
Inline comments and functions docs looks good to me.
Project page also looks good.
I tested module functionality and it worked as intended.
My only real comment would be to take out HTML from t() function. Inclusion of Views and Entity would be a huge enhancement in this module.
Looking at the git history https://www.drupal.org/node/2290579/commits, some commit message are fine but few are too short, you should provide a meaningful short summary what you changed. See https://www.drupal.org/node/52287
Nothing major jumped out at me, so...
Thanks for your contribution, Makarand Chavan!
I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!
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.
Thanks to the dedicated reviewer(s) as well.
Comment #32
ajitsAwesome!
Thanks MPD and Pushpinder!
Congrats Makarand!
Comment #33
cmak commentedHi,
Thanks MPD, Pushpinder, Ajit, Klausi and to all the members involved in the review. It has been a great learning.
I have already started working on Entity support and looking forward to Views support. I am now implementing the changes as suggested and will then publish a stable release. Thanks all and cheers :)