Exemplo n.º 1
0
        public IActionResult Unlock(int id)
        {
            string         currentUser = HttpContext.User.Identity.Name;
            MetadataEntity item        = _metadataRepository.GetById(id, false, false);

            if (item == null)
            {
                return(_securityRepository.GateNotFound(currentUser, AccessLogAction.DocumentUnlocked, "Metadata", id.ToString()));
            }

            if (!_securityRepository.UserIsAuthorisedByBuisnessAreas(HttpContext, AuthActions.Update, item.BuisnessArea))
            {
                return(_securityRepository.GateUnathorised(currentUser, AccessLogAction.DocumentUnlocked, "Metadata", id.ToString()));
            }

            bool success = _metadataRepository.TryUnlockDocument(ref item, HttpContext);

            if (!success)
            {
                return(_securityRepository.GateCannotUnlock(currentUser, "Metadata", id.ToString()));
            }

            _metadataRepository.Touch(ref item);

            _logger.Log(LogLevel.Debug, "DocumentMetadata {0} Locked By {1}", item.Id, currentUser);
            _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentUnlocked, item.Id.ToString(), "Metadata", true);

            _metadataRepository.SaveChanges();

            return(Ok(success));
        }