Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko259 committed Aug 2, 2024
2 parents c0f1ec3 + 1480d0f commit d592e92
Show file tree
Hide file tree
Showing 35 changed files with 81 additions and 299 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ COPY --from=frontend --chown=www-data:www-data /app/public/ /app/public/

WORKDIR /app

# Ensure the storage and cache directories have the correct permissions
RUN chmod -R 755 storage bootstrap/cache && \
composer install --no-dev --no-interaction --prefer-dist && \
mkdir -p /app/storage/app/public/files
composer install --no-dev --no-interaction --prefer-dist && \
mkdir -p /app/storage/app/public/banners && \
chmod -R 775 /app/storage

# Wrap around the default PHP entrypoint with a custom entrypoint
COPY ./container/entrypoint.sh /usr/local/bin/service-entrypoint
ENTRYPOINT [ "service-entrypoint" ]
CMD ["apache2-foreground"]
CMD ["apache2-foreground"]
10 changes: 3 additions & 7 deletions app/Http/Controllers/API/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function index(Calendar $calendar)

// Set the full path on the image attribute
$events->transform(function ($event) {
$event->image = asset('storage/banners/' . $event->image);
$event->image = isset($event->image) ? asset('storage/banners/' . $event->image) : null;
return $event;
});

Expand All @@ -37,7 +37,6 @@ public function store(Request $request)
{
$data = $this->validate($request, [
'calendar_id' => 'required|exists:calendars,id',
'area' => 'required|exists:areas,id',
'title' => 'required|string|max:255',
'short_description' => 'required|max:280',
'long_description' => 'required',
Expand Down Expand Up @@ -70,7 +69,7 @@ public function store(Request $request)
$storedPath = $image->storeAs('banners', $imageName, 'public');

// Check if the image was successfully uploaded
if (!Storage::disk('public')->exists($storedPath)) {
if ($storedPath && !Storage::disk('public')->exists($storedPath)) {
return back()->withErrors(['image' => 'Failed to upload the image.'])->withInput();
}

Expand All @@ -89,8 +88,7 @@ public function store(Request $request)
'image' => $imageName,
]);

// Ensure area and user association
$event->area()->associate($request->input('area'));
// Ensure user association
$event->user()->associate($user);
$event->save();

Expand Down Expand Up @@ -121,7 +119,6 @@ public function update(Request $request, Event $event)
{
$data = $this->validate($request, [
'calendar_id' => 'required|exists:calendars,id',
'area' => 'required|exists:areas,id',
'title' => 'required|string|max:255',
'short_description' => 'required|max:280',
'long_description' => 'required',
Expand Down Expand Up @@ -182,7 +179,6 @@ public function update(Request $request, Event $event)
'image' => $imageURL,
]);

$event->area()->associate($request->input('area'));
$event->user()->associate($user);
$event->save();

Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function login(Request $request)

return redirect()->away($authorizationUrl);
} elseif ($request->input('state') !== session()->pull('oauthstate')) {
return redirect()->route('welcome')->withError('Something went wrong, please try again (state mismatch).');
return redirect()->route('home')->withError('Something went wrong, please try again (state mismatch).');
} else {
return $this->verifyLogin($request);
}
Expand All @@ -81,7 +81,7 @@ protected function verifyLogin(Request $request)
'code' => $request->input('code'),
]);
} catch (IdentityProviderException $e) {
return redirect()->route('welcome')->withError('Authentication error: ' . $e->getMessage());
return redirect()->route('home')->withError('Authentication error: ' . $e->getMessage());
}

$resourceOwner = json_decode(json_encode($this->provider->getResourceOwner($accessToken)->toArray()));
Expand All @@ -93,7 +93,7 @@ protected function verifyLogin(Request $request)
!$data['first_name'] ||
!$data['last_name']
) {
return redirect()->route('welcome')->withError('Missing data from sign-in request. You need to grant all permissions.');
return redirect()->route('home')->withError('Missing data from sign-in request. You need to grant all permissions.');
}

$account = $this->completeLogin($data, $accessToken);
Expand Down Expand Up @@ -133,14 +133,14 @@ protected function completeLogin(array $data, $token)
}

/**
* Log out he user and redirect to welcome page
* Log out he user and redirect to home page
*
* @return \Illuminate\Http\RedirectResponse
*/
public function logout()
{
auth()->logout();

return redirect(route('welcome'))->withSuccess('You have been successfully logged out');
return redirect(route('home'))->withSuccess('You have been successfully logged out');
}
}
19 changes: 5 additions & 14 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers;

use App\Models\Area;
use App\Models\Calendar;
use App\Models\Event;
use Carbon\Carbon;
Expand Down Expand Up @@ -33,11 +32,9 @@ public function create()
{
$this->authorize('create', Event::class);

$areas = Area::all();

$calendars = Calendar::all();

return view('events.create', compact('areas', 'calendars'));
return view('events.create', compact('calendars'));
}

/**
Expand All @@ -49,7 +46,6 @@ public function store(Request $request)

$this->validate($request, [
'calendar_id' => 'required|exists:calendars,id',
'area' => 'required|exists:areas,id',
'title' => 'required|string|max:255',
'short_description' => 'required|max:280',
'long_description' => 'required',
Expand Down Expand Up @@ -78,7 +74,7 @@ public function store(Request $request)
$storedPath = $image->storeAs('banners', $imageName, 'public');

// Check if the image was successfully uploaded
if (!Storage::disk('public')->exists($storedPath)) {
if ($storedPath && !Storage::disk('public')->exists($storedPath)) {
return back()->withErrors(['image' => 'Failed to upload the image.'])->withInput();
}

Expand All @@ -97,8 +93,7 @@ public function store(Request $request)
'image' => $imageName,
]);

// Ensure area and user association
$event->area()->associate($request->input('area'));
// Ensure user association
$event->user()->associate(\Auth::user());
$event->save();

Expand Down Expand Up @@ -128,11 +123,9 @@ public function edit(Event $event)
{
$this->authorize('update', $event);

$areas = Area::all();

$calendars = Calendar::all();

return view('events.edit', compact('areas', 'calendars', 'event'));
return view('events.edit', compact('calendars', 'event'));
}

/**
Expand All @@ -144,7 +137,6 @@ public function update(Request $request, Event $event)

$this->validate($request, [
'calendar_id' => 'required|exists:calendars,id',
'area' => 'required|exists:areas,id',
'title' => 'required|string|max:255',
'short_description' => 'required|max:280',
'long_description' => 'required',
Expand Down Expand Up @@ -201,8 +193,7 @@ public function update(Request $request, Event $event)
'image' => $imageURL,
]);

// Ensure area and user association
$event->area()->associate($request->input('area'));
// Ensure user association
$event->user()->associate(\Auth::user());

// Save the event before handling recurrences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Models\Event;
use Carbon\Carbon;

class WelcomeController extends Controller
class HomeController extends Controller
{
/**
* Show the landing page if not logged in, or redirect if logged in.
Expand All @@ -15,14 +15,14 @@ class WelcomeController extends Controller
*/
public function index()
{
$now = Carbon::now();
$UpcomingEvents = Event::where('start_date', '>=', $now)
->orderBy('start_date', 'asc')
->get()
->filter(function ($event) {
return $event->calendar->public;
// Get events with start date today and the connected Calendar is public
$upcomingEvents = Event::where('start_date', '>=', Carbon::today())
->whereHas('calendar', function($query) {
$query->where('public', 1);
})
->take(5);
->orderBy('start_date', 'asc')
->limit(5)
->get();

$calendar = Calendar::where('public', 1)->first();

Expand All @@ -42,6 +42,6 @@ public function index()
}


return view('welcome', compact('UpcomingEvents', 'events', 'calendar'));
return view('home', compact('upcomingEvents', 'events', 'calendar'));
}
}
5 changes: 1 addition & 4 deletions app/Http/Controllers/StaffingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers;

use App\Models\Area;
use App\Models\Staffing;
use Carbon\Carbon;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -63,11 +62,9 @@ public function create()
}
}

$areas = Area::all();

$channels = $this->getGuildChannels();

return view('staffing.create', compact('allData', 'areas', 'channels'));
return view('staffing.create', compact('allData', 'channels'));
}

protected function getGuildChannels() {
Expand Down
32 changes: 9 additions & 23 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers;

use App\Models\Area;
use App\Models\Group;
use App\Models\User;
use Carbon\Carbon;
Expand Down Expand Up @@ -36,11 +35,9 @@ public function show(User $user)
return \Auth::user()->can('view', $event);
});

$areas = Area::all();

$groups = Group::all();

return view('users.show', compact('user', 'events', 'areas', 'groups'));
return view('users.show', compact('user', 'events', 'groups'));
}

/**
Expand All @@ -53,14 +50,8 @@ public function update(Request $request, User $user)
$permissions = [];

// Generate a list of possible validations
foreach (Area::all() as $area) {
foreach (Group::all() as $group) {
// Only process ranks the user is allowed to change
$this->authorize('updateGroup', [$user, $group, $area]);

$key = $area->id . '_' . $group->name;
$permissions[$key] = '';
}
foreach (Group::all() as $group) {
$permissions[$group->name] = '';
}

// Valiate and allow these fields, then loop through permissions to set the final data set
Expand All @@ -69,27 +60,22 @@ public function update(Request $request, User $user)
isset($data[$key]) ? $permissions[$key] = true : $permissions[$key] = false;
}

//dd($permissions);

// Check and update the permissions
foreach ($permissions as $key => $value) {
$str = explode('_', $key);

$area = Area::where('id', $str[0])->get()->first();
$group = Group::where('name', $str[1])->get()->first();
$group = Group::where('name', $key)->get()->first();

// Check if permission is not set, and set it or other way around.
if ($user->groups()->where('area_id', $area->id)->where('group_id', $group->id)->get()->count() == 0) {
if ($user->groups()->where('group_id', $group->id)->get()->count() == 0) {
if ($value == true) {
$this->authorize('updateGroup', [$user, $group, $area]);

// Attach the new permission
$user->groups()->attach($group, ['area_id' => $area->id, 'inserted_by' => \Auth::user()->id]);
$user->groups()->attach($group, ['inserted_by' => \Auth::user()->id]);
}
} else {
if ($value == false) {
$this->authorize('updateGroup', [$user, $group, $area]);

// Detach the permission
$user->groups()->wherePivot('area_id', $area->id)->wherePivot('group_id', $group->id)->detach();
$user->groups()->wherePivot('group_id', $group->id)->detach();
}
}
}
Expand Down
30 changes: 0 additions & 30 deletions app/Models/Area.php

This file was deleted.

11 changes: 2 additions & 9 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class Event extends Model
'recurrence_end_date',
'published',
'image',
'user_id',
'area_id'
'user_id'
];

protected $dates = [
Expand All @@ -43,11 +42,6 @@ public function user()
return $this->belongsTo(User::class);
}

public function area()
{
return $this->belongsTo(Area::class);
}

public function calendar()
{
return $this->belongsTo(Calendar::class);
Expand Down Expand Up @@ -124,8 +118,7 @@ public function generateRecurrences()
'recurrence_unit' => $this->recurrence_unit,
'recurrence_end_date' => $this->recurrence_end_date,
'image' => $this->image,
'user_id' => $this->user_id,
'area_id' => $this->area_id,
'user_id' => $this->user_id
]);

// Move to the next recurrence date
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class Group extends Model

public function users()
{
return $this->belongsToMany(User::class, 'permissions')->withPivot('area_id')->withTimestamps();
return $this->belongsToMany(User::class, 'permissions');
}
}
Loading

0 comments on commit d592e92

Please sign in to comment.