Description

This module adds a "unpublish" button on comments based on permissions.
You'll se the button if:

  • You are the site administrator
  • You can admin comments
  • You've enabled the permission (defined by this module) unpublish own comment.

Module code information

Manual reviews of other projects

https://www.drupal.org/node/2290647#comment-8981807
https://www.drupal.org/node/2186013#comment-8981993
https://www.drupal.org/node/2303809#comment-8982057

Manual reviews of other projects after the "Reviewed & tested by the community" status

https://www.drupal.org/node/2308015#comment-8996387
https://www.drupal.org/node/2308975#comment-8996613
https://www.drupal.org/node/2203593#comment-8996751

Comments

PA robot’s picture

We 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.

coderider’s picture

Your git command is not in the correct format.

You cannot use a command in the format
username@git.drupal.org:sandbox/username/repo

It must be in the format
http://git.drupal.org/sandbox/username/repo

alvar0hurtad0’s picture

Issue summary: View changes

Thankyou @coderider it's done now.

keopx’s picture

Status: Needs review » Needs work

Please put pareview.sh link into this issue description: http://pareview.sh/pareview/httpgitdrupalorgsandboxalvar0hurtad02303353git

You've a message: You need to set a default branch 7.x-1.x http://drupal.org/node/1659588

alvar0hurtad0’s picture

Issue summary: View changes
Status: Needs work » Needs review

Thank you sensei (@keopx)

keopx’s picture

Please chech 3 other project manual reviews.

Check review bonus

keopx’s picture

Issue summary: View changes
gwprod’s picture

In unpublish_own_comment.module:
On line 17, permissions should generally be entirely lowercase, declarative and related to their title. 'unpublish own comment' would make sense.

The title and description could afford to be more verbose, such as:

(Unpublish Own Comment) and (Allows the user to unpublish comments they have made.)

I'm not sure what the purpose of this is:

/**
 * Implements hook_menu_alter().
 */
function unpublish_own_comment_menu_alter(&$items) {
  $items['node/%/unpublish_own_comment']['access callback'] = 'unpublish_own_comment_access';
  $items['node/%/unpublish_own_comment']['access arguments'] = array(1);
}
keopx’s picture

Status: Needs review » Needs work
alvar0hurtad0’s picture

Status: Needs work » Needs review

Thankyou @gwprod @keopx

:D

daniel.moberly’s picture

The words 'publish' and 'unpublish' should be wrapped as translatable here (lines 22 and 26):

  if ($comment->status) {
    $action = 'unpublish';
    $form['action']['#value'] = 0;
  }
  else {
    $action = 'publish';
    $form['action']['#value'] = 1;
  }

Similarly, you should probably make "available" and "unavailable" translatable as well on line 41:

  t(
      'Submitting this form will @action this comment, making it @visibility to users on the site.',
      array('@action' => $action, '@visibility' => ($comment->status ? 'unavailable' : 'available'))
    ),

Finally, this translation call on line 43 does not do anything as you are just passing a variable

t('@action', array('@action' => ucwords($action)))
alvar0hurtad0’s picture

Thankyou Daniel it's done

keopx’s picture

Status: Needs review » Needs work

Hi @alvar0hurtad0

If user is authenticated and this user has a "Unpublish Own Content" permission, this user don't see link to unpublish

When push unpublish, using user 1, take this error:

Notice: Undefined index: action in unpublish_own_comment_form_submit() (line 40 of /Proyectos/drupal7/sites/all/modules/custom/unpublish_own_comment/unpublish_own_comment.pages.inc).

I'm using clear drupal 7.29 installation

Please review it.

keopx’s picture

Hi,

I do a patch for this error:

If user is authenticated and this user has a "Unpublish Own Content" permission, this user don't see link to unpublish

Review second error ;)

alvar0hurtad0’s picture

Status: Needs work » Needs review

Thanyou so much @keopx. Your patch is applyed and pushed.

alvar0hurtad0’s picture

Issue summary: View changes
alvar0hurtad0’s picture

Issue summary: View changes
alvar0hurtad0’s picture

Issue summary: View changes

Added 3 manual reviews to the project description.

keopx’s picture

Hi Alvar0Hurtad0.

You need add manually tag "PAReview: review bonus" into the main issue ;)

Good work!

miroslavbanov’s picture

Manual review

Application contains a repository and project page link.

Project is not a duplication.

I did find a patch from two years ago to add this functionality to Comment goodness. Without the patch, Comment goodness has functionality to allow user to delete user's own comment. But it also makes sense to have this module separate from anything else. The module name is very indicative of what it does and will certainly be easy to find.

Repository contains code.

Repository has a single version-specific branch.

No security issues.

Licensing is good.

No third-party code.

Readme file contains typos.

You have a README.txt, and it's detailed enough, but I saw a few typos and bad wordings:
You'll se the button if -> You'll see the button if
You can admin comments -> You can administer comments
This module is very useful if you need some role must be able to unpublish own
comments but not edit or delete then ->
This module is very useful if you need some role that must be able to unpublish own
comments but not edit or delete them

PAReview shows no problems.

Using Drupal's API correctly.

Doesn't actually work

This looks to be a mistake in unpublish_own_comment_form_submit()

$comment->status = $form_state['values']['action'];

Notice: Undefined index: action in unpublish_own_comment_form_submit() (line 40 of ../unpublish_own_comment.pages.inc).
At this point all must be validated, and access checks should have been done, and you can just set status directly:

$comment->status = COMMENT_NOT_PUBLISHED;

Confusing code in access callback.

unpublish_own_comment_access() has 5 returns. I would restructure it
To initialize $access on top: $access = FALSE
To return access at the bottom: return $access;
To have nested if statements in between:

  $access = FALSE;

  if ($node && $comment && $comment->status... ) {

    if (user_access('... ) {
      $access = TRUE;
    }

  }

  return $access;

Also, it looks to me like you don't sufficiently check for comment existing and being published. I think comment must absolutely exist and be published in order for the access check to return TRUE, regardless of permissions.

Additional suggestion

With this module, you allow the user to unpublish the comment, even if comments are threaded and there is already an answer to that comment. This would make the thread incoherent, and you should maybe consider this. Comment goodness allows to delete his own comment, but only if there are no answers to that comment already.

miroslavbanov’s picture

Status: Needs review » Needs work
alvar0hurtad0’s picture

Status: Needs work » Needs review

Thanyou so much @MiroslavBanov for your review and your comments.

I've change the README.txt (I'm very sorry about my awfull english Im studing hard to improve it).
I've refactor the unpublish_own_comment_access now it's much more clear.

alvar0hurtad0’s picture

Issue tags: +PAreview: review bonus

Ok,

It's time for braves.

:D

ratanphp’s picture

@alvar0hurtad0
Your module looks good to me as well. As I reviewed your code and also installed on my local machine.
Additional suggestion
Please add hook_help function to your .module file.

alvar0hurtad0’s picture

Thankyou @ratanphp for your review and your suggestion.

I've taken your advice and the module now implements the hook_help.

keopx’s picture

Status: Needs review » Reviewed & tested by the community

Works fine!

alvar0hurtad0’s picture

Issue summary: View changes

Checking some projects ....

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

Assigning to myself for next review.

alvar0hurtad0’s picture

Ehhhhh

<3 U guy

Thank you so much

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Reviewed & tested by the community » Needs work
Issue tags: +PAreview: security

Automated Review

Review of the 7.x-1.x branch (commit 298135f):

  • No automated test cases were found, did you consider writing Simpletests or PHPUnit tests? This is not a requirement but encouraged for professional software development.

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

Individual user account
Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: Does not cause module duplication and fragmentation.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Follows the licensing requirements
3rd party code
Yes: Follows the guidelines for 3rd party code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation and the README Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity (but barely).
Secure code

No. If "no", list security issues identified.

You have a node access bypass problem. If a user has commented on a node, and then for some reason loses read access to the node afterwards, they can
still directly browse to the url defined by your hook_menu and unpublish the comment. You also need to add a
node_access('view', $node) to unpublish_own_comment_access() to make sure that the user has read access to the node on which
they wish to unpublish the comment. Note that the autoloader that gives you the $node doesn't do the check; it is the router
item's responsibility to do this. I also think that you need to check whether comments on the node are hidden or not; users
shouldn't be able to unpublish comments on a node where they are hidden.

Coding style & Drupal API usage

The actual permission name in unpublish_own_comment_permission() is a little misleading. It should be more tied to the action, and not what you can see. I would just use 'unpublish own comment'.

In unpublish_own_comment_comment_view(), use theCOMMENT_PUBLISHED instead of the values. See https://api.drupal.org/api/drupal/modules!comment!comment.module/7

In unpublish_own_comment_comment_view(), do you need an additional class to identify this link? Check the other links to see what they have.

(+) unpublish_own_comment_access() needs to check whether the comment is valid or not. The normal checks are isset($node->nid) and isset($comment->cid).

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.

alvar0hurtad0’s picture

Thank you si mich for tour revision.

I go to the work.

:)

alvar0hurtad0’s picture

Status: Needs work » Needs review

Ok these are the changed I made:

You have a node access bypass problem. If a user has commented on a node, and then for some reason loses read access to the node afterwards, they can
still directly browse to the url defined by your hook_menu and unpublish the comment. You also need to add a
node_access('view', $node) to unpublish_own_comment_access() to make sure that the user has read access to the node on which
they wish to unpublish the comment. Note that the autoloader that gives you the $node doesn't do the check; it is the router
item's responsibility to do this.

this is the new unpublish_own_comment_access():

function unpublish_own_comment_access($node, $comment = NULL) {
  $access = FALSE;
  if (isset($node->nid) && isset($comment->cid) && node_access('view', $node)) {
    global $user;

    if (user_access('administer comments')) {
      $access = TRUE;
    }

    if ($user->uid == $comment->uid) {
      $access = user_access('unpublish own comment');
    }
  }
  return $access;
}
I also think that you need to check whether comments on the node are hidden or not; users shouldn't be able to unpublish comments on a node where they are hidden.

I'm not sure about this point, not sure if it's about the current display in a near future I would like to add the compatibility with views and the view type "fields" so it can be a problem.

The actual permission name in unpublish_own_comment_permission() is a little misleading. It should be more tied to the action, and not what you can see. I would just use 'unpublish own comment'.

I Agree, :D

$perms['unpublish own comment'] = array(
....
    if ($user->uid == $comment->uid) {
      $access = user_access('unpublish own comment');
    }
In unpublish_own_comment_comment_view(), use theCOMMENT_PUBLISHED instead of the values.

:D
if (($comment->status == COMMENT_PUBLISHED) && unpublish_own_comment_access($node, $comment)) {

In unpublish_own_comment_comment_view(), do you need an additional class to identify this link? Check the other links to see what they have.

I think other links are not much different than this one:

<ul class="links inline"><li class="comment-delete first"><a href="/comment/7/delete">delete</a></li>
<li class="comment-edit"><a href="/comment/7/edit">edit</a></li>
<li class="comment-reply"><a href="/comment/reply/1/7">reply</a></li>
<li class="unpublish_own_comment last"><a href="/node/1/unpublish_own_comment/7?destination=node/1">unpublish</a></li>
</ul>
(+) unpublish_own_comment_access() needs to check whether the comment is valid or not. The normal checks are isset($node->nid) and isset($comment->cid).

it's on the first code block of the comment.

Than you so much again for your time.

miroslavbanov’s picture

Status: Needs review » Reviewed & tested by the community

@alvar0hurtad0

The unpublish_own_comment_access() access callback should check $comment->status === COMMENT_PUBLISHED. It is the only problem from my comment #20 that you didn't address. Everything else looks good. I will go ahead and set this one as RTBC.

alvar0hurtad0’s picture

thank you @MiroslavBanov for your review, I've also added your suggestion on the access callback.

:D

klausi’s picture

Status: Reviewed & tested by the community » Fixed

Review of the 7.x-1.x branch (commit 5e24b42):

  • No automated test cases were found, did you consider writing Simpletests or PHPUnit tests? This is not a requirement but encouraged for professional software development.

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:

  1. project page misses a screenshot and is a bit short, see https://www.drupal.org/node/997024
  2. unpublish_own_comment_access(): why is the $comment parameter optional with a NULL default value? You will always need it, otherwise the function does not make sense?
  3. unpublish_own_comment_access(): I don't think you need the $access variable. Just immediately return TRUE when you check the permission and return FALSE as default in the end. I think this has been suggested by another reviewer, but having multiple return statements is perfectly fine in a function.
  4. We usually don't use @author tags in Drupal since over time many people will contribute to a project.
  5. unpublish_own_comment_comment_view(): the second if() is not necessary, just add to the comment content in the first if() body?

But that are not critical application blockers, so ...

Thanks for your contribution, alvar0hurtad0!

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.

alvar0hurtad0’s picture

Thank YOU all for tour reviews and for spend tour time supporting the community.

I've learn a bunch with the review process and i'll try help reviewing other projects.

Thank you again.

:D

Status: Fixed » Closed (fixed)

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