Try our conversational search powered by Generative AI!

Move operation requires access level "Read, Delete" which the current user

Vote:
 

Hi,

I am trying to write an API that will move products from root directory to relevant sub-category. On contentrepository.Move(product, category) I am getting an exception as 

"Access was denied to content 33830__CatalogContent. The source page in this Move operation requires access level "Read, Delete" which the current user does not have."

What I am not able to figure out is which user account my API is using to connect with episerver, I know I can give Read, delete rights to a particular user in Admin section under Commerce menu.

Thanks,

Anurag

#189142
Mar 12, 2018 16:57
Vote:
 

Basically you would have to give the right to the user running the code. You can of course, set the current user (via PrincipalInfo.CurrentPrincipal) to an user with access rights.

#189146
Mar 12, 2018 17:19
Vote:
 

Hi Quan,

Thanks for your reply, I tried that, the problem is the API app that I have is running in read-only mode, I saw there are 2 additional parameters for providing access rights, I ended up doing this way...

_repo.Move(book.ContentLink, categoryToMove,AccessLevel.NoAccess,AccessLevel.NoAccess);

Although the error has gone now the product is still in the same category and hasn't moved to new one, so I thought I need to call _repo.SAVE(book, AccessLevel.NoAccess), and got the followign error :

You cannot save a content that is read-only. Call CreateWritableClone() on content and pass the cloned instance instead.

Any advice?

Thanks,

Anurag

#189183
Mar 13, 2018 11:42
Vote:
 

I'm not sure what do you mean "running in read-only mode"? Basically when you make changes to a content, you would have to create a writable clone first, but I don't think that is necessary in case you move them to a new parent. 

#189184
Mar 13, 2018 11:43
Vote:
 

By read-only I meant I am connecting to EpiserveDB using a database user and not going through the login process, the API application that I have is so far just reading information and not writing or deleting anything in DB, so so far it has worked without complaining about any access rights.

Now, this is the only API that will move content from one category to another, which requires access.

I am looking into WritableClone, hopefully, that will solve it, I will come back with my update.

#189188
Mar 13, 2018 11:51
Vote:
 

Hi,

Just an update, I ended up Adding and Removing NodeRelation to achieve what I wanted. I wanted to move a product in multiple categories, so I tried with MOVE() to move from Root to first category and then COPY() to multiple categories thereafter. Soon I realise that COPY() will create a new product so I tried with ServiceLocator.Current.GetInstance<ILinksRepository>(); UpdateRelation() and RemoveRelation((), this has finally worked for me.

https://world.episerver.com/documentation/items/developers-guide/episerver-commerce/8/content/product-variants/

        public void RemoveCategory(ContentReference referenceToEntryOrCategory, ContentReference referenceToCategory)
        {
            var linksRepository = ServiceLocator.Current.GetInstance<ILinksRepository>();
            var relationToRemove = new NodeRelation
            {
                Source = referenceToEntryOrCategory,
                Target = referenceToCategory
            };

            linksRepository.RemoveRelation(relationToRemove);
        }

        public void AddCategory(ContentReference referenceToEntryOrCategory, ContentReference referenceToCategory)
        {
            var linksRepository = ServiceLocator.Current.GetInstance<ILinksRepository>();

            var newCategory = new NodeRelation
            {
                SortOrder = 100,
                Source = referenceToEntryOrCategory,
                Target = referenceToCategory
            };

            linksRepository.UpdateRelation(newCategory);
        }

Although on CMS I can still see my product under Root Category, the Belongs To tabs shows new categories, Upon restart it removes it from Root Category.

I guess somewhere their is Cache which gets flushed out on the restart, I need to check that next.

Thanks,

Anurag

#189218
Edited, Mar 13, 2018 16:29
Vote:
 

ILinksRepository is deprecated and will be removed.

You can just replace it with IRelationRepository, it has the operations you need.

#189293
Mar 14, 2018 16:29
Vote:
 

Correct, but not entirely correct - he should use Parent/Child property as well.

This is why mentioning the version in your question is important. The APIs change - and for us to provide the most accurate and up-to-date answers, we need to know the version you are using.

#189297
Mar 14, 2018 17:28
* 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.