Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2024-11-13 22:39:01 +00:00
commit 3bf33aa682
4 changed files with 29 additions and 25 deletions

View file

@ -288,33 +288,31 @@ class UsersController extends Controller
$user->password = bcrypt($request->input('password')); $user->password = bcrypt($request->input('password'));
} }
// Update the location of any assets checked out to this user // Update the location of any assets checked out to this user
Asset::where('assigned_type', User::class) Asset::where('assigned_type', User::class)
->where('assigned_to', $user->id) ->where('assigned_to', $user->id)
->update(['location_id' => $user->location_id]); ->update(['location_id' => $user->location_id]);
$permissions_array = $request->input('permission'); $permissions_array = $request->input('permission');
// Strip out the superuser permission if the user isn't a superadmin
if (! auth()->user()->isSuperUser()) {
unset($permissions_array['superuser']);
$permissions_array['superuser'] = $orig_superuser;
}
// Strip out the superuser permission if the user isn't a superadmin $user->permissions = json_encode($permissions_array);
if (! auth()->user()->isSuperUser()) {
unset($permissions_array['superuser']);
$permissions_array['superuser'] = $orig_superuser;
}
$user->permissions = json_encode($permissions_array); // Handle uploaded avatar
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar');
session()->put(['redirect_option' => $request->get('redirect_option')]);
// Handle uploaded avatar if ($user->save()) {
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar'); // Redirect to the user page
session()->put(['redirect_option' => $request->get('redirect_option')]); return redirect()->to(Helper::getRedirectOption($request, $user->id, 'Users'))
->with('success', trans('admin/users/message.success.update'));
if ($user->save()) { }
// Redirect to the user page return redirect()->back()->withInput()->withErrors($user->getErrors());
return redirect()->to(Helper::getRedirectOption($request, $user->id, 'Users'))
->with('success', trans('admin/users/message.success.update'));
}
return redirect()->back()->withInput()->withErrors($user->getErrors());
} }
/** /**

View file

@ -31,6 +31,7 @@ use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Exception; use Exception;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Osama\LaravelTeamsNotification\TeamsNotification; use Osama\LaravelTeamsNotification\TeamsNotification;
class CheckoutableListener class CheckoutableListener
@ -94,7 +95,7 @@ class CheckoutableListener
// Send Webhook notification // Send Webhook notification
try{ try{
if ($this->shouldSendWebhookNotification()) { if ($this->shouldSendWebhookNotification()) {
if (Setting::getSettings()->webhook_selected === 'microsoft') { if ($this->newMicrosoftTeamsWebhookEnabled()) {
$message = $this->getCheckoutNotification($event)->toMicrosoftTeams(); $message = $this->getCheckoutNotification($event)->toMicrosoftTeams();
$notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint); $notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint);
$notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams $notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams
@ -176,7 +177,7 @@ class CheckoutableListener
// Send Webhook notification // Send Webhook notification
try { try {
if ($this->shouldSendWebhookNotification()) { if ($this->shouldSendWebhookNotification()) {
if (Setting::getSettings()->webhook_selected === 'microsoft') { if ($this->newMicrosoftTeamsWebhookEnabled()) {
$message = $this->getCheckinNotification($event)->toMicrosoftTeams(); $message = $this->getCheckinNotification($event)->toMicrosoftTeams();
$notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint); $notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint);
$notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams $notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams
@ -345,4 +346,9 @@ class CheckoutableListener
} }
return (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email()); return (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email());
} }
private function newMicrosoftTeamsWebhookEnabled(): bool
{
return Setting::getSettings()->webhook_selected === 'microsoft' && Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows');
}
} }

View file

@ -114,10 +114,9 @@ class SlackSettingsForm extends Component
$this->webhook_channel = '#NA'; $this->webhook_channel = '#NA';
} }
} }
public function updatedwebhookEndpoint() {
$this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows'); public function updatedwebhookEndpoint()
} {
public function updatedwebhookEndpoint() {
$this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows'); $this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows');
} }

View file

@ -111,7 +111,8 @@ class CheckoutAssetNotification extends Notification
->content($note); ->content($note);
}); });
} }
public function toMicrosoftTeams() : array
public function toMicrosoftTeams()
{ {
$target = $this->target; $target = $this->target;
$admin = $this->admin; $admin = $this->admin;