Ejemplo n.º 1
0
        private File GetFile(File request)
        {
            var  id    = request?.Id;
            File ret   = null;
            var  query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetSelect <File>(currentUser, "File", request.Select);

            DocEntityFile entity = null;

            if (id.HasValue)
            {
                entity = DocEntityFile.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No File found for Id {id.Value}");
            }

            if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route.");
            }

            ret = entity?.ToDto();
            return(ret);
        }
Ejemplo n.º 2
0
        public File Post(FileCopy request)
        {
            File ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityFile.Get(request?.Id);
                    if (null == entity)
                    {
                        throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed.");
                    }
                    if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    var pCost      = entity.Cost;
                    var pFileLabel = entity.FileLabel;
                    if (!DocTools.IsNullOrEmpty(pFileLabel))
                    {
                        pFileLabel += " (Copy)";
                    }
                    var pFileName = entity.FileName;
                    if (!DocTools.IsNullOrEmpty(pFileName))
                    {
                        pFileName += " (Copy)";
                    }
                    var pOriginalFileName = entity.OriginalFileName;
                    if (!DocTools.IsNullOrEmpty(pOriginalFileName))
                    {
                        pOriginalFileName += " (Copy)";
                    }
                    var pRights = entity.Rights;
                    var pScopes = entity.Scopes.ToList();
                    var pSource = entity.Source;
                    var pType   = entity.Type;
                    var copy    = new DocEntityFile(ssn)
                    {
                        Hash               = Guid.NewGuid()
                        , Cost             = pCost
                        , FileLabel        = pFileLabel
                        , FileName         = pFileName
                        , OriginalFileName = pOriginalFileName
                        , Rights           = pRights
                        , Source           = pSource
                        , Type             = pType
                    };
                    foreach (var item in pScopes)
                    {
                        entity.Scopes.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }