Download & Extend

Unauthorized users see extra buttons on /forum

Project:Drupal core
Version:8.x-dev
Component:forum.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Steps to reproduce:

Drupal 8

As Admin user

  • Install Drupal 8 Using the Standard profile
  • Enable "Forum" module
  • Create "Test" user with "Authenticated" role

As anonymous user

  • Navigate to /forum
  • There is a button that says "+" is clickable and sends you to the home page
  • Next to that is a "Log in" link that takes you to the login page

D8Anonymous

As Test user

  • Login as "Test" user
  • Navigate to /forum
  • There is a button that says "+ You are not allowed to post new content in the forum" is clickable and sends you to the home page

D8Authenticated

Drupal 7

As Admin user

  • Install Drupal 7 Using the Standard profile
  • Enable "Forum" module
  • Create "Test" user with "Authenticated" role

As anonymous user

  • Navigate to /forum
  • There is a "+" next to a "Log in" link that takes you to the login page

D7Anonymous

As Test user

  • Login as "Test" user
  • Navigate to /forum
  • There is no button. Just text as expected.

D7Authenticated

One other note is that the text diplayed to anonymous users has the class "action-links", so it's indented etc.
D7ClassActionLinks

AttachmentSizeStatusTest resultOperations
D8Anonymous.png13.68 KBIgnoredNoneNone
D8Authenticated.png13.96 KBIgnoredNoneNone
D7Anonymous.png12.81 KBIgnoredNoneNone
D7Authenticated.png13.19 KBIgnoredNoneNone
D7ClassActionLinks.png35.21 KBIgnoredNoneNone

Comments

#1

Thanks @bjlewis2!

So probably these messages should simply not be displayed inside the actions link markup. We can't backport anything here because it would be a UI change, but the only real oddities are in D8 in any case.

This might also have been affected by #1167350: Action links were ignored .

#2

Status:active» postponed

I've attached a patch to #1167350: Action links were ignored , it will fix this problem

#3

Status:postponed» active

Unpostponing, since the markup being output here seems to be improper usage of action links.

We probably need to move those "messages"/notices into the page markup.

#4

Status:active» needs review

I picked this up from http://core.drupalofficehours.org/task/1238 and have made a first attempt. This simply moves the access checking into the template. I have no idea if this is the best/correct/etc. way of doing it so welcome reviews!

AttachmentSizeStatusTest resultOperations
forum-move-access-error-into-template-1853072-4.patch4.26 KBIdlePASSED: [[SimpleTest]]: [MySQL] 48,896 pass(es).View details | Re-test

#5

Action links broken the UI pattern because it's called "Action link" only. I still think display the text is needed in this case.

Patch seems need more better access handle.

#6

Here's another version which turns the "Log in" into an action (and fixes the link code) so only moves the not authorised message to the template.

AttachmentSizeStatusTest resultOperations
forum-move-access-error-into-template-1853072-6.patch4.09 KBIdlePASSED: [[SimpleTest]]: [MySQL] 48,900 pass(es).View details | Re-test

#7

@xjm in core office hours recommended I post screenshots and code snippets, so here we go. This is for the patch in #6 which is a more sensible patch than #4:

Anonymous, no access

D8-Forum-Anonymous-no-access-link.png

<h1 class="title" id="page-title">Forums</h1>
<div class="tabs"></div>
  <ul class="action-links">
    <li><a href="/user/login?destination=forum" class="button add">Log in to post new content in the forum.</a></li>
  </ul>
<div  class="region region-content">...

Authenticated, no access

D8-Forum-Authenticated-no-access-message.png

<div class="content">
  <div id="forum">
    You are not allowed to post new content in the forum.
    <table id="forum-0">
    <thead>
      <tr>...

Posting this makes me realise there's no markup on the error message, however I'm presuming all this still needs changing to twig at some point?

AttachmentSizeStatusTest resultOperations
D8-Forum-Anonymous-no-access-link.png16.54 KBIgnoredNoneNone
D8-Forum-Authenticated-no-access-message.png13.87 KBIgnoredNoneNone

#8

Status:needs review» reviewed & tested by the community

I applied the patch in #6, created the Test user and tested as anonymous as well as logged in as the Test user and the results were the same as indicated in #7.

#9

Note: Applying this patch causes the patch in http://drupal.org/node/953214#comment-6693922 to not apply.

#10

Status:reviewed & tested by the community» needs review

I've taken a first go at merging patches #1853072-6: Unauthorized users see extra buttons on /forum and #953214-50: shows 'login to post new content in the forum' even when it's not true. I've attached an interdiff file but first time created one so not sure if it worked ok.

If authenticated user has access to post new forum content and visitors can register on the site the action button now redirects to /user and looks like this:
forum-login-register-post.png

...and if Administrator only registrations then it redirects to /user/login and looks like this:
forum-login-post.png

The buttons are still somewhat confusing as you could have comments on forum topics where you can post, this just checks for posting of topics.

AttachmentSizeStatusTest resultOperations
forum-login-register-post.png27.94 KBIgnoredNoneNone
forum-login-post.png26.01 KBIgnoredNoneNone
forum_access_messages-1853072-10-953214-52.patch10.33 KBIdleFAILED: [[SimpleTest]]: [MySQL] 49,256 pass(es), 3 fail(s), and 0 exception(s).View details | Re-test
forum_access_messages-1853072-10-953214-52-inter-diff.txt5.56 KBIgnoredNoneNone

#11

Status:needs review» needs work

The last submitted patch, forum_access_messages-1853072-10-953214-52.patch, failed testing.

#12

The result of the discussion in #1167350: Action links were ignored was that Forum module should not use hook_menu_local_tasks_alter() to expose/show these links in the first place, because these are not action links.

So what we want to do here is to move that code to an entirely different spot, but essentially try to retain the approximate position.

The most simple approach would be to move the code into an own helper function (i.e., renaming the current hook implementation function), make it accept a $build render array, and make it add a container that contains the respective link or markup, depending on the configuration settings, and apply a very low negative weight to the container. (i.e., essentially doing what the current action links are doing, just without action links.)

function forum_login_box(&$build) {
  $build['forum_login'] = array(
    '#type' => 'container',
    '#weight' => -100,
  );
  $build['forum_login']['link'] = array(
    '#type' => 'link',
    '#title' => t('Log in or register to post new content in the forum'),
    '#href' => 'user',
    '#options' => drupal_get_destination(),
  );
}

Then, inject calls to this helper method from every forum page callback that needs it.

That would be the most simple way. However, I want to amend that this messaging is not really part of the actual page callback content (which is probably more or less the reason for why it has been moved into hook_menu_local_tasks_alter()).

Therefore, an alternative approach would be to turn this container into a real and new block, which just outputs the necessary link/content, and make forum_install() enable and position that block into the 'content' region with a low weight. As a result, site builders and themers will be able to move this messaging block very easily to a different place/region (e.g., into a sidebar).

Overall, the block approach would make more sense to me.

#13

@sun thanks for the info, I've had a go at moving it into a block, patch attached with code from #953214-50: shows 'login to post new content in the forum' even when it's not true as it uses a function

Block as it appears in block admin after installing forum module:

forum-messages-block-admin.png

Block content when not logged in and auth user does not have permission to post:

forum-no-message.png

Block content when not logged in, auth user can post, admin-only registration:

forum-login.png

<div id="block-forum-messages-block"  class="block block-forum" role="navigation">
  <div class="content">
    <a href="/user/login?destination=forum">Log in</a> to post new content in the forum.
  </div>
</div>

Block content when not logged in, auth user can post, visitors can register:

forum-login-register.png

<div id="block-forum-messages-block"  class="block block-forum" role="navigation">
  <div class="content">
    <a href="/user/login?destination=forum">Log in</a> or <a href="/user/register?destination=forum">register</a> to post new content in the forum.
  </div>
</div>

Block content when have permission to post:

forum-add-new.png

<div id="block-forum-messages-block"  class="block block-forum" role="navigation">
  <div class="content">
    <a href="/node/add/forum/0">Add new Forum topic</a>
  </div>
</div>

Block content when have permission to post, with redirect to forum being viewed:

forum-add-new-general-discussion.png

<div id="block-forum-messages-block"  class="block block-forum" role="navigation">
  <div class="content">
    <a href="/node/add/forum/1">Add new Forum topic</a>
  </div>
</div>

Block content when logged in and no permission to post:

forum-you-are-not-allowed.png

<div id="block-forum-messages-block"  class="block block-forum" role="navigation">
  <div class="content">
    You are not allowed to post new content in the forum.
  </div>
</div>
AttachmentSizeStatusTest resultOperations
forum-messages-block-admin.png36.24 KBIgnoredNoneNone
forum-no-message.png14.91 KBIgnoredNoneNone
forum-login.png21.65 KBIgnoredNoneNone
forum-login-register.png23.3 KBIgnoredNoneNone
forum-add-new.png19.26 KBIgnoredNoneNone
forum-you-are-not-allowed.png23.28 KBIgnoredNoneNone
forum_access_messages-1853072-13-953214-54.patch13.68 KBIdleFAILED: [[SimpleTest]]: [MySQL] 49,203 pass(es), 19 fail(s), and 0 exception(s).View details | Re-test
forum-add-new-general-discussion.png21.24 KBIgnoredNoneNone

#14

Status:needs work» needs review

Fixing white space issues in patch and status change to needs review

AttachmentSizeStatusTest resultOperations
forum_access_messages-1853072-14-953214-54.patch13.68 KBIdleFAILED: [[SimpleTest]]: [MySQL] 49,166 pass(es), 18 fail(s), and 0 exception(s).View details | Re-test

#15

Status:needs review» needs work

The last submitted patch, forum_access_messages-1853072-14-953214-54.patch, failed testing.

#16

Status:needs work» needs review

Had introduced dependency on block module which also affected other tests. Re-trying.

AttachmentSizeStatusTest resultOperations
forum_access_messages-1853072-16.patch15.31 KBIdlePASSED: [[SimpleTest]]: [MySQL] 49,380 pass(es).View details | Re-test

#17

Missed a file. I'll get the grip of this soon, many appo logies ;)

AttachmentSizeStatusTest resultOperations
forum_access_messages-1853072-17.patch19.94 KBIdlePASSED: [[SimpleTest]]: [MySQL] 49,398 pass(es).View details | Re-test

#18

So *that's* why I see those "Fixing new line issue" posts.

AttachmentSizeStatusTest resultOperations
forum_access_messages-1853072-18.patch19.91 KBIdlePASSED: [[SimpleTest]]: [MySQL] 49,418 pass(es).View details | Re-test

#19

Not sure I like the block approach, not sure why though.
I think it has to do with making block a dependency for forum, but I can't put my finger on it.

#20

I totally agree, I was just following orders ;)

Do you have any alternative suggestions? I know what mine would be, but guess we'd better keep forum for the moment :D

#21

Well, my longer term goal would be a header area in a view, but we need some other things resolved before we can do that eg #1867642: Change notice: Expose forum tables to views.
But I am struggling to come up with something that doesn't feel wrong, after re-reading sun's comments I guess block is the way to go, given most other content is moving to a block (eg site name etc).

#22

Me too which is why I just did the patch, sounds like best idea is to leave it for a while to see how other things develop. If you want me to look at anything in particular feel free to use my contact form or mail steve@purkiss.com and I'll take a look, quite enjoyed getting my teeth into this even though it did give me a little bit of a shock when I realised it broke lots of tests due to the block dependency - all good learning though!

#23

Someone just mentioned on twitter to me that forums should be entities - done a bit of searching but didn't find anything - is this in the planning at all? Would it be worth creating a new issue? Saw it discussed on Advanced Forum but not for Forum.

#24

@stevepurkiss: Forum containers + forums are taxonomy vocabularies, forum posts are nodes. Both vocabularies and nodes are entities in D8, so that's done already. However, that's off-topic here. :)

#25

@sun ok cool thanks - just trying to get my head around future developments as it seems (I may be wrong) that I did a lot of work that won't actually be used, so just want to make sure I spend my "spare" time wisely!

thanks,

nobody click here