示例#1
0
        public IHttpActionResult AssignVehicle([FromUri] string zoneId, [FromUri] string vin)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            Guid guidZone;

            try
            {
                guidZone = Guid.Parse(zoneId);
            }
            catch (FormatException)
            {
                string message = "El id de zona no tiene un formato valido.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
                return(ResponseMessage(response));
            }

            try
            {
                Guid              token             = this.GetToken();
                UserDTO           userLogged        = this.userService.GetUserLoggedIn(token);
                PermissionHandler permissionHandler = new PermissionHandler();
                if (permissionHandler.IsUserAllowedToLocateVehiclesOnZones(userLogged.Role))
                {
                    this.zoneService.AssignVehicle(guidZone, vin);
                    response = this.Request.CreateResponse(HttpStatusCode.OK);
                }
                else
                {
                    response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El usuario no tiene permisos para ejecutar esta accion");
                }
            }
            catch (AssignVehicleToMainZoneException e)
            {
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            catch (AssignVehicleToZoneWithoutCapacityException e)
            {
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            catch (UserNotExistException e)
            {
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            catch (InvalidOperationException)
            {
                string message = "No se ha enviado header de autenticación.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
            }
            catch (FormatException)
            {
                string message = "El token enviado no tiene un formato valido.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
            }

            return(ResponseMessage(response));
        }
示例#2
0
        public void TestAdministratorPermissions()
        {
            string admin = "Administrador";

            PermissionHandler permissionHandler = new PermissionHandler();

            Assert.IsTrue(permissionHandler.IsUserAllowedToCreateInspectionOnYard(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToLocateVehiclesOnZones(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToMoveSubZonesToZones(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToListZones(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToTransportBatches(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToFinishTransportation(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToListBatches(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToCreateBatch(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToCreateVehicle(admin));
            Assert.IsTrue(permissionHandler.IsUserAllowedToCreateInspectionOnPort(admin));
        }
示例#3
0
        public void TestYardOperatorPermissions()
        {
            string yardOperator = "Operario del Patio";

            PermissionHandler permissionHandler = new PermissionHandler();

            Assert.IsTrue(permissionHandler.IsUserAllowedToCreateInspectionOnYard(yardOperator));
            Assert.IsTrue(permissionHandler.IsUserAllowedToLocateVehiclesOnZones(yardOperator));
            Assert.IsTrue(permissionHandler.IsUserAllowedToMoveSubZonesToZones(yardOperator));
            Assert.IsTrue(permissionHandler.IsUserAllowedToListZones(yardOperator));

            Assert.IsFalse(permissionHandler.IsUserAllowedToTransportBatches(yardOperator));
            Assert.IsFalse(permissionHandler.IsUserAllowedToFinishTransportation(yardOperator));
            Assert.IsFalse(permissionHandler.IsUserAllowedToListBatches(yardOperator));
            Assert.IsFalse(permissionHandler.IsUserAllowedToCreateBatch(yardOperator));
            Assert.IsFalse(permissionHandler.IsUserAllowedToCreateVehicle(yardOperator));
            Assert.IsFalse(permissionHandler.IsUserAllowedToCreateInspectionOnPort(yardOperator));
        }
示例#4
0
        public void TestCarrierPermissions()
        {
            string carrier = "Transportista";

            PermissionHandler permissionHandler = new PermissionHandler();

            Assert.IsTrue(permissionHandler.IsUserAllowedToTransportBatches(carrier));
            Assert.IsTrue(permissionHandler.IsUserAllowedToFinishTransportation(carrier));
            Assert.IsTrue(permissionHandler.IsUserAllowedToListBatches(carrier));

            Assert.IsFalse(permissionHandler.IsUserAllowedToCreateBatch(carrier));
            Assert.IsFalse(permissionHandler.IsUserAllowedToCreateVehicle(carrier));
            Assert.IsFalse(permissionHandler.IsUserAllowedToCreateInspectionOnPort(carrier));
            Assert.IsFalse(permissionHandler.IsUserAllowedToCreateInspectionOnYard(carrier));
            Assert.IsFalse(permissionHandler.IsUserAllowedToLocateVehiclesOnZones(carrier));
            Assert.IsFalse(permissionHandler.IsUserAllowedToMoveSubZonesToZones(carrier));
            Assert.IsFalse(permissionHandler.IsUserAllowedToListZones(carrier));
        }
示例#5
0
        public IHttpActionResult RemoveVehicle(string vin)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            if (vin != null)
            {
                try
                {
                    Guid              token             = this.GetToken();
                    UserDTO           userLogged        = this.userService.GetUserLoggedIn(token);
                    PermissionHandler permissionHandler = new PermissionHandler();
                    if (permissionHandler.IsUserAllowedToLocateVehiclesOnZones(userLogged.Role))
                    {
                        this.zoneService.RemoveVehicle(vin);
                        response = this.Request.CreateResponse(HttpStatusCode.OK);
                    }
                    else
                    {
                        response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El usuario no tiene permisos para ejecutar esta accion");
                    }
                }
                catch (UserNotExistException e)
                {
                    response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
                }
                catch (InvalidOperationException)
                {
                    string message = "No se ha enviado header de autenticación.";
                    response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
                }
                catch (FormatException)
                {
                    string message = "El token enviado no tiene un formato valido.";
                    response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
                }
            }
            else
            {
                string message = "El formato de vin ingresado es incorrecto.";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
            }

            return(ResponseMessage(response));
        }