When a moved issue is reopened, it can not be moved again
As part of the single codebase migration we are moving issues from gitlab-org/gitlab-ce to gitlab-org/gitlab-ee. While doing this we ran into errors when moving the following issues:
- https://gitlab.com/gitlab-org/gitlab-ce/issues/40045
- https://gitlab.com/gitlab-org/gitlab-ce/issues/42209
- https://gitlab.com/gitlab-org/gitlab-ce/issues/42349
- https://gitlab.com/gitlab-org/gitlab-ce/issues/45941
- https://gitlab.com/gitlab-org/gitlab-ce/issues/48414
- https://gitlab.com/gitlab-org/gitlab-ce/issues/49003
When moving these issues, the error produced is:
Cannot move issue due to insufficient permissions!
These issues were previously moved to a different project, then reopened (e.g. because the issue was moved by accident). It seems that once this is done, GitLab will never let you move the issues again.
Looking at the data, these issues all have the moved_to_id
value set. In Issue#moved?
we check the presence of this value to determine if an issue has been moved. In Issue#can_move?
we use this method to determine if an issue can be moved as follows:
def can_move?(user, to_project = nil)
if to_project
return false unless user.can?(:admin_issue, to_project)
end
!moved? && persisted? &&
user.can?(:admin_issue, self.project)
end
There is nothing wrong with wanting to move an issue again if it is open, so we should change this code to make this possible. This would need something along the lines of this:
def can_move?(user, to_project = nil)
if to_project
return false unless user.can?(:admin_issue, to_project)
end
return false unless persisted?
return false unless user.can?(:admin_issue, self.project)
return true if opened?
!moved?
end