New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentRepository::AddAllowedChildTypes removes all existing and all but last item in contentTypes #512

Closed
tomaswangen opened this Issue Nov 8, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@tomaswangen
Copy link

tomaswangen commented Nov 8, 2018

public static string AddAllowedChildTypes(Content content, string[] contentTypes)

Actual behavior: Allowed content types on content is only the last element in contentTypes.

Expected behavior: Allowed content types on content are a union of contentTypes and pre-existing allowed contentTypes on content

@tusmester

This comment has been minimized.

Copy link
Member

tusmester commented Nov 8, 2018

Can you please tell us the type you are trying to add new allowed types to? E.g. is it a document library, a task list, a workspace?

@tomaswangen

This comment has been minimized.

Copy link
Author

tomaswangen commented Nov 9, 2018

Bug applies for all supported content types (eg DocumentLibrary) and is easily reproducible.

This code patches behavior (brute force):

        [ODataAction]
        public static string AddAllowedChildTypes(Content content, string[] contentTypes)
        {
            if (!(content.ContentHandler is GenericContent gc))
                return string.Empty;

            var currentTypes = gc.GetAllowedChildTypeNames().ToArray();
            gc.AllowChildTypes(contentTypes.Union(currentTypes).ToArray());

            gc.Save();

            return string.Empty;
        }

The root cause of the problem is that you for each contentType end up in:

private void SetAllowedChildTypes(IEnumerable<ContentType> contentTypes, bool save = false)
    
  var removeList = origTypes.Except(newTypes).ToArray();

  var list = origTypes.Union(newTypes).Distinct().Except(removeList);

@kultsar kultsar added this to the Sprint 171 milestone Nov 14, 2018

@kultsar kultsar added the bug label Nov 14, 2018

@kultsar kultsar modified the milestones: Sprint 171, Sprint 172 Nov 14, 2018

@kavics kavics self-assigned this Nov 21, 2018

@kultsar kultsar modified the milestones: Sprint 172, Sprint 173 Nov 28, 2018

@kultsar kultsar modified the milestones: Sprint 173, Sprint 174 Dec 12, 2018

@kultsar kultsar modified the milestones: Sprint 174, Sprint 175, Sprint 176 Jan 4, 2019

@kultsar kultsar closed this Jan 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment