Changes to Authorisation for users to edit systems, minor cosmetic fixes and more logging

This commit is contained in:
Deon George 2021-12-29 13:44:27 +11:00
parent 10afd6f3a4
commit fa2ac9a656
6 changed files with 24 additions and 5 deletions

View File

@ -219,6 +219,8 @@ class Message extends FTNBase
*/
public static function parseMessage(string $msg,Zone $zone=NULL): self
{
Log::info(sprintf('%s:Processing message [%d] bytes from zone [%d]',self::LOGKEY,strlen($msg),$zone?->zone_id));
$o = new self($zone);
try {

View File

@ -422,10 +422,14 @@ class Packet extends FTNBase implements \Iterator, \Countable
*/
private function parseMessage(string $message): void
{
Log::info(sprintf('%s:Processing message [%d] bytes',self::LOGKEY,strlen($message)));
$msg = Message::parseMessage($message,$this->zone);
// If the message is invalid, we'll ignore it
if ($msg->errors) {
Log::info(sprintf('%s:- Message has errors',self::LOGKEY));
// If the from address doenst exist, we'll create a new entry
if ($msg->errors->messages()->has('from')) {
$e = NULL;

View File

@ -42,7 +42,7 @@ final class Echomail extends Model implements Packet
// @todo if the message is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one)
static::created(function($model) {
if (! $model->echoarea_id) {
Log::alert(sprintf('%s:- Message has no echo area, no exporting',self::LOGKEY,$model->id));
Log::alert(sprintf('%s:- Message has no echo area, not exporting',self::LOGKEY,$model->id));
return;
}

View File

@ -13,12 +13,25 @@ class SystemPolicy
/**
* Determine whether the user can update the model.
*
* A user can update a system if they are the user of it and it has no addresses.
* If it has addresses, at least one of the addresses must have been validated.
* (The assumption is, if a system has multiple addresses, they would be valid, or an admin can remove them.)
*
* @param \App\Models\User $user
* @param \App\Models\System $system
* @return \Illuminate\Auth\Access\Response|bool
*/
public function update(User $user, System $system)
public function update(User $user, System $system): bool
{
return (! $system->exists) || $system->users->contains($user) || $user->isAdmin();
// Site Admins can always edit
if ($user->isAdmin())
return TRUE;
// If it doesnt exist, then its a false.
if (! $system->exists)
return FALSE;
return $system->users->contains($user)
&& (($system->addresses->count() == 0) || ($system->addresses->where('validated',TRUE)->count()));
}
}

View File

@ -113,7 +113,7 @@
text: 'Echomail Statistics'
},
subtitle: {
text: '{{ sprintf('%s - %s',\Carbon\Carbon::now()->subMonths(6)->format('Y-m-d'),\Carbon\Carbon::now()->format('Y-m-d')) }}'
text: '{{ sprintf('%s - %s',\Carbon\Carbon::now()->subMonths(6)->startOfMonth()->format('Y-m-d'),\Carbon\Carbon::now()->format('Y-m-d')) }}'
},
xAxis: {
type: 'category'

View File

@ -94,7 +94,7 @@
FROM: <strong class="highlight">{!! \App\Classes\FTN\Message::tr($msg->user_from) !!}</strong> (<strong class="highlight">{{ $msg->fftn }}</strong>)
</div>
<div class="col-4">
TO: <strong class="highlight">{!! \App\Classes\FTN\Message::tr($msg->user_to) !!}</strong> XX(<strong class="highlight">{{ $msg->tftn }}</strong>)
TO: <strong class="highlight">{!! \App\Classes\FTN\Message::tr($msg->user_to) !!}</strong>@if($msg->isNetmail()) (<strong class="highlight">{{ $msg->tftn }}</strong>) @endif
</div>
</div>