Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
refactor: database overhaul (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoaureliocardoso committed Nov 30, 2022
1 parent 1318636 commit 099a7d3
Show file tree
Hide file tree
Showing 207 changed files with 4,775 additions and 3,663 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ COPY ./.docker/nginx.conf /etc/nginx/nginx.conf
# Installing PHP
RUN apk add --no-cache php81 php81-fpm

RUN ln -s /usr/bin/php81 /usr/bin/php
# # RUN ln -s /usr/bin/php81 /usr/bin/php
RUN ln -s /usr/sbin/php-fpm81 /usr/sbin/php-fpm

# Defining ENV variables which will be used in configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ class SendInstitutionalLoginConfirmationRequiredEvent extends Command
*/
protected $description = 'Send institutional login confirmation required event';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand Down
2 changes: 1 addition & 1 deletion app/Enums/CallStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function description(): string
/**
* @return array<string, string>
*/
public function jsonSerialize():array
public function jsonSerialize(): array
{
return [
'name' => $this->name,
Expand Down
35 changes: 35 additions & 0 deletions app/Events/BondUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Events;

use App\Models\Bond;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class BondUpdated
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(public Bond $bond)
{
}

/**
* Get the channels the event should broadcast on.
*
* @return Channel|array<int, mixed>
*/
public function broadcastOn(): Channel|array
{
return new PrivateChannel('channel-name');
}
}
9 changes: 7 additions & 2 deletions app/Gates/BondGates.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Gates;

use App\Models\Bond;
use App\Models\Course;
use App\Models\User;
use Illuminate\Support\Facades\Gate;

Expand Down Expand Up @@ -59,7 +60,9 @@ public static function define(): void
}

//coord on this course then ok.
return Gate::forUser($user)->any(['isCoord-course_id'], $bond->course_id);
/** @var Course|null $bondCourse */
$bondCourse = $bond->getAttribute('course');
return Gate::forUser($user)->any(['isCoord-course_id'], $bondCourse?->getAttribute('id'));
});

Gate::define('bond-updateTo', static function (User $user, Bond $bond, ?int $course_id) {
Expand All @@ -73,7 +76,9 @@ public static function define(): void
}

//coord on this course then ok.
return Gate::forUser($user)->any(['isCoord-course_id'], $bond->course_id) && Gate::forUser($user)->any(['isCoord-course_id'], $course_id);
/** @var Course|null $bondCourse */
$bondCourse = $bond->getAttribute('course');
return Gate::forUser($user)->any(['isCoord-course_id'], $bondCourse?->getAttribute('id')) && Gate::forUser($user)->any(['isCoord-course_id'], $course_id);
});

Gate::define('bond-destroy', static function ($user) {
Expand Down
24 changes: 8 additions & 16 deletions app/Gates/GenericGates.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,19 @@ public static function define(): void

/* define a coord with course_id */
Gate::define('isCoord-course_id', static function (User $user, int $course_id) {
/**
* @var User $currentUser
*/
/** @var User $currentUser */
$currentUser = auth()->user();
//need to have session Responsibility active.
$currentResponsibility = $currentUser->getCurrentResponsibility();
/** @var Responsibility $currentResponsibility */
$currentResponsibility = session('loggedInUser.currentResponsibility');
if (! $currentResponsibility instanceof \App\Models\Responsibility) {
return false;
}

/**
* @var UserType $currentUserType
*/
/** @var UserType $currentUserType */
$currentUserType = $currentResponsibility->userType;
//if currentResponsibility (Responsibility) is coord, ok
$is_coord = $currentUserType->acronym === 'coord';
// Issue #36: For some reason, sometimes $course_id isn't integer, but string... Fixed with typed parameter.
$course_id_match = $currentResponsibility->course_id === $course_id;

return $is_coord && $course_id_match;
Expand All @@ -104,16 +100,14 @@ private static function checkGenericRoleUta(string $acronym): bool
//return $user->userType->acronym == $acronym;

//need to have session Responsibility active.
/** @var Responsibility */
/** @var Responsibility $currentResponsibility */
$currentResponsibility = session('loggedInUser.currentResponsibility');

if (! $currentResponsibility instanceof \App\Models\Responsibility) {
return false;
}

/**
* @var UserType $currentUserType
*/
/** @var UserType $currentUserType */
$currentUserType = $currentResponsibility->userType;

//if currentResponsibility (Responsibility) is $acronym, ok
Expand All @@ -123,16 +117,14 @@ private static function checkGenericRoleUta(string $acronym): bool
private static function checkGlobalRoleUta(string $acronym): bool
{
//need to have session Responsibility active.
/** @var Responsibility */
/** @var Responsibility $currentResponsibility */
$currentResponsibility = session('loggedInUser.currentResponsibility');

if (! $currentResponsibility instanceof \App\Models\Responsibility) {
return false;
}

/**
* @var UserType $currentUserType
*/
/** @var UserType $currentUserType */
$currentUserType = $currentResponsibility->userType;
//if currentResponsibility (Responsibility) is $acronym, ok
$acronymMatch = $currentUserType->acronym === $acronym;
Expand Down
49 changes: 0 additions & 49 deletions app/Helpers/DocumentRepositoryHelper.php

This file was deleted.

Loading

0 comments on commit 099a7d3

Please sign in to comment.