agregar acciones de update,delete al admin
This commit is contained in:
parent
6ee8e49b60
commit
07db23de0c
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Laravel\Socialite\Facades\Socialite;
|
use Laravel\Socialite\Facades\Socialite;
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
use App\Models\Recursos;
|
use App\Models\Recursos;
|
||||||
use App\Models\Responsables;
|
use App\Models\Responsables;
|
||||||
|
|
||||||
|
//plan::where(["id_user" => $id_user, "id" => $id])->exists()
|
||||||
class PlanController extends Controller
|
class PlanController extends Controller
|
||||||
{
|
{
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
|
||||||
$id_user = auth()->user()->id;
|
$id_user = auth()->user();
|
||||||
if (plan::where(["id_user" => $id_user, "id" => $id])->exists()) {
|
if ($id_user->isCreadorPlan($id) or $id_user->isAdmin()) {
|
||||||
//Actualizamos los atributos propios
|
//Actualizamos los atributos propios
|
||||||
$plan = plan::find($id);
|
$plan = plan::find($id);
|
||||||
$plan->update([
|
$plan->update([
|
||||||
@ -315,7 +315,6 @@ public function createPlan(Request $request)
|
|||||||
$responsable_aux->save();
|
$responsable_aux->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return response([
|
return response([
|
||||||
"status" => 1,
|
"status" => 1,
|
||||||
"message" => "!Plan de mejora creado exitosamente",
|
"message" => "!Plan de mejora creado exitosamente",
|
||||||
@ -323,10 +322,10 @@ public function createPlan(Request $request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//confirmar los datos nesesarios
|
||||||
public function listPlan()
|
public function listPlan()
|
||||||
{
|
{
|
||||||
$id_user = auth()->user()->id;
|
$id_user = auth()->user()->id;
|
||||||
|
|
||||||
$planAll = plan::select('plans.id', 'plans.nombre', 'plans.codigo', 'plans.avance', 'plans.estado', 'plans.id_user', 'estandars.name as estandar_name', 'users.name as user_name')
|
$planAll = plan::select('plans.id', 'plans.nombre', 'plans.codigo', 'plans.avance', 'plans.estado', 'plans.id_user', 'estandars.name as estandar_name', 'users.name as user_name')
|
||||||
->join('estandars', 'plans.id_estandar', '=', 'estandars.id')
|
->join('estandars', 'plans.id_estandar', '=', 'estandars.id')
|
||||||
->join('users', 'plans.id_user', '=', 'users.id')
|
->join('users', 'plans.id_user', '=', 'users.id')
|
||||||
@ -337,7 +336,6 @@ public function listPlan()
|
|||||||
$plan->esCreador = ($plan->id_user == $id_user) ? true : false;
|
$plan->esCreador = ($plan->id_user == $id_user) ? true : false;
|
||||||
unset($plan->id_user);
|
unset($plan->id_user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response([
|
return response([
|
||||||
"status" => 1,
|
"status" => 1,
|
||||||
"message" => "!Lista de planes de mejora",
|
"message" => "!Lista de planes de mejora",
|
||||||
@ -358,8 +356,8 @@ public function updatePlan(Request $request)
|
|||||||
"avance" => "required|integer",
|
"avance" => "required|integer",
|
||||||
]);
|
]);
|
||||||
$id = $request->id;
|
$id = $request->id;
|
||||||
$id_user = auth()->user()->id;
|
$id_user = auth()->user();
|
||||||
if (plan::where(["id_user" => $id_user, "id" => $id])->exists()) {
|
if ($id_user->isCreadorPlan($id) or $id_user->isAdmin()) {
|
||||||
$plan = plan::find($id);
|
$plan = plan::find($id);
|
||||||
$plan->nombre = $request->nombre;
|
$plan->nombre = $request->nombre;
|
||||||
$plan->oportunidad_plan = $request->oportunidad_plan;
|
$plan->oportunidad_plan = $request->oportunidad_plan;
|
||||||
@ -385,8 +383,8 @@ public function updatePlan(Request $request)
|
|||||||
|
|
||||||
public function deletePlan($id)
|
public function deletePlan($id)
|
||||||
{
|
{
|
||||||
$id_user = auth()->user()->id;
|
$id_user = auth()->user();
|
||||||
if (plan::where(["id" => $id, "id_user" => $id_user])->exists()) {
|
if ($id_user->isCreadorPlan($id) or $id_user->isAdmin()) {
|
||||||
$plan = plan::where(["id" => $id, "id_user" => $id_user])->first();
|
$plan = plan::where(["id" => $id, "id_user" => $id_user])->first();
|
||||||
$plan->delete();
|
$plan->delete();
|
||||||
return response([
|
return response([
|
||||||
|
@ -74,7 +74,7 @@ public function userProfile()
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
"status" => 0,
|
"status" => 0,
|
||||||
"message" => "Perfil de usuario",
|
"message" => "Perfil de usuario",
|
||||||
"data" => auth()->user()
|
"data" => auth()->user(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,22 +24,35 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
public function estandars(){
|
public function estandars()
|
||||||
|
{
|
||||||
return $this->hasMany(Estandar::class, 'id');
|
return $this->hasMany(Estandar::class, 'id');
|
||||||
}
|
}
|
||||||
public function plans(){
|
public function plans()
|
||||||
|
{
|
||||||
return $this->hasMany(Plan::class, 'id');
|
return $this->hasMany(Plan::class, 'id');
|
||||||
}
|
}
|
||||||
public function evidencias(){
|
public function evidencias()
|
||||||
|
{
|
||||||
return $this->hasMany(Evidencia::class, 'id');
|
return $this->hasMany(Evidencia::class, 'id');
|
||||||
}
|
}
|
||||||
public function providers(){
|
public function providers()
|
||||||
|
{
|
||||||
return $this->hasMany(Provider::class, 'id_user');
|
return $this->hasMany(Provider::class, 'id_user');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function roles(){
|
public function roles()
|
||||||
|
{
|
||||||
return $this->belongsToMany(role::class, 'role_user', 'id_user', 'id_rol');
|
return $this->belongsToMany(role::class, 'role_user', 'id_user', 'id_rol');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isAdmin()
|
||||||
|
{
|
||||||
|
return $this->roles()->where('name', 'Admin')->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isCreadorPlan($id_plan)
|
||||||
|
{
|
||||||
|
return plan::where('id', $id_plan)->where('id_user', $this->id)->exists();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user