diff --git a/Changelog b/Changelog index bfadab59e..c48fc8911 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-04-17 DariusIII + * Chg: Add admin RoleController * Chg: Add admin SiteController * Chg: Add admin UserController * Chg: Add BookController and edit Blacklist/Anidb class diff --git a/app/Http/Controllers/Admin/RoleController.php b/app/Http/Controllers/Admin/RoleController.php new file mode 100644 index 000000000..b75cc0833 --- /dev/null +++ b/app/Http/Controllers/Admin/RoleController.php @@ -0,0 +1,127 @@ +setAdminPrefs(); + + $title = 'User Role List'; + + //get the user roles + $userroles = UserRole::getRoles(); + + $this->smarty->assign('userroles', $userroles); + + $content = $this->smarty->fetch('role-list.tpl'); + + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + + $this->adminrender(); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @throws \Exception + */ + public function edit(Request $request) + { + $this->setAdminPrefs(); + + // Get the user roles. + $userRoles = UserRole::getRoles(); + $roles = []; + foreach ($userRoles as $userRole) { + $roles[$userRole['id']] = $userRole['name']; + } + + switch ($request->input('action') ?? 'view') { + case 'add': + $title = 'User Roles Add'; + $role = [ + 'id' => '', + 'name' => '', + 'apirequests' => '', + 'downloadrequests' => '', + 'defaultinvites' => '', + 'canpreview' => 0, + 'hideads' => 0, + 'donation' => 0, + 'addyears' => 0, + ]; + $this->smarty->assign('role', $role); + break; + + case 'submit': + if ($request->has('id')) { + $role = UserRole::addRole($request->all()); + /*header('Location:'.WWW_TOP.'/role-list.php');*/ + } else { + $role = UserRole::updateRole($request->all()); + //dd($role); + header('Location:'.WWW_TOP.'/role-list.php'); + + $request->merge(['exccat' => (! $request->has('exccat') || ! \is_array($request->input('exccat'))) ? [] : $request->input('exccat')]); + RoleExcludedCategory::addRoleCategoryExclusions($request->input('id'), $request->input('exccat')); + } + $this->smarty->assign('role', $role); + break; + + case 'view': + default: + if ($request->has('id')) { + $title = 'User Roles Edit'; + $role = UserRole::getRoleById($request->input('id')); + $this->smarty->assign('role', $role); + $this->smarty->assign('roleexccat', RoleExcludedCategory::getRoleCategoryExclusion($request->input('id'))); + } + break; + } + + $this->smarty->assign('yesno_ids', [1, 0]); + $this->smarty->assign('yesno_names', ['Yes', 'No']); + $this->smarty->assign('catlist', Category::getForSelect(false)); + + $content = $this->smarty->fetch('role-edit.tpl'); + + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + + $this->adminrender(); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function destroy(Request $request) + { + if ($request->has('id')) { + UserRole::deleteRole($request->input('id')); + } + + return redirect($request->server('HTTP_REFERER')); + } +} diff --git a/public/admin/role-delete.php b/public/admin/role-delete.php deleted file mode 100644 index 357b6c74a..000000000 --- a/public/admin/role-delete.php +++ /dev/null @@ -1,12 +0,0 @@ -has('id')) { - UserRole::deleteRole(request()->input('id')); -} - -$referrer = request()->server('HTTP_REFERER'); -header('Location: '.$referrer); diff --git a/public/admin/role-edit.php b/public/admin/role-edit.php deleted file mode 100644 index 5820dc75c..000000000 --- a/public/admin/role-edit.php +++ /dev/null @@ -1,68 +0,0 @@ -setAdminPrefs(); - -// Get the user roles. -$userRoles = UserRole::getRoles(); -$roles = []; -foreach ($userRoles as $userRole) { - $roles[$userRole['id']] = $userRole['name']; -} - -switch (request()->input('action') ?? 'view') { - case 'add': - $page->title = 'User Roles Add'; - $role = [ - 'id' => '', - 'name' => '', - 'apirequests' => '', - 'downloadrequests' => '', - 'defaultinvites' => '', - 'canpreview' => 0, - 'hideads' => 0, - 'donation' => 0, - 'addyears' => 0, - ]; - $page->smarty->assign('role', $role); - break; - - case 'submit': - if (request()->has('id')) { - $role = UserRole::addRole(request()->all()); - /*header('Location:'.WWW_TOP.'/role-list.php');*/ - } else { - $role = UserRole::updateRole(request()->all()); - //dd($role); - header('Location:'.WWW_TOP.'/role-list.php'); - - request()->merge(['exccat' => (! request()->has('exccat') || ! is_array(request()->input('exccat'))) ? [] : request()->input('exccat')]); - RoleExcludedCategory::addRoleCategoryExclusions(request()->input('id'), request()->input('exccat')); - } - $page->smarty->assign('role', $role); - break; - - case 'view': - default: - if (request()->has('id')) { - $page->title = 'User Roles Edit'; - $role = UserRole::getRoleById(request()->input('id')); - $page->smarty->assign('role', $role); - $page->smarty->assign('roleexccat', RoleExcludedCategory::getRoleCategoryExclusion(request()->input('id'))); - } - break; -} - -$page->smarty->assign('yesno_ids', [1, 0]); -$page->smarty->assign('yesno_names', ['Yes', 'No']); -$page->smarty->assign('catlist', Category::getForSelect(false)); - -$page->content = $page->smarty->fetch('role-edit.tpl'); -$page->adminrender(); diff --git a/public/admin/role-list.php b/public/admin/role-list.php deleted file mode 100644 index ec9ca39f3..000000000 --- a/public/admin/role-list.php +++ /dev/null @@ -1,19 +0,0 @@ -setAdminPrefs(); - -$page->title = 'User Role List'; - -//get the user roles -$userroles = UserRole::getRoles(); - -$page->smarty->assign('userroles', $userroles); - -$page->content = $page->smarty->fetch('role-list.tpl'); -$page->adminrender(); diff --git a/public/admin/site-edit.php b/public/admin/site-edit.php deleted file mode 100644 index 9c1a53820..000000000 --- a/public/admin/site-edit.php +++ /dev/null @@ -1,170 +0,0 @@ -setAdminPrefs(); - -$sites = new Sites(); -$id = 0; - -// set the current action -$action = request()->input('action') ?? 'view'; - -switch ($action) { - case 'submit': - if (! request()->has('book_reqids')) { - request()->merge(['book_reqids' => []]); - } - $error = ''; - $ret = Settings::settingsUpdate(request()->all()); - if (is_int($ret)) { - if ($ret === Settings::ERR_BADUNRARPATH) { - $error = 'The unrar path does not point to a valid binary'; - } elseif ($ret === Settings::ERR_BADFFMPEGPATH) { - $error = 'The ffmpeg path does not point to a valid binary'; - } elseif ($ret === Settings::ERR_BADMEDIAINFOPATH) { - $error = 'The mediainfo path does not point to a valid binary'; - } elseif ($ret === Settings::ERR_BADNZBPATH) { - $error = 'The nzb path does not point to a valid directory'; - } elseif ($ret === Settings::ERR_DEEPNOUNRAR) { - $error = 'Deep password check requires a valid path to unrar binary'; - } elseif ($ret === Settings::ERR_BADTMPUNRARPATH) { - $error = 'The temp unrar path is not a valid directory'; - } elseif ($ret === Settings::ERR_BADLAMEPATH) { - $error = 'The lame path is not a valid directory'; - } elseif ($ret === Settings::ERR_SABCOMPLETEPATH) { - $error = 'The sab complete path is not a valid directory'; - } - } - - if ($error === '') { - $site = $ret; - $returnid = $site['id']; - header('Location:'.WWW_TOP.'/site-edit.php?id='.$returnid); - } else { - $page->smarty->assign('error', $error); - $site = $sites->row2Object(request()->all()); - $page->smarty->assign('site', $site); - } - - break; - case 'view': - default: - - $page->title = 'Site Edit'; - $site = $page->settings; - $page->smarty->assign('site', $site); - $page->smarty->assign('settings', Settings::toTree()); - break; -} - -$page->smarty->assign('yesno_ids', [1, 0]); -$page->smarty->assign('yesno_names', ['Yes', 'No']); - -$page->smarty->assign('passwd_ids', [1, 0]); -$page->smarty->assign('passwd_names', ['Deep (requires unrar)', 'None']); - -/*0 = English, 2 = Danish, 3 = French, 1 = German*/ -$page->smarty->assign('langlist_ids', [0, 2, 3, 1]); -$page->smarty->assign('langlist_names', ['English', 'Danish', 'French', 'German']); - -$page->smarty->assign( - 'imdblang_ids', - [ - 'en', 'da', 'nl', 'fi', 'fr', 'de', 'it', 'tlh', 'no', 'po', 'ru', 'es', - 'sv', - ] -); -$page->smarty->assign( - 'imdblang_names', - [ - 'English', 'Danish', 'Dutch', 'Finnish', 'French', 'German', 'Italian', - 'Klingon', 'Norwegian', 'Polish', 'Russian', 'Spanish', 'Swedish', - ] -); - -$page->smarty->assign('sabintegrationtype_ids', [SABnzbd::INTEGRATION_TYPE_USER, SABnzbd::INTEGRATION_TYPE_NONE]); -$page->smarty->assign('sabintegrationtype_names', ['User', 'None (Off)']); - -$page->smarty->assign('newgroupscan_names', ['Days', 'Posts']); - -$page->smarty->assign('registerstatus_ids', [Settings::REGISTER_STATUS_OPEN, Settings::REGISTER_STATUS_INVITE, Settings::REGISTER_STATUS_CLOSED]); -$page->smarty->assign('registerstatus_names', ['Open', 'Invite', 'Closed']); - -$page->smarty->assign('passworded_ids', [0, 1, 2]); -$page->smarty->assign('passworded_names', [ - 'Hide passworded or potentially passworded (*yes)', - 'Hide passworded or potentially passworded (*no)', - 'Show non-passworded and potentially passworded (*no)', - 'Show everything (*no)', -]); - -$page->smarty->assign('lookuplanguage_iso', ['en', 'de', 'es', 'fr', 'it', 'nl', 'pt', 'sv']); -$page->smarty->assign('lookuplanguage_names', ['English', 'Deutsch', 'Español', 'Français', 'Italiano', 'Nederlands', 'Português', 'Svenska']); - -$page->smarty->assign('imdb_urls', [0, 1]); -$page->smarty->assign('imdburl_names', ['imdb.com', 'akas.imdb.com']); - -$page->smarty->assign('lookupbooks_ids', [0, 1, 2]); -$page->smarty->assign('lookupbooks_names', ['Disabled', 'Lookup All Books', 'Lookup Renamed Books']); - -$page->smarty->assign('lookupgames_ids', [0, 1, 2]); -$page->smarty->assign('lookupgames_names', ['Disabled', 'Lookup All Consoles', 'Lookup Renamed Consoles']); - -$page->smarty->assign('lookupmusic_ids', [0, 1, 2]); -$page->smarty->assign('lookupmusic_names', ['Disabled', 'Lookup All Music', 'Lookup Renamed Music']); - -$page->smarty->assign('lookupmovies_ids', [0, 1, 2]); -$page->smarty->assign('lookupmovies_names', ['Disabled', 'Lookup All Movies', 'Lookup Renamed Movies']); - -$page->smarty->assign('lookuptv_ids', [0, 1, 2]); -$page->smarty->assign('lookuptv_names', ['Disabled', 'Lookup All TV', 'Lookup Renamed TV']); - -$page->smarty->assign('lookup_reqids_ids', [0, 1, 2]); -$page->smarty->assign('lookup_reqids_names', ['Disabled', 'Lookup Request IDs', 'Lookup Request IDs Threaded']); - -$page->smarty->assign('coversPath', NN_COVERS); - -// return a list of audiobooks, mags, ebooks, technical and foreign books -$result = Category::query()->whereIn('id', [Category::MUSIC_AUDIOBOOK, Category::BOOKS_MAGAZINES, Category::BOOKS_TECHNICAL, Category::BOOKS_FOREIGN])->get(['id', 'title']); - -// setup the display lists for these categories, this could have been static, but then if names changed they would be wrong -$book_reqids_ids = []; -$book_reqids_names = []; -foreach ($result as $bookcategory) { - $book_reqids_ids[] = $bookcategory['id']; - $book_reqids_names[] = $bookcategory['title']; -} - -// convert from a string array to an int array as we want to use int -$book_reqids_ids = array_map(function ($value) { - return (int) $value; -}, $book_reqids_ids); -$page->smarty->assign('book_reqids_ids', $book_reqids_ids); -$page->smarty->assign('book_reqids_names', $book_reqids_names); - -// convert from a list to an array as we need to use an array, but teh Settings table only saves strings -$books_selected = explode(',', Settings::settingValue('..book_reqids')); - -// convert from a string array to an int array -$books_selected = array_map(function ($value) { - return (int) $value; -}, $books_selected); -$page->smarty->assign('book_reqids_selected', $books_selected); - -$page->smarty->assign('themelist', Utility::getThemesList()); - -if (strpos(env('NNTP_SERVER'), 'astra') === false) { - $page->smarty->assign('compress_headers_warning', 'compress_headers_warning'); -} - -$page->content = $page->smarty->fetch('site-edit.tpl'); -$page->adminrender(); diff --git a/public/admin/site-stats.php b/public/admin/site-stats.php deleted file mode 100644 index b4048a67c..000000000 --- a/public/admin/site-stats.php +++ /dev/null @@ -1,37 +0,0 @@ -setAdminPrefs(); - -$page->title = 'Site Stats'; - -$topgrabs = User::getTopGrabbers(); -$page->smarty->assign('topgrabs', $topgrabs); - -$topdownloads = Release::getTopDownloads(); -$page->smarty->assign('topdownloads', $topdownloads); - -$topcomments = Release::getTopComments(); -$page->smarty->assign('topcomments', $topcomments); - -$recent = Category::getRecentlyAdded(); -$page->smarty->assign('recent', $recent); - -$usersbymonth = User::getUsersByMonth(); -$page->smarty->assign('usersbymonth', $usersbymonth); - -$usersbyrole = UserRole::getUsersByRole(); -$page->smarty->assign('usersbyrole', $usersbyrole); -$page->smarty->assign('totusers', 0); -$page->smarty->assign('totrusers', 0); - -$page->content = $page->smarty->fetch('site-stats.tpl'); -$page->adminrender(); diff --git a/routes/web.php b/routes/web.php index c05455e38..4d18ea95a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -225,4 +225,10 @@ Route::prefix('admin')->group(function () { Route::post('site-edit', 'Admin\SiteController@edit'); Route::get('site-stats', 'Admin\SiteController@stats'); Route::post('site-stats', 'Admin\SiteController@stats'); + Route::get('role-list', 'Admin\RoleController@index'); + Route::post('role-list', 'Admin\RoleController@index'); + Route::get('role-edit', 'Admin\RoleController@edit'); + Route::post('role-edit', 'Admin\RoleController@edit'); + Route::get('role-delete', 'Admin\RoleController@destroy'); + Route::post('role-delete', 'Admin\RoleController@destroy'); });