public void FieldUsingTokensAreCorrectlyOrdered()
        {
            var template = new ProvisioningTemplate();

            template.Parameters.Add("TestFieldPrefix", "PnP");


            var contentType = new ContentType
            {
                Id          = "0x010100503B9E20E5455344BFAC2292DC6FE805",
                Name        = "Test Content Type",
                Group       = "PnP",
                Description = "Test Description",
                Overwrite   = true,
                Hidden      = false
            };

            var nonOobField = new Field
            {
                SchemaXml = "<Field ID=\"{dd6b7dae-1281-458d-a66c-01b0c7b7930b}\" Name=\"{parameter:TestFieldPrefix}TestField\" DisplayName=\"TestField\" Type=\"Note\" Group=\"PnP\" Description=\"\" />"
            };

            template.SiteFields.Add(nonOobField);

            contentType.FieldRefs.Add(new FieldRef("{parameter:TestFieldPrefix}TestField")
            {
                Id = new Guid("{dd6b7dae-1281-458d-a66c-01b0c7b7930b}")
            });

            contentType.FieldRefs.Add(new FieldRef("AssignedTo")
            {
                Id = BuiltInFieldId.AssignedTo
            });
            template.ContentTypes.Add(contentType);

            using (var ctx = TestCommon.CreateClientContext())
            {
                TokenParser parser = new TokenParser(ctx.Web, template);
                new ObjectField().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
                new ObjectContentType().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
                var ct = ctx.Web.GetContentTypeByName("Test Content Type");
                ct.EnsureProperty(x => x.FieldLinks);
                Assert.AreEqual(ct.FieldLinks[0].Id, template.ContentTypes.First().FieldRefs[0].Id);
                Assert.AreEqual(ct.FieldLinks[1].Id, template.ContentTypes.First().FieldRefs[1].Id);
            }
        }
Exemplo n.º 2
0
        public void WorkflowTaskOutcomeFieldIsUnique()
        {
            var template = new ProvisioningTemplate();

            var contentType = new ContentType
            {
                Id          = "0x0108003365C4474CAE8C42BCE396314E88E51F008E5B850C364947248508D252250ED723",
                Name        = "Test Custom Outcome Workflow Task",
                Group       = "PnP",
                Description = "Ensure inherited workflow task displays correct custom OutcomeChoice",
                Overwrite   = true,
                Hidden      = false
            };

            var nonOobField = new Field
            {
                SchemaXml = "<Field ID=\"{35e4bd1f-c1a3-4bf2-bf86-4470c2e8bcfd}\" Type=\"OutcomeChoice\" StaticName=\"AuthorReviewOutcome\" Name=\"AuthorReviewOutcome\" DisplayName=\"AuthorReviewOutcome\" Group=\"PnP\">"
                            + "<Default>Approved</Default>"
                            + "<CHOICES>"
                            + "<CHOICE>Approved</CHOICE>"
                            + "<CHOICE>Rejected</CHOICE>"
                            + "<CHOICE>Reassign</CHOICE>"
                            + "</CHOICES>"
                            + "</Field>"
            };

            template.SiteFields.Add(nonOobField);

            contentType.FieldRefs.Add(new FieldRef("AuthorReviewOutcome")
            {
                Id = new Guid("{35e4bd1f-c1a3-4bf2-bf86-4470c2e8bcfd}")
            });

            template.ContentTypes.Add(contentType);

            using (var ctx = TestCommon.CreateClientContext())
            {
                TokenParser parser = new TokenParser(ctx.Web, template);
                new ObjectField(FieldAndListProvisioningStepHelper.Step.ListAndStandardFields).ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
                new ObjectContentType(FieldAndListProvisioningStepHelper.Step.ListAndStandardFields).ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
                var ct = ctx.Web.GetContentTypeByName("Test Custom Outcome Workflow Task");
                ct.EnsureProperty(x => x.Fields);
                Assert.AreEqual(ct.Fields.Count(f => f.FieldTypeKind == FieldType.OutcomeChoice), 1);
            }
        }
        public void FieldUsingTokensAreCorrectlyOrdered()
        {
            var template = new ProvisioningTemplate();

            template.Parameters.Add("TestFieldPrefix","PnP");
            

            var contentType = new ContentType
            {
                Id = "0x010100503B9E20E5455344BFAC2292DC6FE805",
                Name = "Test Content Type",
                Group = "PnP",
                Description = "Test Description",
                Overwrite = true,
                Hidden = false
            };

            var nonOobField = new Field
            {
                SchemaXml = "<Field ID=\"{dd6b7dae-1281-458d-a66c-01b0c7b7930b}\" Name=\"{parameter:TestFieldPrefix}TestField\" DisplayName=\"TestField\" Type=\"Note\" Group=\"PnP\" Description=\"\" />"
            };
            template.SiteFields.Add(nonOobField);

            contentType.FieldRefs.Add(new FieldRef("{parameter:TestFieldPrefix}TestField")
            {
                Id= new Guid("{dd6b7dae-1281-458d-a66c-01b0c7b7930b}")
            });

            contentType.FieldRefs.Add(new FieldRef("AssignedTo")
            {
                Id = BuiltInFieldId.AssignedTo
            });
            template.ContentTypes.Add(contentType);

            using (var ctx = TestCommon.CreateClientContext())
            {
                TokenParser parser = new TokenParser(ctx.Web, template);
                new ObjectField().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
                new ObjectContentType().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
                var ct = ctx.Web.GetContentTypeByName("Test Content Type");
                ct.EnsureProperty(x => x.FieldLinks);
                Assert.AreEqual(ct.FieldLinks[0].Id, template.ContentTypes.First().FieldRefs[0].Id);
                Assert.AreEqual(ct.FieldLinks[1].Id, template.ContentTypes.First().FieldRefs[1].Id);

            }


        }
Exemplo n.º 4
0
        public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateCreationInformation creationInfo)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                // if this is a sub site then we're not creating field entities.
                if (web.IsSubSite())
                {
                    scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns);
                    return template;
                }

                var existingFields = web.Fields;
                web.Context.Load(web, w => w.ServerRelativeUrl);
                web.Context.Load(existingFields);
                web.Context.Load(web.Lists, ls => ls.Include(l => l.Id, l => l.Title));
                web.Context.ExecuteQueryRetry();

                var taxTextFieldsToMoveUp = new List<Guid>();

                foreach (var field in existingFields)
                {
                    if (!BuiltInFieldId.Contains(field.Id))
                    {
                        if (creationInfo.ExecutePreProvisionEvent<Field,SPField>(Handlers.Fields, template, null, field))
                        {
                            var fieldXml = field.SchemaXml;
                            XElement element = XElement.Parse(fieldXml);

                            // Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths
                            var listIdentifier = element.Attribute("List") != null ? element.Attribute("List").Value : null;
                            if (!string.IsNullOrEmpty(listIdentifier))
                            {
                                var listGuid = Guid.Empty;
                                fieldXml = ParseFieldSchema(fieldXml, web.Lists);
                                element = XElement.Parse(fieldXml);
                                //if (Guid.TryParse(listIdentifier, out listGuid))
                                //{
                                //    fieldXml = ParseListSchema(fieldXml, web.Lists);
                                //if (newfieldXml == fieldXml)
                                //{
                                //    var list = web.Lists.GetById(listGuid);
                                //    web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl);
                                //    web.Context.ExecuteQueryRetry();

                                //    var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/');
                                //    element.Attribute("List").SetValue(listUrl);
                                //    fieldXml = element.ToString();
                                //}
                                //}
                            }
                            // Check if the field is of type TaxonomyField
                            if (field.TypeAsString.StartsWith("TaxonomyField"))
                            {
                                var taxField = (TaxonomyField)field;
                                web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id);
                                web.Context.ExecuteQueryRetry();
                                taxTextFieldsToMoveUp.Add(taxField.TextField);
                            }
                            // Check if we have version attribute. Remove if exists
                            if (element.Attribute("Version") != null)
                            {
                                element.Attributes("Version").Remove();
                                fieldXml = element.ToString();
                            }
                            Field templateField = new Field() { SchemaXml = fieldXml };
                            template.SiteFields.Add(templateField);

                            creationInfo.ExecutePostProvisionEvent<Field, SPField>(Handlers.Fields, template, templateField, field);
                        }
                    }
                }
                // move hidden taxonomy text fields to the top of the list
                foreach (var textFieldId in taxTextFieldsToMoveUp)
                {
                    var field = template.SiteFields.First(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId));
                    template.SiteFields.RemoveAll(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId));
                    template.SiteFields.Insert(0, field);
                }
                // If a base template is specified then use that one to "cleanup" the generated template model
                if (creationInfo.BaseTemplate != null)
                {
                    template = CleanupEntities(template, creationInfo.BaseTemplate);
                }
            }
            return template;
        }