Roles check for alerts
This commit is contained in:
parent
a1d4c04bd3
commit
da0f1aa362
|
@ -7,6 +7,7 @@ function alertsRouter (FastRoute\RouteCollector $r) {
|
|||
'',
|
||||
function ($vars) {
|
||||
global $db;
|
||||
requireLogin();
|
||||
$alerts = $db->select("SELECT * FROM `".DB_PREFIX."_alerts`");
|
||||
if(is_null($alerts)) $alerts = [];
|
||||
foreach($alerts as &$alert) {
|
||||
|
@ -27,7 +28,13 @@ function alertsRouter (FastRoute\RouteCollector $r) {
|
|||
'POST',
|
||||
'',
|
||||
function ($vars) {
|
||||
global $db;
|
||||
global $db, $users;
|
||||
requireLogin();
|
||||
$users->online_time_update();
|
||||
if(!$users->hasRole(Role::SUPER_EDITOR)) {
|
||||
apiResponse(["error" => "access denied"]);
|
||||
return;
|
||||
}
|
||||
$crew = [
|
||||
[
|
||||
"name" => "Nome1",
|
||||
|
@ -62,6 +69,7 @@ function alertsRouter (FastRoute\RouteCollector $r) {
|
|||
'/{id:\d+}',
|
||||
function ($vars) {
|
||||
global $db;
|
||||
requireLogin();
|
||||
$alert = $db->selectRow("SELECT * FROM `".DB_PREFIX."_alerts` WHERE `id` = :id", [":id" => $vars["id"]]);
|
||||
if(is_null($alert)) {
|
||||
apiResponse(["error" => "alert not found"]);
|
||||
|
@ -76,7 +84,13 @@ function alertsRouter (FastRoute\RouteCollector $r) {
|
|||
'POST',
|
||||
'/{id:\d+}/settings',
|
||||
function ($vars) {
|
||||
global $db;
|
||||
global $db, $users;
|
||||
requireLogin();
|
||||
$users->online_time_update();
|
||||
if(!$users->hasRole(Role::SUPER_EDITOR)) {
|
||||
apiResponse(["error" => "access denied"]);
|
||||
return;
|
||||
}
|
||||
$db->update(
|
||||
DB_PREFIX."_alerts",
|
||||
[
|
||||
|
@ -93,7 +107,13 @@ function alertsRouter (FastRoute\RouteCollector $r) {
|
|||
'DELETE',
|
||||
'/{id:\d+}',
|
||||
function ($vars) {
|
||||
global $db;
|
||||
global $db, $users;
|
||||
requireLogin();
|
||||
$users->online_time_update();
|
||||
if(!$users->hasRole(Role::SUPER_EDITOR)) {
|
||||
apiResponse(["error" => "access denied"]);
|
||||
return;
|
||||
}
|
||||
$db->delete(
|
||||
DB_PREFIX."_alerts",
|
||||
[
|
||||
|
|
|
@ -35,20 +35,28 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button type="button" class="btn btn-primary mb-2" (click)="isAdvancedCollapsed = !isAdvancedCollapsed"
|
||||
<ng-container *ngIf="auth.profile.hasRole('SUPER_EDITOR')">
|
||||
<button type="button" class="btn btn-primary mb-2" (click)="isAdvancedCollapsed = !isAdvancedCollapsed"
|
||||
[attr.aria-expanded]="!isAdvancedCollapsed" aria-controls="collapseBasic">
|
||||
<ng-container *ngIf="isAdvancedCollapsed">Mostra impostazioni avanzate</ng-container>
|
||||
<ng-container *ngIf="!isAdvancedCollapsed">Nascondi impostazioni avanzate</ng-container>
|
||||
</button>
|
||||
<div [collapse]="isAdvancedCollapsed" [isAnimated]="true">
|
||||
<div class="well well-lg card card-block card-header">
|
||||
<label for="details" class="form-label">Dettagli allerta</label>
|
||||
<textarea class="form-control" id="details" rows="3" [(ngModel)]="notes"></textarea>
|
||||
<button class="btn btn-secondary mt-2" (click)="saveAlertSettings()">Salva</button>
|
||||
<ng-container *ngIf="isAdvancedCollapsed">Mostra impostazioni avanzate</ng-container>
|
||||
<ng-container *ngIf="!isAdvancedCollapsed">Nascondi impostazioni avanzate</ng-container>
|
||||
</button>
|
||||
<div [collapse]="isAdvancedCollapsed" [isAnimated]="true">
|
||||
<div class="well well-lg card card-block card-header">
|
||||
<label for="details" class="form-label">Dettagli allerta</label>
|
||||
<textarea class="form-control" id="details" rows="3" [(ngModel)]="notes"></textarea>
|
||||
<button class="btn btn-secondary mt-2" (click)="saveAlertSettings()" *ngIf="auth.profile.hasRole('SUPER_EDITOR')">Salva</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="!auth.profile.hasRole('SUPER_EDITOR')">
|
||||
<div class="well well-lg card card-block card-header">
|
||||
<h5>Dettagli allerta</h5>
|
||||
<h2>{{ notes }}</h2>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-danger" (click)="deleteAlert()">Rimuovi allerta corrente <i class="fas fa-exclamation-triangle"></i></button>
|
||||
<button type="button" class="btn btn-danger" (click)="deleteAlert()" *ngIf="auth.profile.hasRole('SUPER_EDITOR')">Rimuovi allerta corrente <i class="fas fa-exclamation-triangle"></i></button>
|
||||
<button type="button" class="btn btn-secondary" (click)="bsModalRef.hide()">{{ 'close'|translate }}</button>
|
||||
</div>
|
|
@ -1,6 +1,7 @@
|
|||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { BsModalRef } from 'ngx-bootstrap/modal';
|
||||
import { ApiClientService } from 'src/app/_services/api-client.service';
|
||||
import { AuthService } from 'src/app/_services/auth.service';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import Swal from 'sweetalert2';
|
||||
|
||||
|
@ -19,7 +20,12 @@ export class ModalAlertComponent implements OnInit, OnDestroy {
|
|||
|
||||
notes = "";
|
||||
|
||||
constructor(public bsModalRef: BsModalRef, private api: ApiClientService, private toastr: ToastrService) { }
|
||||
constructor(
|
||||
public bsModalRef: BsModalRef,
|
||||
private api: ApiClientService,
|
||||
public auth: AuthService,
|
||||
private toastr: ToastrService
|
||||
) { }
|
||||
|
||||
loadResponsesData() {
|
||||
this.api.get(`alerts/${this.id}`).then((response) => {
|
||||
|
@ -50,6 +56,7 @@ export class ModalAlertComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
saveAlertSettings() {
|
||||
if(!this.auth.profile.hasRole('SUPER_EDITOR')) return;
|
||||
this.api.post(`alerts/${this.id}/settings`, {
|
||||
notes: this.notes
|
||||
}).then((response) => {
|
||||
|
@ -58,6 +65,7 @@ export class ModalAlertComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
deleteAlert() {
|
||||
if(!this.auth.profile.hasRole('SUPER_EDITOR')) return;
|
||||
Swal.fire({
|
||||
title: "Sei sicuro di voler ritirare l'allarme?",
|
||||
text: "I vigili verranno avvisati dell'azione",
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<owner-image></owner-image>
|
||||
<div class="text-center">
|
||||
<div class="text-center" *ngIf="auth.profile.hasRole('SUPER_EDITOR')">
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-danger" (click)="addAlertFull()">
|
||||
🚒 Richiedi squadra completa
|
||||
|
|
|
@ -25,7 +25,7 @@ export class ListComponent implements OnInit, OnDestroy {
|
|||
|
||||
constructor(
|
||||
private api: ApiClientService,
|
||||
private auth: AuthService,
|
||||
public auth: AuthService,
|
||||
private toastr: ToastrService,
|
||||
private modalService: BsModalService,
|
||||
private translate: TranslateService
|
||||
|
@ -72,6 +72,7 @@ export class ListComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
addAlertFull() {
|
||||
if(!this.auth.profile.hasRole('SUPER_EDITOR')) return;
|
||||
this.api.post("alerts", {
|
||||
type: "full"
|
||||
}).then((response) => {
|
||||
|
@ -85,6 +86,7 @@ export class ListComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
addAlertSupport() {
|
||||
if(!this.auth.profile.hasRole('SUPER_EDITOR')) return;
|
||||
this.api.post("alerts", {
|
||||
type: "support"
|
||||
}).then((response) => {
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
<alert type="danger" *ngIf="alerts.length > 0">
|
||||
<strong>Attenzione!</strong> Allertamento in corso.<br>
|
||||
<ng-container *ngIf="alerts.length == 1">
|
||||
Emergenza attuale: <a (click)="openAlert(alerts[0]['id'])"><b>{{ alerts[0]["created_at"] | date:'dd/MM/YYYY, HH:mm:ss' }}</b> (premi per ulteriori informazioni)</a>
|
||||
Emergenza attuale: <a (click)="openAlert(alerts[0]['id'])"><b>{{ alerts[0]["created_at"] | date:'dd/MM/YYYY, HH:mm:ss' }}</b> (premere per ulteriori informazioni)</a>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="alerts.length > 1">
|
||||
Emergenze attuali:
|
||||
<ul>
|
||||
<li *ngFor="let alert of alerts">
|
||||
<a (click)="openAlert(alert['id'])"><b>{{ alert["created_at"] | date:'dd/MM/YYYY, HH:mm:ss' }}</b> (premi per ulteriori informazioni)</a>
|
||||
<a (click)="openAlert(alert['id'])"><b>{{ alert["created_at"] | date:'dd/MM/YYYY, HH:mm:ss' }}</b> (premere per ulteriori informazioni)</a>
|
||||
</li>
|
||||
</ul>
|
||||
</ng-container>
|
||||
|
|
Loading…
Reference in New Issue