Наследование: PipelineArgs
Пример #1
0
        public virtual void Process(AddDbItemArgs args)
        {
            var item = args.DbItem;

            var rules = new AccessRuleCollection();

            this.FillAccessRules(rules, item.Access, AccessRight.ItemRead, a => a.CanRead);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemWrite, a => a.CanWrite);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemRename, a => a.CanRename);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemCreate, a => a.CanCreate);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemDelete, a => a.CanDelete);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemAdmin, a => a.CanAdmin);

            if (!rules.Any())
            {
                return;
            }

            var serializer = new AccessRuleSerializer();

            item.Fields.Add(new DbField("__Security", FieldIDs.Security)
            {
                Value = serializer.Serialize(rules)
            });
        }
Пример #2
0
        public virtual void Process(AddDbItemArgs args)
        {
            var item = args.DbItem;

            var rules = new AccessRuleCollection();

            this.FillAccessRules(rules, item.Access, AccessRight.ItemRead, a => a.CanRead);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemWrite, a => a.CanWrite);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemRename, a => a.CanRename);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemCreate, a => a.CanCreate);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemDelete, a => a.CanDelete);
            this.FillAccessRules(rules, item.Access, AccessRight.ItemAdmin, a => a.CanAdmin);

            if (!rules.Any())
            {
                return;
            }

            var serializer = new AccessRuleSerializer();

            // TODO: Should not require to check if Security field is exists
            if (item.Fields.Any(f => f.ID == FieldIDs.Security))
            {
                item.Fields[FieldIDs.Security].Value = serializer.Serialize(rules);
            }
            else
            {
                item.Fields.Add(new DbField("__Security", FieldIDs.Security)
                {
                    Value = serializer.Serialize(rules)
                });
            }
        }
Пример #3
0
        public virtual void Process(AddDbItemArgs args)
        {
            var item = args.DbItem;

            var date = DateUtil.IsoNow;
            var user = Context.User.Name;

            item.Fields.Add(new DbField("__Created", FieldIDs.Created)
            {
                Value = date
            });
            item.Fields.Add(new DbField("__Created by", FieldIDs.CreatedBy)
            {
                Value = user
            });
            item.Fields.Add(new DbField("__Revision", FieldIDs.Revision)
            {
                Value = ID.NewID.ToString()
            });
            item.Fields.Add(new DbField("__Updated", FieldIDs.Updated)
            {
                Value = date
            });
            item.Fields.Add(new DbField("__Updated by", FieldIDs.UpdatedBy)
            {
                Value = user
            });
        }
Пример #4
0
        public virtual void Process(AddDbItemArgs args)
        {
            var item        = args.DbItem;
            var dataStorage = args.DataStorage;

            dataStorage.FakeItems.Add(item.ID, item);
        }
    public virtual void Process(AddDbItemArgs args)
    {
      var item = args.DbItem;
      var date = DateUtil.IsoNow;
      var user = Context.User.Name;

      AddStatisticsFields(item, date, user);
      SetStatisticsForAllLanguages(item, date, user);
    }
        public virtual void Process(AddDbItemArgs args)
        {
            var item = args.DbItem;
            var date = DateUtil.IsoNow;
            var user = Context.User.Name;

            AddStatisticsFields(item, date, user);
            SetStatisticsForAllLanguages(item, date, user);
        }
Пример #7
0
    public void ShouldAddFirstVersion()
    {
      // arrange
      var processor = new AddVersion();
      var args = new AddDbItemArgs(new DbItem("home"), new DataStorage());

      // act
      processor.Process(args);

      // assert
      args.DbItem.VersionsCount["en"].Should().Be(1);
    }
    public void ShouldAddVersionInTheGivenLanguage()
    {
      // arrange
      var processor = new AddVersion();
      var args = new AddDbItemArgs(new DbItem("home"), new DataStorage(Database.GetDatabase("master")), Language.Parse("fr-FR"));

      // act
      processor.Process(args);

      // assert
      args.DbItem.GetVersionCount("fr-FR").Should().Be(1);
    }
    public void ShouldAddFirstVersion()
    {
      // arrange
      var processor = new AddVersion();
      var args = new AddDbItemArgs(new DbItem("home"), new DataStorage(Database.GetDatabase("master")));

      // act
      processor.Process(args);

      // assert
      args.DbItem.GetVersionCount("en").Should().Be(1);
    }
Пример #10
0
    public void ShouldSetTemplateIdToBranchTemplateIdIfParentIsBrancesAndNoTemplateIdSet(string originalTemplateId, string expectedNewTemlateId)
    {
      // arrange
      var branchItem = new DbItem("branch item") { ParentID = ItemIDs.BranchesRoot, TemplateID = ID.Parse(originalTemplateId) };
      var args = new AddDbItemArgs(branchItem, this.dataStorage);

      // act
      this.processor.Process(args);

      // assert
      branchItem.TemplateID.Should().Be(ID.Parse(expectedNewTemlateId));
    }
Пример #11
0
        public virtual void Process(AddDbItemArgs args)
        {
            var item        = args.DbItem;
            var dataStorage = args.DataStorage;

            foreach (var child in item.Children)
            {
                child.ParentID = item.ID;
                child.FullPath = item.FullPath + "/" + child.Name;
                dataStorage.AddFakeItem(child);
            }
        }
Пример #12
0
    public virtual void Process(AddDbItemArgs args)
    {
      var item = args.DbItem;

      var date = DateUtil.IsoNow;
      var user = Context.User.Name;

      item.Fields.Add(new DbField("__Created", FieldIDs.Created) { Value = date });
      item.Fields.Add(new DbField("__Created by", FieldIDs.CreatedBy) { Value = user });
      item.Fields.Add(new DbField("__Revision", FieldIDs.Revision) { Value = ID.NewID.ToString() });
      item.Fields.Add(new DbField("__Updated", FieldIDs.Updated) { Value = date });
      item.Fields.Add(new DbField("__Updated by", FieldIDs.UpdatedBy) { Value = user });
    }
    public void ProcessSetsValidRevision(
      SetStatistics sut,
      [Frozen] DbItem item,
      AddDbItemArgs args,
      ID id,
      string value)
    {
      var field = new DbField(id) { { "en", value } };
      item.Fields.Add(field);

      sut.Process(args);
      var actual = item.Fields[FieldIDs.Revision].GetValue("en", 0);

      Assert.True(ID.IsID(actual));
    }
Пример #14
0
    public virtual void Process(AddDbItemArgs args)
    {
      var item = args.DbItem;
      var dataStorage = args.DataStorage;

      var parentItem = dataStorage.GetFakeItem(item.ParentID);
      if (parentItem == null)
      {
        throw new ItemNotFoundException("The parent item \"{0}\" was not found.".FormatWith(item.ParentID), null);
      }

      if (!parentItem.Children.Contains(item))
      {
        parentItem.Children.Add(item);
      }
    }
        public virtual void Process(AddDbItemArgs args)
        {
            var item        = args.DbItem;
            var dataStorage = args.DataStorage;

            var parentItem = dataStorage.GetFakeItem(item.ParentID);

            if (parentItem == null)
            {
                throw new ItemNotFoundException("The parent item \"{0}\" was not found.".FormatWith(item.ParentID), null);
            }

            if (!parentItem.Children.Contains(item))
            {
                parentItem.Children.Add(item);
            }
        }
Пример #16
0
    public void Process(AddDbItemArgs args)
    {
      Assert.ArgumentNotNull(args, "args");

      var item = args.DbItem;
      var template = args.DataStorage.GetFakeTemplate(item.TemplateID);
      if (template == null)
      {
        return;
      }

      string defaultWorkflow;
      if (template.StandardValues.TryGetValue(FieldIDs.DefaultWorkflow, out defaultWorkflow))
      {
        item.Fields.Add(FieldIDs.Workflow, defaultWorkflow);
      }
    }
Пример #17
0
        public virtual void Process(AddDbItemArgs args)
        {
            var item        = args.DbItem;
            var dataStorage = args.DataStorage;

            var isResolved = this.ResolveTemplate(item, dataStorage);

            if (isResolved)
            {
                new TemplateTreeBuilder().Build(item);

                return;
            }

            if (!ID.IsNullOrEmpty(item.TemplateID) && dataStorage.GetFakeTemplate(item.TemplateID) != null)
            {
                return;
            }

            if (item.TemplateID == ID.Null)
            {
                item.TemplateID = ID.NewID;
            }

            var template = new DbTemplate(item.Name, item.TemplateID)
            {
                Generated = true
            };

            foreach (var itemField in item.Fields)
            {
                var templatefield = new DbField(itemField.Name, itemField.ID)
                {
                    Shared = itemField.Shared,
                    Type   = itemField.Type,
                    Source = itemField.Source
                };
                template.Add(templatefield);
            }

            new TemplateTreeBuilder().Build(item);

            dataStorage.AddFakeItem(template);
        }
        public void Process(AddDbItemArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var item     = args.DbItem;
            var template = args.DataStorage.GetFakeTemplate(item.TemplateID);

            if (template == null)
            {
                return;
            }

            string defaultWorkflow;

            if (template.StandardValues.TryGetValue(FieldIDs.DefaultWorkflow, out defaultWorkflow))
            {
                item.Fields.Add(FieldIDs.Workflow, defaultWorkflow);
            }
        }
Пример #19
0
    public virtual void Process(AddDbItemArgs args)
    {
      var item = args.DbItem;
      var dataStorage = args.DataStorage;

      var isResolved = this.ResolveTemplate(item, dataStorage);
      if (isResolved)
      {
        new TemplateTreeBuilder().Build(item);

        return;
      }

      if (!ID.IsNullOrEmpty(item.TemplateID) && dataStorage.GetFakeTemplate(item.TemplateID) != null)
      {
        return;
      }

      if (item.TemplateID == ID.Null)
      {
        item.TemplateID = ID.NewID;
      }

      var template = new DbTemplate(item.Name, item.TemplateID)
      {
        Generated = true
      };

      foreach (var itemField in item.Fields)
      {
        var templatefield = new DbField(itemField.Name, itemField.ID)
                              {
                                Shared = itemField.Shared,
                                Type = itemField.Type,
                                Source = itemField.Source
                              };
        template.Add(templatefield);
      }

      new TemplateTreeBuilder().Build(item);

      dataStorage.AddFakeItem(template);
    }
Пример #20
0
    public virtual void Process(AddDbItemArgs args)
    {
      var item = args.DbItem;

      var rules = new AccessRuleCollection();

      this.FillAccessRules(rules, item.Access, AccessRight.ItemRead, a => a.CanRead);
      this.FillAccessRules(rules, item.Access, AccessRight.ItemWrite, a => a.CanWrite);
      this.FillAccessRules(rules, item.Access, AccessRight.ItemRename, a => a.CanRename);
      this.FillAccessRules(rules, item.Access, AccessRight.ItemCreate, a => a.CanCreate);
      this.FillAccessRules(rules, item.Access, AccessRight.ItemDelete, a => a.CanDelete);
      this.FillAccessRules(rules, item.Access, AccessRight.ItemAdmin, a => a.CanAdmin);

      if (!rules.Any())
      {
        return;
      }

      var serializer = new AccessRuleSerializer();
      item.Fields.Add(new DbField("__Security", FieldIDs.Security) { Value = serializer.Serialize(rules) });
    }
    public void ProcessSetsSameCreateAndUpdateInfoForAllLanguages(
      string statisticField,
      SetStatistics sut,
      [Frozen] DbItem item,
      AddDbItemArgs args,
      ID id1,
      ID id2,
      string value1,
      string value2)
    {
      var statisticFieldId = ID.Parse(statisticField);
      var fieldEn = new DbField(id1) { { "en", value1 } };
      var fieldDa = new DbField(id2) { { "da", value2 } };
      item.Fields.Add(fieldEn);
      item.Fields.Add(fieldDa);

      sut.Process(args);
      var valueEn = item.Fields[statisticFieldId].GetValue("en", 0);
      var valueDa = item.Fields[statisticFieldId].GetValue("da", 0);

      valueEn.Should().Be(valueDa);
    }
    public void ProcessSetsUniqueRevisionsForAllLanguages(
      SetStatistics sut,
      [Frozen] DbItem item,
      AddDbItemArgs args,
      ID id1,
      ID id2,
      string value1,
      string value2)
    {
      var fieldEn = new DbField(id1) { { "en", value1 } };
      var fieldDa = new DbField(id2) { { "da", value2 } };
      item.Fields.Add(fieldEn);
      item.Fields.Add(fieldDa);

      sut.Process(args);
      var revisionEn = item.Fields[FieldIDs.Revision].GetValue("en", 0);
      var revisionDa = item.Fields[FieldIDs.Revision].GetValue("da", 0);

      revisionEn.Should().NotBeNullOrEmpty();
      revisionDa.Should().NotBeNullOrEmpty();
      revisionEn.Should().NotBe(revisionDa);
    }
Пример #23
0
    public virtual void Process(AddDbItemArgs args)
    {
      var item = args.DbItem;

      if (!ID.IsNullOrEmpty(item.ParentID))
      {
        return;
      }

      if (item.TemplateID == TemplateIDs.Template)
      {
        item.ParentID = ItemIDs.TemplateRoot;
        return;
      }

      if (item.TemplateID == TemplateIDs.BranchTemplate)
      {
        item.ParentID = ItemIDs.BranchesRoot;
        return;
      }

      item.ParentID = item is DbTemplate ? args.DefaultTemplateRoot : args.DefaultItemRoot;
    }
Пример #24
0
        public virtual void Process(AddDbItemArgs args)
        {
            var item = args.DbItem;

            if (!ID.IsNullOrEmpty(item.ParentID))
            {
                return;
            }

            if (item.TemplateID == TemplateIDs.Template)
            {
                item.ParentID = ItemIDs.TemplateRoot;
                return;
            }

            if (item.TemplateID == TemplateIDs.BranchTemplate)
            {
                item.ParentID = ItemIDs.BranchesRoot;
                return;
            }

            item.ParentID = item is DbTemplate ? args.DefaultTemplateRoot : args.DefaultItemRoot;
        }
    public void ProcessSetsStatisticsForItemWithoutFieldsInDefaultLanguage(
      string statisticField,
      SetStatistics sut,
      [Frozen] DbItem item,
      AddDbItemArgs args)
    {
      var statisticFieldId = ID.Parse(statisticField);

      sut.Process(args);
      var value = item.Fields[statisticFieldId].GetValue("en", 0);

      value.Should().NotBeNullOrEmpty();
    }
Пример #26
0
 public virtual void Process(AddDbItemArgs args)
 {
   args.DbItem.VersionsCount.Add(Language.Current.Name, 1);
 }
Пример #27
0
 public virtual void Process(AddDbItemArgs args)
 {
     args.DbItem.AddVersion(Language.Current.Name);
 }
Пример #28
0
 public virtual void Process(AddDbItemArgs args)
 {
   args.DbItem.AddVersion(Language.Current.Name);
 }
Пример #29
0
 public virtual void Process(AddDbItemArgs args)
 {
     args.DbItem.VersionsCount.Add(Language.Current.Name, 1);
 }