Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: on forum page, tell user they have to log in to post #6040

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions html/inc/forum.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1271,12 +1271,16 @@ function is_admin($user) {
return false;
}

// return
// 'yes' if logged in and can post (show New thread button)
// 'login' if could post if logged in (show login to post msg)
// 'no' if can't post (don't show anythin)
//
function user_can_create_thread($user, $forum) {
if (!$user) return false;
if ($forum->is_dev_blog && !is_admin($user)) {
return false;
if ($forum->is_dev_blog) {
return is_admin($user)?'yes':'no';
}
return true;
return $user ?'yes':'login';
}

function check_post_access($user, $forum) {
Expand Down
20 changes: 12 additions & 8 deletions html/user/forum_forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,19 @@ function forum_page($forum, $user, $msg=null) {
<td colspan=2>
';

if ($user) {
if (user_can_create_thread($user, $forum)) {
show_button(
"forum_post.php?id=$forum->id",
tra("New thread"),
tra("Add a new thread to this forum")
);
}
switch (user_can_create_thread($user, $forum)) {
case 'yes':
show_button(
"forum_post.php?id=$forum->id", tra("New thread"),
tra("Add a new thread to this forum")
);
break;
case 'login':
echo "To add a thread, you must <a href=login_form.php>log in</a>.";
break;
}

if ($user) {
if (is_subscribed(-$forum->id, $subs)) {
BoincNotify::delete_aux(sprintf(
'userid=%d and type=%d and opaque=%d',
Expand Down
2 changes: 1 addition & 1 deletion html/user/forum_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
error_page("Forums are disabled");
}

if (!user_can_create_thread($logged_in_user, $forum)) {
if (user_can_create_thread($logged_in_user, $forum)=='no') {
error_page(tra("Only project admins may create a thread here. However, you may reply to existing threads."));
}
check_post_access($logged_in_user, $forum);
Expand Down
Loading