Update item relationships & inventory permissions for inventory item card [SCI-12083] (#8649)

This commit is contained in:
Alex Kriuchykhin 2025-07-10 11:32:15 +02:00 committed by GitHub
parent 3164ebc323
commit 07142ad2c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 32 additions and 24 deletions

View file

@ -58,13 +58,11 @@ class RepositoryRowsController < ApplicationController
end
end
@assigned_modules = @repository_row.my_modules
.joins(experiment: :project)
.joins(:my_module_repository_rows)
.select('my_module_repository_rows.created_at, my_modules.*')
.order('my_module_repository_rows.created_at': :desc)
.distinct
@assigned_modules = @repository_row.my_modules.distinct
@viewable_modules = @assigned_modules.viewable_by_user(current_user, current_user.teams)
.joins(:my_module_repository_rows)
.select('my_module_repository_rows.created_at, my_modules.*')
.order(my_module_repository_rows: { created_at: :desc })
@reminders_present = @repository_row.repository_cells.with_active_reminder(@current_user).any?
end
end

View file

@ -190,7 +190,8 @@
:class="{ 'rotate-90': relationshipDetailsState[parent.code] }" />
<span>
<span>{{ i18n.t('repositories.item_card.relationships.item') }}</span>
<a :href="parent.path" class="record-info-link btn-text-link !text-sn-science-blue">{{ parent.name }}</a>
<a v-if="parent.path" :href="parent.path" class="record-info-link btn-text-link !text-sn-science-blue">{{ parent.name }}</a>
<span v-else>{{ parent.name }}</span>
<button v-if="permissions.can_connect_rows" @click="openUnlinkModal(parent)"
class=" ml-2 bg-transparent border-none opacity-0 group-hover:opacity-100 cursor-pointer">
<img :src="icons.unlink_path" />
@ -201,7 +202,7 @@
<span>
{{ i18n.t('repositories.item_card.relationships.id', { code: parent.code }) }}
</span>
<span>
<span v-if="parent.repository_name && parent.repository_path">
<span>{{ i18n.t('repositories.item_card.relationships.inventory') }}</span>
<a :href="parent.repository_path" class="btn-text-link !text-sn-science-blue">
{{ parent.repository_name }}
@ -240,7 +241,8 @@
:class="{ 'rotate-90': relationshipDetailsState[child.code] }"/>
<span class="group/child">
<span>{{ i18n.t('repositories.item_card.relationships.item') }}</span>
<a :href="child.path" class="record-info-link btn-text-link !text-sn-science-blue">{{ child.name }}</a>
<a v-if="child.path" :href="child.path" class="record-info-link btn-text-link !text-sn-science-blue">{{ child.name }}</a>
<span v-else>{{ child.name }}</span>
<button v-if="permissions.can_connect_rows" @click="openUnlinkModal(child)"
class="ml-2 bg-transparent border-none opacity-0 group-hover:opacity-100 cursor-pointer">
<img :src="icons.unlink_path" />
@ -249,7 +251,7 @@
</summary>
<p class="flex flex-col gap-3 ml-6 mb-4">
<span>{{ i18n.t('repositories.item_card.relationships.id', { code: child.code }) }}</span>
<span>
<span v-if="child.repository_name && child.repository_path">
<span>{{ i18n.t('repositories.item_card.relationships.inventory') }}</span>
<a :href="child.repository_path" class="btn-text-link !text-sn-science-blue">
{{ child.repository_name }}

View file

@ -23,9 +23,8 @@ module PermissionCheckableModel
.where('user_roles_team_assignments.permissions @> ARRAY[?]::varchar[]', permissions)
)
.distinct
where(id: with_granted_user_permissions.select(:id))
.or(where(id: with_granted_group_permissions.select(:id)))
where(id: with_granted_user_permissions.reselect(:id))
.or(where(id: with_granted_group_permissions.reselect(:id)))
}
end

View file

@ -7,7 +7,7 @@ class TeamAssignment < ApplicationRecord
belongs_to :assigned_by, class_name: 'User'
has_many :users, through: :team
enum assigned: { automatically: 0, manually: 1 }, _suffix: true
enum :assigned, { automatically: 0, manually: 1 }, suffix: true
validates :team, uniqueness: { scope: :assignable }
end

View file

@ -17,7 +17,7 @@ class UserAssignment < ApplicationRecord
belongs_to :team
belongs_to :assigned_by, class_name: 'User', optional: true
enum assigned: { automatically: 0, manually: 1 }, _suffix: true
enum :assigned, { automatically: 0, manually: 1 }, suffix: true
validates :user, uniqueness: { scope: %i(assignable team_id) }

View file

@ -7,7 +7,7 @@ class UserGroupAssignment < ApplicationRecord
belongs_to :user_role
belongs_to :assigned_by, class_name: 'User'
enum assigned: { automatically: 0, manually: 1 }, _suffix: true
enum :assigned, { automatically: 0, manually: 1 }, suffix: true
validates :user_group, uniqueness: { scope: %i(assignable team_id) }

View file

@ -87,10 +87,14 @@ json.relationships do
json.array! @repository_row.parent_repository_rows.preload(:repository).each do |parent|
json.id parent.id
json.code parent.code
json.name parent.name_with_label
json.path repository_repository_row_path(parent.repository, parent)
json.repository_name parent.repository.name_with_label
json.repository_path repository_path(parent.repository)
if can_read_repository?(parent.repository)
json.name parent.name_with_label
json.path repository_repository_row_path(parent.repository, parent)
json.repository_name parent.repository.name_with_label
json.repository_path repository_path(parent.repository)
else
json.name I18n.t('repositories.item_card.relationships.private_item_name')
end
json.unlink_path repository_repository_row_repository_row_connection_path(parent.repository,
parent,
@repository_row.parent_connections
@ -101,10 +105,14 @@ json.relationships do
json.array! @repository_row.child_repository_rows.preload(:repository).each do |child|
json.id child.id
json.code child.code
json.name child.name_with_label
json.path repository_repository_row_path(child.repository, child)
json.repository_name child.repository.name_with_label
json.repository_path repository_path(child.repository)
if can_read_repository?(child.repository)
json.name child.name_with_label
json.path repository_repository_row_path(child.repository, child)
json.repository_name child.repository.name_with_label
json.repository_path repository_path(child.repository)
else
json.name I18n.t('repositories.item_card.relationships.private_item_name')
end
json.unlink_path repository_repository_row_repository_row_connection_path(child.repository,
child,
@repository_row.child_connections

View file

@ -2842,6 +2842,7 @@ en:
item: "Item: "
inventory: "Inventory: "
empty: "This item has no relationships assigned."
private_item_name: "Private item"
parents:
count: "Parents (%{count})"
empty: ""