Skip to content

Commit b2c2eaa

Browse files
authored
Merge pull request #6962 from BOINC/dpa_forum12
web: require credit to post outside Help categories
2 parents 06d3661 + 673b3e7 commit b2c2eaa

5 files changed

Lines changed: 63 additions & 37 deletions

File tree

html/inc/delete_account.inc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
// You should have received a copy of the GNU Lesser General Public License
1717
// along with BOINC. If not, see <https://www.gnu.org/licenses/>.
1818

19+
// functions to remove accounts
20+
// wipe_account(): delete account and all related DB records
21+
// obfuscate_account(): change name and email of account; delete forum items
22+
// delete_account(): call one of these (or project-supplied func)
23+
// based on config setting
24+
//
25+
// NOTE: this is way too complex. Just use the wipe option.
26+
1927
require_once("../inc/common_defs.inc");
2028
require_once("../inc/util.inc");
2129
require_once("../inc/user.inc");
@@ -27,8 +35,7 @@ require_once("../inc/submit_util.inc");
2735
require_once("../project/project.inc");
2836

2937
// Constants for different methods of deleting accounts
30-
// These correspond to the value used in the config.xml
31-
// field of <enable_delete_account/>
38+
// Selected in the <enable_delete_account/> element in config.xml
3239
//
3340
define("DELETE_ACCOUNT_METHOD_OBFUSCATE", 1);
3441
define("DELETE_ACCOUNT_METHOD_WIPE", 2);

html/inc/forum.inc

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ define('ST_NEW', 'New member');
6262

6363
if (!defined('MAXIMUM_EDIT_TIME')) {
6464
define('MAXIMUM_EDIT_TIME', 3600);
65-
// allow edits of forums posts up till one hour after posting.
65+
// allow edits of forums posts up to one hour after posting.
66+
}
67+
68+
if (!defined('NEED_CREDIT_TO_POST_EXCEPT_HELP')) {
69+
define('NEED_CREDIT_TO_POST_EXCEPT_HELP', true);
6670
}
6771

6872
define('MAX_FORUM_LOGGING_TIME', 2419200); //3600*24*28 - 28 days
@@ -1275,20 +1279,24 @@ function is_admin($user) {
12751279
return false;
12761280
}
12771281

1278-
// return
1279-
// 'yes' if logged in and can post (show New thread button)
1280-
// 'login' if could post if logged in (show login to post msg)
1281-
// 'no' if can't post (don't show anythin)
1282+
// should we show a 'new thread' button in a forum page?
1283+
// Note: we show the button even if in some cases
1284+
// an attempt to post will fail (see below)
12821285
//
1283-
function user_can_create_thread($user, $forum) {
1286+
function show_post_button($user, $forum) {
12841287
if ($forum->is_dev_blog) {
1285-
return is_admin($user)?'yes':'no';
1288+
return is_admin($user);
12861289
}
1287-
return $user ?'yes':'login';
1290+
return true;
12881291
}
12891292

1293+
// If the user is not allowed to post to the forum, show an error page.
1294+
//
12901295
function check_post_access($user, $forum) {
12911296
if (is_admin($user)) return;
1297+
if ($forum->is_dev_blog) {
1298+
error_page("Can't post to News");
1299+
}
12921300

12931301
switch ($forum->parent_type) {
12941302
case 0:
@@ -1306,34 +1314,49 @@ function check_post_access($user, $forum) {
13061314
break;
13071315
}
13081316

1309-
// If user haven't got enough credit (according to forum regulations)
1310-
// We do not tell the (ab)user how much this is -
1317+
// check if user has enough credit according to forum settings.
1318+
// We don't tell the user how much this is -
13111319
// no need to make it easy for them to break the system.
13121320
//
1313-
if ($user->total_credit<$forum->post_min_total_credit || $user->expavg_credit<$forum->post_min_expavg_credit) {
1314-
error_page(tra("To create a new thread in %1 you must have a certain level of average credit. This is to protect against abuse of the system.", $forum->title));
1321+
if ($user->total_credit<$forum->post_min_total_credit
1322+
|| $user->expavg_credit<$forum->post_min_expavg_credit
1323+
) {
1324+
error_page(tra("To create a thread you must have computing credit."));
1325+
}
1326+
1327+
if (NEED_CREDIT_TO_POST_EXCEPT_HELP) {
1328+
if ($user->total_credit == 0) {
1329+
$category = BoincCategory::lookup_id($forum->category);
1330+
if (!$category->is_helpdesk) {
1331+
error_page(
1332+
tra("To create a thread you must have computing credit.")
1333+
);
1334+
}
1335+
}
13151336
}
13161337

13171338
// If the user is posting faster than forum regulations allow
13181339
// Tell the user to wait a while before creating any more posts
13191340
//
1320-
if (time()-$user->prefs->last_post <$forum->post_min_interval) {
1321-
error_page(tra("You cannot create threads right now. Please wait before trying again. This is to protect against abuse of the system."));
1341+
if (time() - $user->prefs->last_post < $forum->post_min_interval) {
1342+
error_page(
1343+
tra(
1344+
"You can't create a thread right now. Please try again later."
1345+
)
1346+
);
13221347
}
13231348
}
13241349

1350+
// if the user is not allowed to reply to threads in the forum,
1351+
// show an error page
1352+
//
13251353
function check_reply_access($user, $forum, $thread) {
13261354
if ($thread->locked && !is_moderator($user, $forum)) {
1327-
error_page(
1328-
tra("This thread is locked. Only forum moderators and administrators are allowed to post there.")
1329-
);
1355+
error_page(tra("This thread is locked."));
13301356
}
13311357
if ($thread->hidden) {
1332-
error_page(
1333-
tra("Can't post to a hidden thread.")
1334-
);
1358+
error_page(tra("Can't post to a hidden thread."));
13351359
}
1336-
13371360
check_post_access($user, $forum);
13381361
}
13391362

html/ops/delete_user.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
if (is_numeric($argv[1])) {
3131
$user = BoincUser::lookup_id((int) $argv[1]);
3232
if (!$user) die("no such user\n");
33-
$retval = delete_account($user);
33+
$retval = wipe_account($user);
3434
if ($retval) {
3535
echo "Failed to delete user: $retval\n";
3636
} else {
@@ -39,7 +39,7 @@
3939
} else {
4040
$users = BoincUser::enum(sprintf("name='%s'", $argv[1]));
4141
foreach ($users as $user) {
42-
$retval = delete_account($user);
42+
$retval = wipe_account($user);
4343
if ($retval) {
4444
echo "Failed to delete user: $retval\n";
4545
} else {

html/user/forum_forum.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,15 @@ function forum_page($forum, $user, $msg=null) {
9797
<td colspan=2>
9898
';
9999

100-
switch (user_can_create_thread($user, $forum)) {
101-
case 'yes':
102-
show_button(
103-
"forum_post.php?id=$forum->id", tra("New thread"),
104-
tra("Add a new thread to this forum")
105-
);
106-
break;
107-
case 'login':
100+
if ($user) {
101+
if (show_post_button($user, $forum)) {
102+
show_button(
103+
"forum_post.php?id=$forum->id", tra("New thread"),
104+
tra("Add a new thread to this forum")
105+
);
106+
}
107+
} else {
108108
echo "To add a thread, you must <a href=login_form.php>log in</a>.";
109-
break;
110109
}
111110

112111
if ($user) {

html/user/forum_post.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
error_page("Forums are disabled");
4545
}
4646

47-
if (user_can_create_thread($logged_in_user, $forum)=='no') {
48-
error_page(tra("Only project admins may create a thread here. However, you may reply to existing threads."));
49-
}
5047
check_post_access($logged_in_user, $forum);
5148

5249
$title = post_str("title", true);

0 commit comments

Comments
 (0)