staff message add permission

This commit is contained in:
xiaomlove
2022-08-22 21:07:06 +08:00
parent f55fef594c
commit 4b30804121
11 changed files with 219 additions and 59 deletions

View File

@@ -2693,18 +2693,28 @@ else {
$totalreports = get_row_count("reports");
$Cache->cache_value('staff_report_count', $totalreports, 900);
}
$totalsm = $Cache->get_value('staff_message_count');
if ($totalsm == ""){
$totalsm = get_row_count("staffmessages");
$Cache->cache_value('staff_message_count', $totalsm, 900);
}
$totalcheaters = $Cache->get_value('staff_cheater_count');
if ($totalcheaters == ""){
$totalcheaters = get_row_count("cheaters");
$Cache->cache_value('staff_cheater_count', $totalcheaters, 900);
}
print("<a href=\"cheaterbox.php\"><img class=\"cheaterbox\" alt=\"cheaterbox\" title=\"".$lang_functions['title_cheaterbox']."\" src=\"pic/trans.gif\" /> </a>".$totalcheaters." <a href=\"reports.php\"><img class=\"reportbox\" alt=\"reportbox\" title=\"".$lang_functions['title_reportbox']."\" src=\"pic/trans.gif\" /> </a>".$totalreports." <a href=\"staffbox.php\"><img class=\"staffbox\" alt=\"staffbox\" title=\"".$lang_functions['title_staffbox']."\" src=\"pic/trans.gif\" /> </a>".$totalsm." ");
print(
"<a href=\"cheaterbox.php\"><img class=\"cheaterbox\" alt=\"cheaterbox\" title=\"".$lang_functions['title_cheaterbox']."\" src=\"pic/trans.gif\" /> </a>".$totalcheaters
." <a href=\"reports.php\"><img class=\"reportbox\" alt=\"reportbox\" title=\"".$lang_functions['title_reportbox']."\" src=\"pic/trans.gif\" /> </a>".$totalreports
);
}
// $cacheKey = "staff_message_count_" . $CURUSER['id'];
// $totalsm = $Cache->get_value($cacheKey);
$totalsm = \App\Repositories\MessageRepository::getStaffMessageCountCache($CURUSER['id'], 'total');
if ($totalsm == ""){
$totalsm = \App\Repositories\MessageRepository::countStaffMessage($CURUSER['id']);
// $Cache->cache_value($cacheKey, $totalsm, 900);
\App\Repositories\MessageRepository::updateStaffMessageCountCache($CURUSER['id'], 'total', $totalsm);
}
if ($totalsm > 0) {
print (" <a href=\"staffbox.php\"><img class=\"staffbox\" alt=\"staffbox\" title=\"".$lang_functions['title_staffbox']."\" src=\"pic/trans.gif\" /> </a>".$totalsm." ");
}
print("<a href=\"messages.php\">".$inboxpic."</a> ".($messages ? $messages." (".$unread.$lang_functions['text_message_new'].")" : "0"));
print(" <a href=\"messages.php?action=viewmailbox&amp;box=-1\"><img class=\"sentbox\" alt=\"sentbox\" title=\"".$lang_functions['title_sentbox']."\" src=\"pic/trans.gif\" /></a> ".($outmessages ? $outmessages : "0"));
@@ -2795,6 +2805,21 @@ if ($msgalert)
}
}
//Staff message, not only staff member
// $cacheKey = 'staff_new_message_count_' . $CURUSER['id'];
// $nummessages = $Cache->get_value($cacheKey);
$nummessages = \App\Repositories\MessageRepository::getStaffMessageCountCache($CURUSER['id'], 'new');
if ($nummessages == ""){
$nummessages = \App\Repositories\MessageRepository::countStaffMessage($CURUSER['id'], 0);
// $Cache->cache_value($cacheKey, $nummessages, 900);
\App\Repositories\MessageRepository::updateStaffMessageCountCache($CURUSER['id'], 'new', $nummessages);
}
if ($nummessages > 0) {
$text = $lang_functions['text_there_is'].is_or_are($nummessages).$nummessages.$lang_functions['text_new_staff_message'] . add_s($nummessages);
msgalert("staffbox.php",$text, "blue");
}
if (user_can('staffmem'))
{
//torrent approval
@@ -2827,15 +2852,7 @@ if ($msgalert)
$text = $lang_functions['text_there_is'].is_or_are($numreports).$numreports.$lang_functions['text_new_report'] .add_s($numreports);
msgalert("reports.php",$text, "blue");
}
$nummessages = $Cache->get_value('staff_new_message_count');
if ($nummessages == ""){
$nummessages = get_row_count("staffmessages","WHERE answered='no'");
$Cache->cache_value('staff_new_message_count', $nummessages, 900);
}
if ($nummessages > 0) {
$text = $lang_functions['text_there_is'].is_or_are($nummessages).$nummessages.$lang_functions['text_new_staff_message'] . add_s($nummessages);
msgalert("staffbox.php",$text, "blue");
}
$numcheaters = $Cache->get_value('staff_new_cheater_count');
if ($numcheaters == ""){
$numcheaters = get_row_count("cheaters","WHERE dealtwith=0");

View File

@@ -1,7 +1,5 @@
<?php
use App\Models\User;
function get_global_sp_state()
{
static $global_promotion_state;
@@ -892,7 +890,10 @@ function getDataTraffic(array $torrent, array $queries, array $user, $peer, $sna
function clear_user_cache($uid, $passkey = '')
{
do_log("uid: $uid, passkey: $passkey");
\Nexus\Database\NexusDB::cache_del("user_{$uid}_content");
\Nexus\Database\NexusDB::cache_del("user_{$uid}_permissions");
\Nexus\Database\NexusDB::cache_del("user_{$uid}_roles");
if ($passkey) {
\Nexus\Database\NexusDB::cache_del('user_passkey_'.$passkey.'_content');
}
@@ -904,36 +905,47 @@ function clear_setting_cache()
\Nexus\Database\NexusDB::cache_del('nexus_settings_in_nexus');
}
function clear_staff_message_cache()
{
do_log("clear_staff_message_cache");
\App\Repositories\MessageRepository::updateStaffMessageCountCache(false);
}
function user_can($permission, $fail = false, $uid = 0): bool
{
$log = "permission: $permission, fail: $fail, user: $uid";
static $userCanCached = [];
if ($uid == 0) {
$uid = get_user_id();
$log .= ", set current uid: $uid";
}
if ($uid <= 0) {
do_log("$log, no uid, false");
return false;
}
if (!$fail && isset($userCanCached[$permission][$uid])) {
return $userCanCached[$permission][$uid];
}
$userInfo = get_user_row($uid);
$log = "permission: $permission, user: $uid, userClass: {$userInfo['class']}";
if ($userInfo['class'] == User::CLASS_STAFF_LEADER) {
$log .= ", userClass: " . $userInfo['class'];
if ($userInfo['class'] == \App\Models\User::CLASS_STAFF_LEADER) {
do_log("$log, CLASS_STAFF_LEADER, true");
$userCanCached[$permission][$uid] = true;
return true;
}
$result = apply_filter('nexus_user_can', null, $permission, $uid);
$requireClass = get_setting("authority.$permission");
if (!is_bool($result)) {
$result = is_numeric($requireClass) && $requireClass >= 0 && $requireClass < $userInfo['class'];
$log .= ", requireClass: $requireClass, result: $result";
} else {
$log .= ", get result: $result from filter nexus_user_can";
}
$userAllPermissions = \App\Repositories\ToolRepository::listUserAllPermissions($uid);
$result = in_array($permission, $userAllPermissions);
$log .= ", userAllPermissions: " . json_encode($userAllPermissions) . ", result: $result";
if (!$fail || $result) {
do_log($log);
$userCanCached[$permission][$uid] = $result;
return $result;
}
do_log("$log, [FAIL]");
if (IN_NEXUS && !IN_TRACKER) {
global $lang_functions;
if (isset(User::$classes[$requireClass])) {
$requireClass = get_setting("authority.$permission");
if (isset(\App\Models\User::$classes[$requireClass])) {
stderr($lang_functions['std_sorry'],$lang_functions['std_permission_denied_only'].get_user_class_name($requireClass,false,true,true).$lang_functions['std_or_above_can_view'],false);
} else {
stderr($lang_functions['std_error'], $lang_functions['std_permission_denied']);