Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20240103 bump #894

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ USE_OLLAMA=false
OLLAMA_MODEL=llama3.2
OLLAMA_URL=

OHDEAR_ENABLED=false
OHDEAR_URL=""

ORCID_USE_SANDBOX=false
ORCID_REDIRECT_URI="${FRONTEND_URL}api/orcid/callback"
ORCID_CLIENT_ID=""
Expand Down
30 changes: 30 additions & 0 deletions app/Http/Controllers/Announcement/CheckAnnouncementController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Controllers\Announcement;

use App\Http\Controllers\Controller;
use App\Http\Resources\AnnouncementResource;
use App\Models\Announcement;
use App\Traits\LocaleTrait;
use Illuminate\Http\Request;

class CheckAnnouncementController extends Controller
{
use LocaleTrait;

/**
* Display active announcements.
*/
public function __invoke(Request $request)
{

$announcement = Announcement::active()->orderBy('start_at', 'desc')->get();

if ($announcement->isEmpty()) {
return response()->json([], 204);
}

return AnnouncementResource::collection($announcement);

}
}
38 changes: 0 additions & 38 deletions app/Http/Controllers/OhDear/CheckStatusPageController.php

This file was deleted.

36 changes: 36 additions & 0 deletions app/Http/Resources/AnnouncementResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
* @mixin \App\Models\Announcement
*/
class AnnouncementResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'data' => [
'id' => $this->id,
'title_en' => $this->title_en,
'title_fr' => $this->title_fr,
'text_en' => $this->text_en,
'text_fr' => $this->text_fr,
'start_at' => $this->start_at,
'end_at' => $this->end_at,
],
'can' => [
'update' => false,
'delete' => false,
],
];
}
}
35 changes: 35 additions & 0 deletions app/Models/Announcement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Announcement extends Model
{
/** @use HasFactory<\Database\Factories\AnnouncementFactory> */
use HasFactory;

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
public function casts(): array
{
return [
'start_at' => 'datetime',
'end_at' => 'datetime',
];
}

/**
* Return active announcements
*/
public function scopeActive(Builder $query)
{
return $query->where('start_at', '<=', now())
->where('end_at', '>=', now());
}
}
50 changes: 50 additions & 0 deletions app/Policies/AnnouncementPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Policies;

use App\Enums\Permissions\UserRole;
use App\Models\Announcement;
use App\Models\User;

class AnnouncementPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->hasRole(UserRole::ADMIN);
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, Announcement $announcement): bool
{
return $user->hasRole(UserRole::ADMIN);
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->hasRole(UserRole::ADMIN);
}

/**
* Determine whether the user can update the model.
*/
public function update(User $user, Announcement $announcement): bool
{
return $user->hasRole(UserRole::ADMIN);
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Announcement $announcement): bool
{
return $user->hasRole(UserRole::ADMIN);
}
}
Loading
Loading