Пример #1
0
        public InstallationSummary InstallCompiledPackageData(XDocument?packageXml, int userId = Constants.Security.SuperUserId)
        {
            CompiledPackage compiledPackage = GetCompiledPackageInfo(packageXml);

            if (compiledPackage == null)
            {
                throw new InvalidOperationException("Could not read the package file " + packageXml);
            }

            // Trigger the Importing Package Notification and stop execution if event/user is cancelling it
            var importingPackageNotification = new ImportingPackageNotification(compiledPackage.Name);

            if (_eventAggregator.PublishCancelable(importingPackageNotification))
            {
                return(new InstallationSummary(compiledPackage.Name));
            }

            var summary = _packageInstallation.InstallPackageData(compiledPackage, userId, out _);

            _auditService.Add(AuditType.PackagerInstall, userId, -1, "Package", $"Package data installed for package '{compiledPackage.Name}'.");

            // trigger the ImportedPackage event
            _eventAggregator.Publish(new ImportedPackageNotification(summary).WithStateFrom(importingPackageNotification));

            return(summary);
        }
        public void Handle(ContentCopiedNotification notification)
        {
            if (notification.RelateToOriginal == false)
            {
                return;
            }

            var relationType = _relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias);

            if (relationType == null)
            {
                relationType = new RelationType(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias,
                                                Constants.Conventions.RelationTypes.RelateDocumentOnCopyName,
                                                true,
                                                Constants.ObjectTypes.Document,
                                                Constants.ObjectTypes.Document,
                                                false);

                _relationService.Save(relationType);
            }

            var relation = new Relation(notification.Original.Id, notification.Copy.Id, relationType);

            _relationService.Save(relation);

            _auditService.Add(
                AuditType.Copy,
                notification.Copy.WriterId,
                notification.Copy.Id, ObjectTypes.GetName(UmbracoObjectTypes.Document),
                $"Copied content with Id: '{notification.Copy.Id}' related to original content with Id: '{notification.Original.Id}'");
        }
    public void Handle(ContentMovedToRecycleBinNotification notification)
    {
        using (IScope scope = _scopeProvider.CreateScope())
        {
            const string  relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias;
            IRelationType?relationType      = _relationService.GetRelationTypeByAlias(relationTypeAlias);

            // check that the relation-type exists, if not, then recreate it
            if (relationType == null)
            {
                Guid         documentObjectType = Constants.ObjectTypes.Document;
                const string relationTypeName   = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName;

                relationType = new RelationType(relationTypeName, relationTypeAlias, false, documentObjectType, documentObjectType, false);
                _relationService.Save(relationType);
            }

            foreach (MoveEventInfo <IContent> item in notification.MoveInfoCollection)
            {
                IList <string> originalPath     = item.OriginalPath.ToDelimitedList();
                var            originalParentId = originalPath.Count > 2
                    ? int.Parse(originalPath[originalPath.Count - 2], CultureInfo.InvariantCulture)
                    : Constants.System.Root;

                // before we can create this relation, we need to ensure that the original parent still exists which
                // may not be the case if the encompassing transaction also deleted it when this item was moved to the bin
                if (_entityService.Exists(originalParentId))
                {
                    // Add a relation for the item being deleted, so that we can know the original parent for if we need to restore later
                    IRelation relation =
                        _relationService.GetByParentAndChildId(originalParentId, item.Entity.Id, relationType) ??
                        new Relation(originalParentId, item.Entity.Id, relationType);
                    _relationService.Save(relation);

                    _auditService.Add(
                        AuditType.Delete,
                        item.Entity.WriterId,
                        item.Entity.Id,
                        UmbracoObjectTypes.Document.GetName(),
                        string.Format(_textService.Localize("recycleBin", "contentTrashed"), item.Entity.Id, originalParentId));
                }
            }

            scope.Complete();
        }
    }
Пример #4
0
        public async Task <decimal> Convert(string userName, decimal input, string fromCurrency, string toCurrency)
        {
            var currenctRate = GetRatio(fromCurrency, toCurrency);
            var result       = Math.Round(input * currenctRate, 2);
            await _auditService.Add(new Models.AuditModel {
                UserName = userName, FromCurrency = fromCurrency, ToCurrency = toCurrency, InputAmmount = input, Rate = currenctRate, ResultAmount = result, AddedOn = DateTime.UtcNow
            });

            return(result);
        }
Пример #5
0
        /// <inheritdoc />
        public async Task <FileInfo> FetchPackageFileAsync(Guid packageId, Version umbracoVersion, int userId)
        {
            //includeHidden = true because we don't care if it's hidden we want to get the file regardless
            var url = $"{Constants.PackageRepository.RestApiBaseUrl}/{packageId}?version={umbracoVersion.ToString(3)}&includeHidden=true&asFile=true";

            byte[] bytes;
            try
            {
                if (_httpClient == null)
                {
                    _httpClient = new HttpClient();
                }
                bytes = await _httpClient.GetByteArrayAsync(url);
            }
            catch (HttpRequestException ex)
            {
                throw new ConnectionException("An error occurring downloading the package from " + url, ex);
            }

            //successful
            if (bytes.Length > 0)
            {
                var packagePath = Current.IOHelper.MapPath(SystemDirectories.Packages);

                // Check for package directory
                if (Directory.Exists(packagePath) == false)
                {
                    Directory.CreateDirectory(packagePath);
                }

                var packageFilePath = Path.Combine(packagePath, packageId + ".umb");

                using (var fs1 = new FileStream(packageFilePath, FileMode.Create))
                {
                    fs1.Write(bytes, 0, bytes.Length);
                    return(new FileInfo(packageFilePath));
                }
            }

            _auditService.Add(AuditType.PackagerInstall, userId, -1, "Package", $"Package {packageId} fetched from {Constants.PackageRepository.DefaultRepositoryId}");
            return(null);
        }
Пример #6
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var request = _httpContextAccessor.HttpContext.Request;

            var audit = new AuditDto
            {
                UserName = _httpContextAccessor.HttpContext.User.IsAuthenticated()
                    ? _httpContextAccessor.HttpContext.User.Identity.Name
                    : UserType.Anonymous,
                UrlAccessed       = request.GetDisplayUrl(),
                ExternalIpAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(),
                TimeStamp         = DateTimeOffset.Now,
                CreatedBy         = UserType.SystemGenerated,
                AudittingLevel    = _audittingLevel,
                Data = SerializeRequest(request)
            };

            _auditService.Add(audit);

            base.OnActionExecuting(context);
        }
Пример #7
0
 public async Task <IActionResult> AddAudit([FromBody] Audit audit)
 {
     return(Ok(await _auditService.Add(audit)));
 }