Esempio n. 1
0
        public IHttpActionResult Post([FromBody] InspectionDTO inspection)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            if (inspection != null)
            {
                try
                {
                    Guid    token = this.GetToken();
                    UserDTO user  = this.userService.GetUserLoggedIn(token);
                    inspection.CreatorUserName = user.UserName;
                    PermissionHandler permissionHandler = new PermissionHandler();
                    bool permissionInPort = permissionHandler.IsUserAllowedToCreateInspectionOnPort(user.Role);
                    bool permissionInYard = permissionHandler.IsUserAllowedToCreateInspectionOnYard(user.Role);
                    if ((permissionInPort && this.LocationIsPort(inspection.Location)) ||
                        (permissionInYard && this.LocationIsYard(inspection.Location)))
                    {
                        this.inspectionService.CreateInspection(inspection);
                        response = this.Request.CreateResponse(HttpStatusCode.OK);
                    }
                    else if (this.LocationIsPort(inspection.Location) || this.LocationIsYard(inspection.Location))
                    {
                        response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El usuario no tiene permisos para ejecutar esta accion");
                    }
                    else
                    {
                        response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El lugar ingresado no es un lugar válido");
                    }
                }
                catch (UserNotExistException e)
                {
                    response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
                }
                catch (ImageNotFoundException e)
                {
                    response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
                }
                catch (FormatException)
                {
                    string message = "El token enviado no tiene un formato valido.";
                    response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
                }
                catch (InvalidOperationException)
                {
                    string message = "No se ha enviado header de autenticación.";
                    response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
                }
                catch (VehicleNotFoundException e)
                {
                    response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
                }
            }
            else
            {
                string message = "El formato de usuario es incorrecto";
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message);
            }

            return(ResponseMessage(response));
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 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));
        }