mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-05 20:23:16 +08:00
Unlink items to other shared repositories on unsharing [SCI-10055] (#6981)
- Team A has Repository A with Item A - Team B - Team C has Repository C with Item C 1) Share Repository A and Repository C to Team B 2) Link Item A to Item C in Team B 3) Unshare Repository A from Team B Item A is unlinked to Item C
This commit is contained in:
parent
62f040d475
commit
e70889c001
1 changed files with 13 additions and 4 deletions
|
@ -58,6 +58,9 @@ class TeamSharedObject < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def unlink_unshared_items
|
def unlink_unshared_items
|
||||||
|
# We keep all the other teams shared with and the repository's own team
|
||||||
|
teams_ids = shared_object.teams_shared_with.where.not(id: team).pluck(:id)
|
||||||
|
teams_ids << shared_object.team_id
|
||||||
repository_rows_ids = shared_object.repository_rows.select(:id)
|
repository_rows_ids = shared_object.repository_rows.select(:id)
|
||||||
rows_to_unlink = RepositoryRow.joins("LEFT JOIN repository_row_connections \
|
rows_to_unlink = RepositoryRow.joins("LEFT JOIN repository_row_connections \
|
||||||
ON repository_rows.id = repository_row_connections.parent_id \
|
ON repository_rows.id = repository_row_connections.parent_id \
|
||||||
|
@ -67,11 +70,17 @@ class TeamSharedObject < ApplicationRecord
|
||||||
repository_rows_ids,
|
repository_rows_ids,
|
||||||
repository_rows_ids)
|
repository_rows_ids)
|
||||||
.joins(:repository)
|
.joins(:repository)
|
||||||
.where(repositories: { team: team })
|
.where.not(repositories: { team: teams_ids })
|
||||||
|
.select(:id)
|
||||||
|
|
||||||
RepositoryRowConnection.where(parent: rows_to_unlink, child: repository_rows_ids)
|
RepositoryRowConnection.where("(repository_row_connections.parent_id IN (?) \
|
||||||
.destroy_all
|
AND repository_row_connections.child_id IN (?)) \
|
||||||
RepositoryRowConnection.where(parent: repository_rows_ids, child: rows_to_unlink)
|
OR (repository_row_connections.parent_id IN (?) \
|
||||||
|
AND repository_row_connections.child_id IN (?))",
|
||||||
|
repository_rows_ids,
|
||||||
|
rows_to_unlink,
|
||||||
|
rows_to_unlink,
|
||||||
|
repository_rows_ids)
|
||||||
.destroy_all
|
.destroy_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue