Пример #1
0
        public IActionResult Archive(int id)
        {
            MetadataEntity origItem = _metadataRepository.GetById(id, false, false);

            string currentUser = HttpContext.User.Identity.Name;

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

            if (!_securityRepository.UserIsAuthorisedByBuisnessAreas(HttpContext, AuthActions.Archive, origItem.BuisnessArea))
            {
                return(_securityRepository.GateUnathorised(currentUser, AccessLogAction.DocumentArchive, "Metadata", id.ToString()));
            }

            origItem.Archive.Archive(currentUser);

            _logger.Log(LogLevel.Debug, "Document {0} Archived By {1}", origItem.Id, currentUser);
            _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentArchive, id, "Document", true);

            _metadataRepository.Edit(origItem);
            _metadataRepository.SaveChanges();

            return(Ok());
        }
Пример #2
0
        public async Task <IActionResult> Put(int id, [FromBody] Stream value)
        {
            var currentUser = HttpContext.User.Identity.Name;

            //uploading a new version of the document
            var meta = _metadataRepository.GetById(id, true, false);

            if (meta == null)
            {
                return(_securityRepository.GateNotFound(currentUser, AccessLogAction.DocumentUpdate, "Document", id.ToString()));
            }

            if (!_securityRepository.UserIsAuthorisedByBuisnessAreas(HttpContext, AuthActions.Update, meta.BuisnessArea))
            {
                return(_securityRepository.GateUnathorised(currentUser, AccessLogAction.DocumentUpdate, "Document", id.ToString()));
            }

            if (meta.Locked.Is && meta.Locked.By != currentUser)
            {
                return(_securityRepository.GateDocumentLockedByAnotherUser(currentUser, "Document", id.ToString()));
            }

            meta.Versions.Add(DocumentVersionEntity.FromMetadata(meta));

            meta.Version++;

            await _documentRepository.SetDocumentAsync(meta, value);

            _logger.Log(LogLevel.Debug, "Uploaded New Document Version {0} for User {1}", meta.Id, HttpContext.User.Identity.Name);
            _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentUpdate, id, "Document", true);

            _metadataRepository.Edit(meta);
            _metadataRepository.SaveChanges();

            return(Ok());
        }