Prevent deleting service definitions when they are in use throughout the system. Closes #153

This commit is contained in:
Andy Heathershaw 2020-04-30 08:38:37 +01:00
parent 3655c28c73
commit 8f9a386494
2 changed files with 24 additions and 3 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use App\Configuration;
use App\ExternalService; use App\ExternalService;
use App\Facade\Theme; use App\Facade\Theme;
use App\Facade\UserConfig; use App\Facade\UserConfig;
@ -311,8 +312,28 @@ class ServiceController extends Controller
private function isServiceInUse(ExternalService $service) private function isServiceInUse(ExternalService $service)
{ {
// TODO check if the service is in use anywhere else and prevent it being deleted if so switch ($service->service_type)
return false; {
case ExternalService::FACEBOOK:
// Cannot delete Facebook service if it's set as the login provider
$facebookConfig = Configuration::where('key', 'facebook_external_service_id')->first();
return !is_null($facebookConfig) && intval($facebookConfig->value) == $service->id;
case ExternalService::GOOGLE:
// Cannot delete Google service if it's set as the login provider
$googleConfig = Configuration::where('key', 'google_external_service_id')->first();
return !is_null($googleConfig) && intval($googleConfig->value) == $service->id;
case ExternalService::DROPBOX:
return Storage::where('external_service_id', $service->id)->count() > 0;
case ExternalService::TWITTER:
// Cannot delete Twitter service if it's set as the login provider
$twitterConfig = Configuration::where('key', 'twitter_external_service_id')->first();
return !is_null($twitterConfig) && intval($twitterConfig->value) == $service->id;
}
return true;
} }
private function serviceTypeList() private function serviceTypeList()

View File

@ -72,7 +72,7 @@ return [
'bulk_photos_changed' => ':number photo was updated successfully.|:number photos were updated successfully.', 'bulk_photos_changed' => ':number photo was updated successfully.|:number photos were updated successfully.',
'bulk_photos_changed_queued' => 'Your requested change has been queued. :number photo will be updated shortly.|Your requested change has been queued. :number photos will be updated shortly.', 'bulk_photos_changed_queued' => 'Your requested change has been queued. :number photo will be updated shortly.|Your requested change has been queued. :number photos will be updated shortly.',
'cannot_delete_own_user_account' => 'It is not possible to delete your own user account. Please ask another administrator to delete it for you.', 'cannot_delete_own_user_account' => 'It is not possible to delete your own user account. Please ask another administrator to delete it for you.',
'cannot_delete_service_in_use' => 'This service is still in use and cannot be deleted. Please remove any references to it in your configuration and try again.', 'cannot_delete_service_in_use' => 'This service is still in use and cannot be deleted. Please remove any references to it in your configuration or storages and try again.',
'cannot_remove_own_admin' => 'You cannot remove your own administrator permissions. Please ask another administrator to remove the administrator permissions for you.', 'cannot_remove_own_admin' => 'You cannot remove your own administrator permissions. Please ask another administrator to remove the administrator permissions for you.',
'change_album_message' => 'Please select the album to move the photo(s) to:', 'change_album_message' => 'Please select the album to move the photo(s) to:',
'change_album_title' => 'Move photo(s) to another album', 'change_album_title' => 'Move photo(s) to another album',