diff --git a/app/Http/Controllers/ShotController.php b/app/Http/Controllers/ShotController.php index c4984d2..6a3766d 100644 --- a/app/Http/Controllers/ShotController.php +++ b/app/Http/Controllers/ShotController.php @@ -49,10 +49,14 @@ public function show(Request $request, string $id) ]); } + if($shot->require_logged_in && !$request->user()) { + abort(404); + } + return Inertia::render('Shots/Show', [ 'shot' => fn () => $shot->fresh(), 'childShots' => fn () => Shot::whereParentShotId($shot->getKey())->get(), - 'author' => fn () => $shot->user->only(['id', 'name']), + 'author' => fn () => $shot->anonymize ? null : $shot->user->only(['id', 'name']), 'reaction' => fn () => $request->user()?->reactions()->whereShotId($shot->getKey())->first(), 'reactionCounts' => fn () => ShotReaction::whereShotId($shot->getKey()) ->select('reaction', DB::raw('count(*) as count')) @@ -60,6 +64,7 @@ public function show(Request $request, string $id) ->get() ->mapWithKeys(fn ($result) => [$result['reaction'] => $result['count']]), 'showLinks' => config('shots.links'), + 'isOwner' => $shot->user_id == $request->user()->getKey(), ]); } diff --git a/resources/js/Components/ui/UserAvatar.vue b/resources/js/Components/ui/UserAvatar.vue index 1bee5ad..cfc1a54 100644 --- a/resources/js/Components/ui/UserAvatar.vue +++ b/resources/js/Components/ui/UserAvatar.vue @@ -7,7 +7,7 @@ const props = defineProps({ }) const initials = computed(() => { - return props.user?.name.split(' ').map(fragment => fragment[0].toUpperCase()).join('') + return props.user?.name?.split(' ').map(fragment => fragment[0].toUpperCase()).join('') ?? "A" }) diff --git a/resources/js/Pages/Shots/Partials/ShotDetails.vue b/resources/js/Pages/Shots/Partials/ShotDetails.vue index c3364d2..e587562 100644 --- a/resources/js/Pages/Shots/Partials/ShotDetails.vue +++ b/resources/js/Pages/Shots/Partials/ShotDetails.vue @@ -23,6 +23,7 @@ const props = defineProps({ author: Object, reaction: Object, reactionCounts: Object, + isOwner: Boolean, }) const titleFocus = ref(false) @@ -38,10 +39,6 @@ const reactToShot = (shotId, reaction) => { }) } -const isOwner = computed(() => { - return props.author.id === usePage().props.auth.user?.id -}) - let updating = ref({}) const updateShot = (body = {}) => { @@ -52,7 +49,7 @@ const updateShot = (body = {}) => { return axios.patch(route('shots.update', props.shot.id), body) .then((response) => { router.reload({ - only: ['shot'], + only: ['shot', 'author'], onFinish: () => updateKeys.forEach(key => updating.value[key] = false) }) @@ -186,7 +183,14 @@ const deleteShot = () => {