Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
1.2k views
in Q2A Core by

Hi, 

In the Admin settings, I've set the permission for "Viewing question pages:" to "Registered users". 

Individual question pages require people to log in. That woks just fine. However if a not logged in user browses to "/questions" or "/unanswered", they are able to see all the questions together with the users who asked them. I assume the same will be true for the tags page. 

I would need to be able to restrict the viewing to registered users only. I would also need to be able to restrict viewing of all the users to regiestered users only (already raised here: http://www.question2answer.org/qa/12457/how-can-disable-viewing-the-list-members-for-not-registered). 

Not sure if it is relevant, but I'm using single sign-on. 

Best regards, 

Vlad

Q2A version: 1.5.2

1 Answer

+2 votes
by

Hi, 

I managed to find a workaround by pasting the code below (slgthly adapted from qa-page-question.php) to the following files: qa-page-questions.php, qa-page-tags, qa-page-unanswered, qa-page.php (at the beginning of the function qa_get_request_content).

I know this is definitely not a clean solution, but it seems to be a good workaround for me now. 

$permiterror=qa_user_permit_error('permit_view_q_page');

 

if ( $permiterror && (qa_is_human_probably() || !qa_opt('allow_view_q_bots')) ) {
$qa_content=qa_content_prepare();
$topage=qa_q_request($questionid, $question['title']);
 
switch ($permiterror) {
case 'login':
$qa_content['error']=qa_insert_login_links(qa_lang_html('main/view_q_must_login'), $topage);
break;
 
case 'confirm':
$qa_content['error']=qa_insert_login_links(qa_lang_html('main/view_q_must_confirm'), $topage);
break;
 
default:
$qa_content['error']=qa_lang_html('users/no_permission');
break;
}
 
return $qa_content;
}
 
Another hack I did was to change the message that is displayed to make it relevant to other pages as well, by changing the following line in qa-lang-main.php
 
'view_q_must_login' => 'Please ^1log in^2 or ^3register^4 to view this page.',
by
This is the same problem I need to solve. I tried your solution but wasn't able to make it work. Admittedly, I'm not that technical so I may have implemented it incorrectly. Could you specify if it matters where the code is added in each of the files? (Line numbers would be amazing!)
...