Skip to content

Roles with time constraints #566

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

Draft
wants to merge 11 commits into
base: development
Choose a base branch
from
2 changes: 1 addition & 1 deletion app/Exports/UsersSheets/CollegistsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function map($user): array
return [
'=HYPERLINK("'.route('users.show', ['user' => $user->id]).'", "'.$user->name.'")',
$user->educationalInformation?->neptun,
$user->isResident() ? 'Bentlakó' : ($user->isExtern() ? 'Bejáró' : ($user->isAlumni() ? "Alumni" : ($user->isTenant() ? "Vendég" : ""))),
$user->collegistStatus(),
$user->getStatus($this->semester)?->translatedStatus(),
$user->email,
$user->educationalInformation?->email,
Expand Down
2 changes: 1 addition & 1 deletion app/Exports/UsersSheets/SemesterEvaluationExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function map($evaluation): array
$user->educationalInformation?->neptun,
implode(" \n", $user->faculties->pluck('name')->toArray()),
implode(" \n", $user->workshops->pluck('name')->toArray()),
$user->isResident() ? 'Bentlakó' : ($user->isExtern() ? 'Bejáró' : ($user->isAlumni() ? "Alumni" : ($user->isTenant() ? "Vendég" : ""))),
$user->collegistStatus(),
$evaluation->resign_residency ? 'Igen' : '',
$user->getStatus($evaluation->semester)?->translatedStatus(),
$user->getStatus($evaluation->semester->succ())?->translatedStatus(),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function updateApplicationPeriod(Request $request): RedirectResponse
*/
public function showApplicationForm(Request $request): View|RedirectResponse
{
if (user()->hasRole(Role::get(Role::TENANT))) {
if (user()->isTenant()) {
//let the user delete their tenant status
return view('user.update_tenant_status');
}
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Secretariat/GuestsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public function index()
$users = User::withoutGlobalScope('verified')
->where('verified', false)
->whereHas('roles', function (Builder $query) {
$query->where('name', Role::TENANT);
$query->where('name', Role::RESIDENT);
})
->whereDoesntHave('roles', function (Builder $query) {
$query->where('name', Role::COLLEGIST);
})
->with(['personalInformation'])
->get();
Expand All @@ -55,7 +58,7 @@ public function accept(Request $request)
}

$user->update(['verified' => true]);
if ($user->hasRole(Role::TENANT)) {
if ($user->isTenant()) {
$date = min(Carbon::now()->addMonths(6), Carbon::parse($user->personalInformation->tenant_until));
$user->internetAccess()->update(['has_internet_until' => $date]);
$user->personalInformation()->update(['tenant_until' => $date]);
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Secretariat/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ public function tenantToApplicant()
$user = user();
$user->personalInformation()->update(['tenant_until' => null]);
$user->update(['verified' => false]);
$user->removeRole(Role::get(Role::TENANT));
$user->setExtern();
$user->addRole(Role::collegist());
$user->application()->create();
Cache::forget('collegists');
return back();
Expand Down
17 changes: 12 additions & 5 deletions app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Role extends Model
// General roles
public const SYS_ADMIN = 'sys-admin';
public const COLLEGIST = 'collegist';
public const TENANT = 'tenant';
public const WORKSHOP_ADMINISTRATOR = 'workshop-administrator';
public const WORKSHOP_LEADER = 'workshop-leader';
public const APPLICATION_COMMITTEE_MEMBER = 'application-committee';
Expand Down Expand Up @@ -104,15 +103,15 @@ class Role extends Model
// Module-related roles
public const PRINTER = 'printer';

//collegist related roles
// The resident role is indefinite for 'true' residents
// and has an expiry date for resident-externs.
// Tenants also have this role.
public const RESIDENT = 'resident';
public const EXTERN = 'extern';

// all roles
public const ALL = [
self::SYS_ADMIN,
self::COLLEGIST,
self::TENANT,
self::WORKSHOP_ADMINISTRATOR,
self::WORKSHOP_LEADER,
self::APPLICATION_COMMITTEE_MEMBER,
Expand Down Expand Up @@ -248,6 +247,14 @@ public static function collegist(): Role
return self::where('name', self::COLLEGIST)->first();
}

/**
* Returns the resident role.
*/
public static function resident(): Role
{
return self::where('name', self::RESIDENT)->first();
}

/**
* Returns the role for the students council.
*/
Expand Down Expand Up @@ -298,7 +305,7 @@ public function color(): string
return match ($this->name) {
self::SYS_ADMIN => 'pink',
self::COLLEGIST => 'coli',
self::TENANT => 'coli blue',
self::RESIDENT => 'coli blue',
self::WORKSHOP_ADMINISTRATOR => 'purple',
self::WORKSHOP_LEADER => 'deep-purple',
self::SECRETARY => 'indigo',
Expand Down
9 changes: 8 additions & 1 deletion app/Models/RoleUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ class RoleUser extends Pivot
{
protected $table = 'role_users';

protected $fillable = ['workshop_id', 'object_id', 'user_id', 'role_id'];
protected $fillable = ['workshop_id', 'object_id', 'user_id', 'role_id', 'valid_from', 'valid_until'];

/**
* We don't need the default timestamps.
*
* @var bool
*/
public $timestamps = false;

/**
* Always eager load workshop and object relations.
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Semester.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function isActive($user)
*/
public function transactions(): HasMany
{
return $this->hasMany(App\Models\Transaction::class, 'semester_id');
return $this->hasMany(\App\Models\Transaction::class, 'semester_id');
}

public function communityServices(): HasMany
Expand All @@ -247,7 +247,7 @@ public function transactionsInCheckout(Checkout $checkout)
*/
public function workshopBalances(): HasMany
{
return $this->hasMany(App\Models\WorkshopBalance::class);
return $this->hasMany(\App\Models\WorkshopBalance::class);
}

/**
Expand Down
Loading
Loading