Add setting to disable backfill, setting to disable profile access to non admin/mod user.

This commit is contained in:
Darko
2015-06-01 15:46:26 +02:00
parent c159c2dc1e
commit 03abdc0f8e
13 changed files with 171 additions and 29 deletions
+2 -2
View File
@@ -2,8 +2,8 @@
<newznab>
<versions>
<sql>
<db>122</db>
<file>122</file>
<db>125</db>
<file>125</file>
</sql>
<git>
<tag>0.4.1</tag>
+20 -1
View File
@@ -77,6 +77,12 @@ class Backfill
*/
protected $_safePartRepair;
/**
* Should we disable the group if we have backfilled far enough?
* @var bool
*/
protected $_disableBackfillGroup;
/**
* Constructor.
*
@@ -114,6 +120,7 @@ class Backfill
$this->_safeBackFillDate = ($this->pdo->getSetting('safebackfilldate') != '') ? (string)$this->pdo->getSetting('safebackfilldate') : '2008-08-14';
$this->_safePartRepair = ($this->pdo->getSetting('safepartrepair') == 1 ? 'update' : 'backfill');
$this->_tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 1 ? true : false);
$this->_disableBackfillGroup = ($this->pdo->getSetting('disablebackfillgroup') == 1 ? true : false);
}
/**
@@ -268,11 +275,23 @@ class Backfill
$dMessage =
"We have hit the maximum we can backfill for " .
$groupName .
", skipping it, consider disabling backfill on it.";
($this->_disableBackfillGroup ? ", disabling backfill on it." :
", skipping it, consider disabling backfill on it.");
if ($this->_debug) {
$this->_debugging->log('Backfill', "backfillGroup", $dMessage, \Logger::LOG_NOTICE);
}
if ($this->_disableBackfillGroup) {
$this->pdo->queryExec(
sprintf('
UPDATE groups
SET backfill = 0
WHERE id = %d',
$groupArr['id']
)
);
}
if ($this->_echoCLI) {
$this->pdo->log->doEcho($this->pdo->log->notice($dMessage), true);
}
+51 -3
View File
@@ -18,6 +18,7 @@ class Users
const ROLE_USER = 1;
const ROLE_ADMIN = 2;
const ROLE_DISABLED = 3;
const ROLE_MODERATOR = 4;
const DEFAULT_INVITES = 1;
const DEFAULT_INVITE_EXPIRY_DAYS = 7;
@@ -434,9 +435,7 @@ class Users
public function isDisabled($username)
{
$role = $this->pdo->queryOneRow(sprintf("select role as role from users where username = %s ", $this->pdo->escapeString($username)));
return ($role["role"] == Users::ROLE_DISABLED);
return $this->roleCheck(self::ROLE_DISABLED, $username);
}
public function isValidUrl($url)
@@ -986,4 +985,53 @@ class Users
{
return $this->pdo->queryInsert(sprintf("delete from userdownloads where releaseid = %d", $releaseID));
}
/**
* Checks if a user is a specific role.
*
* @notes Uses type of $user to denote identifier. if string: username, if int: userid
* @param int $roleID
* @param string|int $user
* @return bool
*/
public function roleCheck($roleID, $user) {
if (is_string($user) && strlen($user) > 0) {
$user = $this->pdo->escapeString($user);
$querySuffix = "username = '$user'";
} elseif (is_int($user) && $user >= 0) {
$querySuffix = "id = $user";
} else {
return false;
}
$result = $this->pdo->queryOneRow(
sprintf(
"SELECT role FROM users WHERE %s",
$querySuffix
)
);
return ((integer)$result['role'] == (integer) $roleID) ? true : false;
}
/**
* Wrapper for roleCheck specifically for Admins.
*
* @param int $userID
* @return bool
*/
public function isAdmin($userID) {
return $this->roleCheck(self::ROLE_ADMIN, (integer) $userID);
}
/**
* Wrapper for roleCheck specifically for Moderators.
*
* @param int $userId
* @return bool
*/
public function isModerator($userId) {
return $this->roleCheck(self::ROLE_MODERATOR, (integer) $userId);
}
}
+9 -2
View File
@@ -1,2 +1,9 @@
INSERT INTO `site` (`setting`, `value`) VALUES ('processthumbnails', '0');
UPDATE `site` SET `value` = '121' WHERE `setting` = 'sqlpatch';
INSERT IGNORE INTO settings (name, value, hint, setting)
VALUES (
'processthumbnails', 0,
'Whether to attempt to process a video thumbnail image. You must have ffmpeg for this.',
'processthumbnails'
);
UPDATE site SET value = 1
WHERE setting = 'processthumbnails' AND (SELECT * FROM (SELECT value FROM site WHERE setting = 'ffmpegpath') s) != '';
+6
View File
@@ -0,0 +1,6 @@
INSERT IGNORE INTO settings (name, value, hint, setting)
VALUES (
'disablebackfillgroup', 0,
'Whether to disable backfill on a group if the target date has been reached.',
'disablebackfillgroup'
);
+1
View File
@@ -0,0 +1 @@
INSERT INTO settings (section, subsection, name, value, hint, setting) VALUES ('', '', 'privateprofiles', 1, 'Hide profiles from other users (admin/mod can still access).', 'privateprofiles');
+9
View File
@@ -0,0 +1,9 @@
INSERT IGNORE INTO settings (name, value, hint, setting)
VALUES (
'processthumbnails', 0,
'Whether to attempt to process a video thumbnail image. You must have ffmpeg for this.',
'processthumbnails'
);
UPDATE settings SET value = 1
WHERE setting = 'processthumbnails' AND (SELECT * FROM (SELECT value FROM settings WHERE setting = 'ffmpegpath') s) != '';
+26
View File
@@ -19,6 +19,29 @@ elseif (isset($_GET["name"]))
else
$userid = $users->currentUserId();
$privileged = ($users->isAdmin($userid) || $users->isModerator($userid)) ? true : false;
$privateProfiles = ($page->settings->getSetting('privateprofiles') == 1) ? true : false;
$publicView = false;
if (!$privateProfiles || $privileged) {
$altID = (isset($_GET['id']) && $_GET['id'] >= 0) ? (int) $_GET['id'] : false;
$altUsername = (isset($_GET['name']) && strlen($_GET['name']) > 0) ? $_GET['name'] : false;
// If both 'id' and 'name' are specified, 'id' should take precedence.
if ($altID === false && $altUsername !== false) {
$user = $users->getByUsername($altUsername);
if ($user) {
$altID = $user['id'];
}
} else if ($altID !== false) {
$userid = $altID;
$publicView = true;
}
}
$data = $users->getById($userid);
if (!$data)
$page->show404();
@@ -31,6 +54,9 @@ $page->smarty->assign('apihits', $users->getApiRequests($userid));
$page->smarty->assign('grabstoday', $users->getDownloadRequests($userid));
$page->smarty->assign('userinvitedby',$invitedby);
$page->smarty->assign('user',$data);
$page->smarty->assign('privateprofiles', $privateProfiles);
$page->smarty->assign('publicview', $publicView);
$page->smarty->assign('privileged', $privileged);
$commentcount = $rc->getCommentCountForUser($userid);
$offset = isset($_REQUEST["offset"]) ? $_REQUEST["offset"] : 0;
@@ -619,6 +619,15 @@
</td>
</tr>
<tr>
<td style="width:180px;"><label for="disablebackfillgroup">Auto disable groups during Backfill:</label></td>
<td>
{html_radios id="disablebackfillgroup" name='disablebackfillgroup' values=$yesno_ids output=$yesno_names selected=$fsite->disablebackfillgroup separator='<br />'}
<div class="hint">Whether to disable a group automatically during backfill if the target date has been reached.</div>
</td>
</tr>
<tr>
</table>
</fieldset>
@@ -1532,6 +1541,15 @@
</td>
</tr>
</tr>
<tr>
<td style="width:180px;"><label for="privateprofiles">Private Profiles:</label></td>
<td>
{html_radios id="privateprofiles" name='privateprofiles' values=$yesno_ids output=$yesno_names selected=$fsite->privateprofiles separator='<br />'}
<div class="hint">Should we <strong>disallow</strong> users from accessing profiles other than their own? (regardless of this setting admin/mod can access).</div>
</td>
</tr>
<tr>
<td style="width:130px;"><label for="userdownloadpurgedays">User Downloads Purge Days</label>:</td>
<td>
@@ -25,10 +25,12 @@
{$result.message|escape:"htmlall"|truncate:200:'...':false:false}
</div>
</td>
<td>
<a title="View profile" href="{$smarty.const.WWW_TOP}/profile/?name={$result.username}">{$result.username}</a>
<br/>
on <span title="{$result.createddate}">{$result.createddate|date_format}</span> <div class="hint">({$result.createddate|timeago})</div>
{if !$privateprofiles || $isadmin || $ismod}
<a title="View profile" href="{$smarty.const.WWW_TOP}/profile/?name={$result.username}">{$result.username}</a><br>
{else}
{$result.username}
{/if}
<span title="{$result.createddate}">{$result.createddate|date_format}</span> <div class="hint">({$result.createddate|timeago})</div>
</td>
<td>
<a href="{$smarty.const.WWW_TOP}/forumpost/{$result.id}#last" title="{$result.updateddate}">{$result.updateddate|date_format}</a> <div class="hint">({$result.updateddate|timeago})</div>
@@ -17,10 +17,11 @@
{foreach from=$results item=result name=result}
<tr class="{cycle values=",alt"}">
<td width="15%;">
{if $result.isadmin == 1}<strong>{/if}
<a {if $smarty.foreach.result.last}id="last"{/if} title="{if $result.isadmin == 1}Admin{else}View profile{/if}" href="{$smarty.const.WWW_TOP}/profile/?name={$result.username}">{$result.username}</a>
{if $result.isadmin == 1}</strong>{/if}
<br/>
{if !$privateprofiles || $isadmin || $ismod}
<a {if $smarty.foreach.result.last}id="last"{/if} title="View profile" href="{$smarty.const.WWW_TOP}/profile/?name={$result.username}">{$result.username}</a>
{else}
{$result.username}
{/if}
on <span title="{$result.createddate}">{$result.createddate|date_format}</span> <div class="hint">({$result.createddate|timeago})</div>
{if $userdata.role==2}
<div>
@@ -3,14 +3,14 @@
<table class="data">
<tr><th>Username:</th><td>{$user.username|escape:"htmlall"}</td></tr>
{if $user.id==$userdata.id || $userdata.role==2}<tr><th title="Not public">Email:</th><td>{$user.email}</td></tr>{/if}
{if $isadmin || !$publicview}<tr><th title="Not public">Email:</th><td>{$user.email}</td></tr>{/if}
<tr><th>Registered:</th><td title="{$user.createddate}">{$user.createddate|date_format} ({$user.createddate|timeago} ago)</td></tr>
<tr><th>Last Login:</th><td title="{$user.lastlogin}">{$user.lastlogin|date_format} ({$user.lastlogin|timeago} ago)</td></tr>
<tr><th>Role:</th><td>{$user.rolename}</td></tr>
<tr><th>Theme:</th><td>{$user.style}</td></tr>
{if $userdata.role==2}<tr><th title="Admin Notes">Notes:</th><td>{$user.notes|escape:htmlall}{if $user.notes|count_characters > 0}<br/>{/if}<a href="{$smarty.const.WWW_TOP}/admin/user-edit.php?id={$user.id}#notes">Add/Edit</a></td></tr>{/if}
{if $user.id==$userdata.id || $userdata.role==2}<tr><th title="Not public">Site Api/Rss Key:</th><td><a href="{$smarty.const.WWW_TOP}/rss?t=0&amp;dl=1&amp;i={$user.id}&amp;r={$user.rsstoken}">{$user.rsstoken}</a></td></tr>{/if}
{if $user.id==$userdata.id || $userdata.role==2}
{if $isadmin || !$publicview}<tr><th title="Not public">Site Api/Rss Key:</th><td><a href="{$smarty.const.WWW_TOP}/rss?t=0&amp;dl=1&amp;i={$user.id}&amp;r={$user.rsstoken}">{$user.rsstoken}</a></td></tr>{/if}
{if $isadmin || !$publicview}
<tr><th>API Hits Today:</th><td><span id="uatd">{$apihits.num}</span> {if $userdata.role==2 && $apihits.num > 0}<a onclick="resetapireq({$user.id}, 'api'); document.getElementById('uatd').innerHTML='0'; return false;" href="#">Reset</a>{/if}</td></tr>
<tr><th>Grabs Today:</th><td><span id="ugrtd">{$grabstoday.num}</span> {if $grabstoday.num >= $user.downloadrequests}&nbsp;&nbsp;<small>(Next DL in {($grabstoday.nextdl/3600)|intval}h {($grabstoday.nextdl/60) % 60}m)</small>{/if}{if $userdata.role==2 && $grabstoday.num > 0}<a onclick="resetapireq({$user.id}, 'grabs'); document.getElementById('ugrtd').innerHTML='0'; return false;" href="#">Reset</a>{/if}</td></tr>
{/if}
@@ -37,8 +37,17 @@
{/if}
{if $userinvitedby && $userinvitedby.username != ""}
<tr><th>Invited By:</th><td><a title="View {$userinvitedby.username}'s profile" href="{$smarty.const.WWW_TOP}/profile?name={$userinvitedby.username}">{$userinvitedby.username}</a></td>
{/if}
<tr>
<th>Invited By:</th>
<td>
{if $privileged || !$privateprofiles}
<a title="View {$userinvitedby.username}'s profile" href="{$smarty.const.WWW_TOP}/profile?name={$userinvitedby.username}">{$userinvitedby.username}</a>
{else}
{$userinvitedby.username}
{/if}
</td>
</tr>{/if}
<tr><th>UI Preferences:</th>
<td>
@@ -50,7 +59,7 @@
{if $user.bookview == "1"}View book covers{else}View standard book category{/if}
</td>
</tr>
{if $user.id==$userdata.id || $userdata.role==2}<tr><th title="Not public">Excluded Categories:</th><td>{$exccats|replace:",":"<br/>"}</td></tr>{/if}
{if $isadmin || !$publicview}<tr><th title="Not public">Excluded Categories:</th><td>{$exccats|replace:",":"<br/>"}</td></tr>{/if}
{if $page->site->sabintegrationtype == 2 && $user.id==$userdata.id}
<tr><th>SABnzbd Integration:</th>
<td>
@@ -573,14 +573,10 @@
{foreach from=$comments|@array_reverse:true item=comment}
<tr>
<td class="less" title="{$comment.createddate}">
{if $comment.role == -1}<i class="icon-globe" title="Syndicated User"></i>
{$comment.username}{if $isadmin} @<a href="{$smarty.const.WWW_TOP}/admin/spotnab-edit.php?id={$comment.sourceid}&amp;from={$smarty.server.REQUEST_URI}">{$comment.rolename}</a>{/if}
{elseif $comment.role == 2}<i class="icon-font" title="{$comment.rolename}"></i>
<strong><a title="View {$comment.username}'s profile" href="{$smarty.const.WWW_TOP}/profile?name={$comment.username}">{$comment.username}</a></strong>
{elseif $comment.role == 4}<i class="icon-certificate" title="{$comment.rolename}"></i>
<a title="View {$comment.username}'s profile" href="{$smarty.const.WWW_TOP}/profile?name={$comment.username}">{$comment.username}</a>
{else}<i class="icon-user" title="{$comment.username}"></i>
{if !$privateprofiles || $isadmin || $ismod}
<a title="View {$comment.username}'s profile" href="{$smarty.const.WWW_TOP}/profile?name={$comment.username}">{$comment.username}</a>
{else}
{$comment.username}
{/if}
<br/>{$comment.createddate|daysago}
</td>