Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.

 

Turn Off Content Approvals on AssetFolders Or Uploaded Media

Vote:
 

CMS 10.10

I'm trying to disable programmatically the legacy of populating down Approval Sequence to local asset folder "for this page". 

"ApprovalDefinitionOperationException: Not allowed to create a ContentApprovalDefinition inside a local asset folder"

Even if I have a Approval Sequence on a page, I don't want its behavior on un uploaded image under "for this page", I want the image to be published automatically. 

                var folder = contentAssetHelper.GetOrCreateAssetFolder(page.ContentLink);

                if (folder != null)
                {
                    Task.Run(async () => { await (DisableContentApprovalDefinition(folder.ContentLink)); }).Wait(); 
                }

        public async Task DisableContentApprovalDefinition(ContentReference contentLink)
        {
            IApprovalDefinitionRepository definitionRepository= ServiceLocator.Current.GetInstance();

            // Gets a definition
            ApprovalDefinition definition = await definitionRepository.GetAsync(contentLink);
            if (definition == null) // allways null
            {
                definition = new ContentApprovalDefinition
                {
                    ContentLink = contentLink
                };
            }
            else
                definition = definition.CreateWritableClone();


            definition.IsEnabled = false;
            // Saves a definition
            await definitionRepository.SaveAsync(definition);
        }

Any ideas?

#183469
Edited, Oct 16, 2017 9:48
Vote:
 

The approvals wasn't the problem, it was the parents publish rights. Solved it by automatically publishing it when created:

        public void Initialize(InitializationEngine context)
        {
            IContentEvents events = ServiceLocator.Current.GetInstance<IContentEvents>();
            events.CreatedContent += CreatedContent;
        }

    
        private void CreatedContent(object sender, ContentEventArgs e)
        {

            if (e.Content != null && e.Content is ImageData)
            {
                SetPublished(e.Content as ImageData);
            }
        }

    private void SetPublished(ImageData content)
        {
            if (content.IsPendingPublish)
            {
                var clone = content.CreateWritableClone() as ImageData;
                var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
                contentRepository.Save(clone, SaveAction.Publish, AccessLevel.NoAccess);
            }
        }
#183470
Oct 16, 2017 10:33
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.