diff --git a/objects/user.php b/objects/user.php index f68047665c..b7a7e03416 100644 --- a/objects/user.php +++ b/objects/user.php @@ -1505,7 +1505,8 @@ if (typeof gtag !== \"function\") { public static function canStream() { self::recreateLoginFromCookie(); - return !empty($_SESSION['user']['isAdmin']) || !empty($_SESSION['user']['canStream']); + + return !empty($_SESSION['user']['isAdmin']) || !empty($_SESSION['user']['canStream']) || AVideoPlugin::userCanLivestream($_SESSION['user']['id']); } public static function externalOptions($id) @@ -2525,7 +2526,7 @@ if (typeof gtag !== \"function\") { if (self::isLogged() && !empty($_SESSION['user']['canUpload'])) { return true; } - return self::isAdmin(); + return self::isAdmin() || AVideoPlugin::userCanUpload(User::getId()); } public static function canViewChart() diff --git a/plugin/AVideoPlugin.php b/plugin/AVideoPlugin.php index 281faea377..e03954e79b 100644 --- a/plugin/AVideoPlugin.php +++ b/plugin/AVideoPlugin.php @@ -1531,6 +1531,38 @@ class AVideoPlugin return $resp; } + public static function userCanLivestream($users_id) + { + if (empty($users_id)) { + return false; + } + $resp = false; + $plugins = Plugin::getAllEnabled(); + foreach ($plugins as $value) { + self::YPTstart(); + $p = static::loadPlugin($value['dirName']); + if (is_object($p)) { + $can = $p->userCanLivestream($users_id); + if (!empty($can)) { + if ($can < 0) { + if (!empty($users_id)) { + _error_log("userCanLivestream: DENIED The plugin {$value['dirName']} said the user ({$users_id}) can NOT upload a video "); + } + $resp = false; + } + if ($can > 0) { + if (!empty($users_id)) { + _error_log("userCanLivestream: SUCCESS The plugin {$value['dirName']} said the user ({$users_id}) can upload a video "); + } + return true; + } + } + } + self::YPTend("{$value['dirName']}::" . __FUNCTION__); + } + return $resp; + } + public static function userCanWatchVideo($users_id, $videos_id) { global $userCanWatchVideoFunction; diff --git a/plugin/Live/view/menuRight.php b/plugin/Live/view/menuRight.php index 8f17ed5d9f..2ec02be277 100644 --- a/plugin/Live/view/menuRight.php +++ b/plugin/Live/view/menuRight.php @@ -10,6 +10,7 @@ if (empty($isLive)) { } else { $liveInfo = Live::getInfo($isLive['key'], $isLive['live_servers_id']); } + if (User::canStream()) { if (empty($obj->doNotShowGoLiveButton)) { ?> diff --git a/plugin/Permissions/Permissions.php b/plugin/Permissions/Permissions.php index e0a2698c62..bd1d9f213c 100644 --- a/plugin/Permissions/Permissions.php +++ b/plugin/Permissions/Permissions.php @@ -14,6 +14,8 @@ class Permissions extends PluginAbstract { const PERMISSION_CACHE = 40; const PERMISSION_SITEMAP = 50; const PERMISSION_LOG = 60; + const PERMISSION_CAN_UPLOAD_VIDEOS = 70; + const PERMISSION_CAN_LIVESTREAM = 80; public function getDescription() { $desc = "Permissions will allow you to add intermediate permisson to usergroups without need to make them Admin, " @@ -105,15 +107,8 @@ class Permissions extends PluginAbstract { return false; } - static function hasPermission($type, $pluginName) { + static function hasPermission($type, $pluginName, $users_id = 0) { global $hasPermission; - if (!User::isLogged()) { - return false; - } - - if (User::isAdmin()) { - return true; - } if (empty($hasPermission)) { $hasPermission = []; @@ -121,11 +116,22 @@ class Permissions extends PluginAbstract { if (empty($hasPermission[$pluginName])) { $hasPermission[$pluginName] = []; } - if (isset($hasPermission[$pluginName][$type])) { - return $hasPermission[$pluginName][$type]; + if(empty($users_id)){ + if (!User::isLogged()) { + return false; + } + + if (User::isAdmin()) { + return true; + } + + if (isset($hasPermission[$pluginName][$type])) { + return $hasPermission[$pluginName][$type]; + } + $users_id = User::getId(); } $hasPermission[$pluginName][$type] = false; - $groups = UserGroups::getUserGroups(User::getId()); + $groups = UserGroups::getUserGroups($users_id); foreach ($groups as $value) { $permissions = Users_groups_permissions::getAllFromUserGorup($value['id']); if (!empty($permissions[$pluginName]) && in_array($type, $permissions[$pluginName])) { @@ -143,6 +149,28 @@ class Permissions extends PluginAbstract { static function canAdminVideos() { return self::hasPermission(Permissions::PERMISSION_FULLACCESSVIDEOS, 'Permissions'); } + + public function userCanUpload($users_id) { + if(empty($users_id)){ + return -1; + } + + if(self::hasPermission(Permissions::PERMISSION_CAN_UPLOAD_VIDEOS, 'Permissions', $users_id)){ + return 1;// Yes + } + return 0;// I dont know + } + + public function userCanLivestream($users_id) { + if(empty($users_id)){ + return -1; // NO HE CANT + } + + if(self::hasPermission(Permissions::PERMISSION_CAN_LIVESTREAM, 'Permissions', $users_id)){ + return 1;// Yes + } + return 0;// I dont know + } static function canModerateVideos() { return self::hasPermission(Permissions::PERMISSION_INACTIVATEVIDEOS, 'Permissions') || self::canAdminVideos(); @@ -180,16 +208,29 @@ class Permissions extends PluginAbstract { */ function getPermissionsOptions() { $permissions = []; - $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_COMMENTS, __('Comments Admin'), __('Users with this option will be able to edit and delete comments in any video'), 'Permissions'); + // Video permissions $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_FULLACCESSVIDEOS, __('Videos Admin'), __('Just like admin, this user will have permission to edit and delete videos from any user, including videos from admin'), 'Permissions'); $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_INACTIVATEVIDEOS, __('Videos Moderator'), __('This is a level below the (Videos Admin), this type of user can change the video publicity (Active, Inactive, Unlisted)'), 'Permissions'); + $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_CAN_UPLOAD_VIDEOS, __('Upload Videos'), __('Users with this option will be able to upload videos'), 'Permissions'); + + // Comments permissions + $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_COMMENTS, __('Comments Admin'), __('Users with this option will be able to edit and delete comments in any video'), 'Permissions'); + + // User and User Group permissions $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_USERS, __('Users Admin'), __('This type of user can edit users, can add or remove users into user groups, but cannot make them admins'), 'Permissions'); $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_USERGROUPS, __('Users Groups Admin'), __('Can edit and delete user groups'), 'Permissions'); - $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_CACHE, __('Cache Manager'), __('This will give the option to can clear cache (Site and first page)'), 'Permissions'); - $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_SITEMAP, __('Sitemap'), __('This will give the option to generate SiteMap'), 'Permissions'); + + // Livestream permission + $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_CAN_LIVESTREAM, __('Live Stream'), __('Users with this option will be able to live stream'), 'Permissions'); + + // Cache, Log, and Sitemap permissions + $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_CACHE, __('Cache Manager'), __('This will give the option to clear cache (Site and first page)'), 'Permissions'); + $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_SITEMAP, __('Sitemap'), __('This will give the option to generate a SiteMap'), 'Permissions'); $permissions[] = new PluginPermissionOption(Permissions::PERMISSION_LOG, __('Log'), __('This will give the option to see the log file menu'), 'Permissions'); + return $permissions; } + static function getPluginPermissions($plugins_id) { global $getPluginPermissions; diff --git a/plugin/Plugin.abstract.php b/plugin/Plugin.abstract.php index 25f29a5112..d754b94f30 100644 --- a/plugin/Plugin.abstract.php +++ b/plugin/Plugin.abstract.php @@ -574,6 +574,15 @@ abstract class PluginAbstract { public function userCanUpload($users_id) { return 0; } + + /** + * + * @param string $users_id + * @return 0 = I dont know, -1 = can not upload, 1 = can upload + */ + public function userCanLivestream($users_id) { + return 0; + } /** *