diff --git a/app/Actions/Settings/SetDefaultSettingsForUser.php b/app/Actions/Settings/SetDefaultSettingsForUser.php index 01fdae86..557bddcf 100644 --- a/app/Actions/Settings/SetDefaultSettingsForUser.php +++ b/app/Actions/Settings/SetDefaultSettingsForUser.php @@ -23,6 +23,8 @@ class SetDefaultSettingsForUser extends SettingsMigration $this->migrator->add($group . '.time_format', $defaults['time_format']); $this->migrator->add($group . '.locale', $defaults['locale']); + $this->migrator->add($group . '.profile_is_public', $defaults['profile_is_public']); + $this->migrator->add($group . '.links_default_visibility', $defaults['links_default_visibility']); $this->migrator->add($group . '.notes_default_visibility', $defaults['notes_default_visibility']); $this->migrator->add($group . '.lists_default_visibility', $defaults['lists_default_visibility']); diff --git a/app/Helper/functions.php b/app/Helper/functions.php index 4a1294bd..a853c4a1 100644 --- a/app/Helper/functions.php +++ b/app/Helper/functions.php @@ -30,15 +30,20 @@ function setupCompleted() /** * Shorthand for the current user settings * - * @param string $key + * @param string $key + * @param int|null $userId * @return mixed */ -function usersettings(string $key = ''): mixed +function usersettings(string $key = '', ?int $userId = null): mixed { - if (!auth()->user()) { + if (is_null($userId) && !auth()->user()) { return null; } + if (!is_null($userId)) { + app(UserSettings::class)::setUserId($userId); + } + if ($key === '') { return app(UserSettings::class)->toArray(); } diff --git a/app/Http/Controllers/App/UserSettingsController.php b/app/Http/Controllers/App/UserSettingsController.php index 37fda5be..a0bfdcf7 100644 --- a/app/Http/Controllers/App/UserSettingsController.php +++ b/app/Http/Controllers/App/UserSettingsController.php @@ -53,8 +53,6 @@ class UserSettingsController extends Controller */ public function saveAppSettings(UserSettings $settings, UserSettingsUpdateRequest $request): RedirectResponse { - $userId = $request->user()->id; - // Save all user settings or update them $newSettings = $request->except(['_token', 'share']); foreach ($newSettings as $key => $value) { diff --git a/app/Http/Controllers/Guest/UserController.php b/app/Http/Controllers/Guest/UserController.php new file mode 100644 index 00000000..2fb4c9a4 --- /dev/null +++ b/app/Http/Controllers/Guest/UserController.php @@ -0,0 +1,54 @@ +id) === false) { + abort(404); + } + + $links = Link::byUser($user->id) + ->whereVisibility(ModelAttribute::VISIBILITY_PUBLIC) + ->latest() + ->take(10) + ->paginate(pageName: 'link_page'); + + $lists = LinkList::byUser($user->id) + ->whereVisibility(ModelAttribute::VISIBILITY_PUBLIC) + ->latest() + ->take(10) + ->paginate(pageName: 'link_page'); + + $tags = Tag::byUser($user->id) + ->whereVisibility(ModelAttribute::VISIBILITY_PUBLIC) + ->latest() + ->take(10) + ->paginate(pageName: 'link_page'); + + $stats = [ + 'total_links' => Link::byUser($user->id)->whereVisibility(ModelAttribute::VISIBILITY_PUBLIC)->count(), + 'total_lists' => LinkList::byUser($user->id)->whereVisibility(ModelAttribute::VISIBILITY_PUBLIC)->count(), + 'total_tags' => Tag::byUser($user->id)->whereVisibility(ModelAttribute::VISIBILITY_PUBLIC)->count(), + 'total_notes' => Note::byUser($user->id)->whereVisibility(ModelAttribute::VISIBILITY_PUBLIC)->count(), + ]; + + return view('guest.users.show', [ + 'user' => $user, + 'links' => $links, + 'lists' => $lists, + 'tags' => $tags, + 'stats' => $stats, + ]); + } +} diff --git a/app/Settings/UserSettings.php b/app/Settings/UserSettings.php index fc3a5dbb..c90c8576 100644 --- a/app/Settings/UserSettings.php +++ b/app/Settings/UserSettings.php @@ -12,6 +12,8 @@ class UserSettings extends Settings public string $time_format; public string $locale; + public bool $profile_is_public; + public int $links_default_visibility; public int $notes_default_visibility; public int $lists_default_visibility; @@ -47,16 +49,23 @@ class UserSettings extends Settings public bool $share_whatsapp; public bool $share_xing; + private static int $user_id = 0; + public static function group(): string { - return 'user-' . auth()->id(); + return 'user-' . self::getUserId(); + } + + public static function setUserId(int $user_id): void + { + self::$user_id = $user_id; + } + + protected static function getUserId(): int + { + return self::$user_id ?: auth()->id(); } - /** - * Returns the default settings for users - * - * @return array{string: string|int|bool|null} - */ public static function defaults(): array { return [ @@ -64,6 +73,7 @@ class UserSettings extends Settings 'date_format' => config('linkace.default.date_format'), 'time_format' => config('linkace.default.time_format'), 'locale' => config('app.fallback_locale'), + 'profile_is_public' => false, 'links_default_visibility' => ModelAttribute::VISIBILITY_PUBLIC, 'notes_default_visibility' => ModelAttribute::VISIBILITY_PUBLIC, 'lists_default_visibility' => ModelAttribute::VISIBILITY_PUBLIC, diff --git a/database/settings/2022_06_22_124112_migrate_existing_settings.php b/database/settings/2022_06_22_124112_migrate_existing_settings.php index c57fd0ae..62f06741 100644 --- a/database/settings/2022_06_22_124112_migrate_existing_settings.php +++ b/database/settings/2022_06_22_124112_migrate_existing_settings.php @@ -79,6 +79,11 @@ class MigrateExistingSettings extends SettingsMigration $this->userSettings->get('locale', config('app.fallback_locale')) ); + $this->migrator->add( + 'user-1.profile_is_public', + (bool)$this->sysSettings->get('system_guest_access', false) + ); + $this->migrator->add( 'user-1.links_default_visibility', $this->userSettings->get('links_private_default', false) diff --git a/lang/en_US/settings.php b/lang/en_US/settings.php index c9b836cf..3c4b2dfa 100644 --- a/lang/en_US/settings.php +++ b/lang/en_US/settings.php @@ -18,7 +18,9 @@ return [ 'markdown_for_text' => 'Enable Markdown for descriptions and notes', 'privacy' => 'Privacy', - 'default_visibility_help' => 'Choose the default visibility for Links, Lists, Notes and Tags when adding new entries.', + 'profile_privacy' => 'The following settings apply to your user profile which is visible to guests.', + 'profile_is_public' => 'Profile is public', + 'default_visibility_help' => 'The following settings define the default visibility for Links, Lists, Notes and Tags when adding new ones.', 'links_default_visibility' => 'Default Links visibility', 'notes_default_visibility' => 'Default Notes visibility', 'lists_default_visibility' => 'Default Lists visibility', diff --git a/resources/views/app/settings/partials/app-settings/privacy.blade.php b/resources/views/app/settings/partials/app-settings/privacy.blade.php index 0f67a9d8..0fd4efd8 100644 --- a/resources/views/app/settings/partials/app-settings/privacy.blade.php +++ b/resources/views/app/settings/partials/app-settings/privacy.blade.php @@ -14,6 +14,33 @@ $settings = [ @lang('settings.privacy') +
@lang('settings.profile_privacy')
+ ++ {{ $errors->first('profile_is_public') }} +
+ @endif +@lang('settings.default_visibility_help')