[Step2|BE] Define snippet multi action specification

Now that we almost have the new snippet_files param in the services and in GraphQL API, we need to define the info that array will have and check that once the services get it, they apply the proper changes.

I propose to use the same definition we have for the web IDE. In the following image, we have what info we need to pass per each action:

image

We need to ensure that Snippets::CreateService and Snippets::UpdateService can apply that definition to the repository properly.

For the Snippets::CreateService we need to ensure that we only accept create actions, because others don't make sense.

We need to update as well the validation in SnippetInputAction to match the necessary requirements according to the action.

After checking with FE, the specification of the actions and the fields inside them, is like this:

  • Create action. We will use this action to create files with content
    • action -> create
    • file_path
    • content
  • Update action. We will use this action to update only the file content
    • action -> update
    • file_path
    • content
    • Optional (but not needed at all): previous_path. If present, it's value has to be the same as file_path.
  • Delete action. We will use this action to delete files
    • action -> delete
    • file_path
  • Move action. We will use this action to rename files or to rename files + update content at the same time.
    • action -> move
    • file_path
    • previous_path. Its value has to be different from file_path
    • Optional: content

For this we have to update the following:

  • In the Snippets::UpdateService we have to update https://gitlab.com/gitlab-org/gitlab/blob/master/app/services/snippets/update_service.rb#L41 to only set the content if it is present in the action. If we have an action like delete without a content and we don't change this, the content in the db will always be set to nil.
  • Update SnippetInputAction:
    • For the move action, add a validation to ensure that the previous_path is different from the file_path
  • Add specs for the Snippets::UpdateService to check every action and the combination of them.
Edited by Francisco Javier López