mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-06 20:30:27 +08:00
Update scope 'accessible_by_teams' and fix load_vars method in controllers
This commit is contained in:
parent
b1dba8013a
commit
dc4751e49a
4 changed files with 10 additions and 8 deletions
|
@ -304,7 +304,7 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
def load_vars
|
def load_vars
|
||||||
repository_id = params[:id] || params[:repository_id]
|
repository_id = params[:id] || params[:repository_id]
|
||||||
@repository = current_team.repositories.find_by_id(repository_id)
|
@repository = Repository.accessible_by_teams(current_team).find_by_id(repository_id)
|
||||||
render_404 unless @repository
|
render_404 unless @repository
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -173,14 +173,14 @@ class RepositoryColumnsController < ApplicationController
|
||||||
AvailableRepositoryColumn = Struct.new(:id, :name)
|
AvailableRepositoryColumn = Struct.new(:id, :name)
|
||||||
|
|
||||||
def load_vars
|
def load_vars
|
||||||
@repository = current_team.repositories.find_by_id(params[:repository_id])
|
@repository = Repository.accessible_by_teams(current_team).find_by_id(params[:repository_id])
|
||||||
render_404 unless @repository
|
render_404 unless @repository
|
||||||
@repository_column = @repository.repository_columns.find_by_id(params[:id])
|
@repository_column = @repository.repository_columns.find_by_id(params[:id])
|
||||||
render_404 unless @repository_column
|
render_404 unless @repository_column
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_vars_nested
|
def load_vars_nested
|
||||||
@repository = current_team.repositories.find_by_id(params[:repository_id])
|
@repository = Repository.accessible_by_teams(current_team).find_by_id(params[:repository_id])
|
||||||
render_404 unless @repository
|
render_404 unless @repository
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -348,9 +348,10 @@ class RepositoryRowsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_vars
|
def load_vars
|
||||||
@repository = current_team.repositories
|
@repository = Repository.accessible_by_teams(current_team)
|
||||||
.eager_load(:repository_columns)
|
.eager_load(:repository_columns)
|
||||||
.find_by_id(params[:repository_id])
|
.find_by_id(params[:repository_id])
|
||||||
|
|
||||||
@record = @repository.repository_rows
|
@record = @repository.repository_rows
|
||||||
.eager_load(:repository_columns)
|
.eager_load(:repository_columns)
|
||||||
.find_by_id(params[:id])
|
.find_by_id(params[:id])
|
||||||
|
@ -358,7 +359,7 @@ class RepositoryRowsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_repository
|
def load_repository
|
||||||
@repository = current_team.repositories.find_by_id(params[:repository_id])
|
@repository = Repository.accessible_by_teams(current_team).find_by_id(params[:repository_id])
|
||||||
render_404 unless @repository
|
render_404 unless @repository
|
||||||
render_403 unless can_read_repository?(@repository)
|
render_403 unless can_read_repository?(@repository)
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,8 @@ class Repository < ApplicationRecord
|
||||||
scope :accessible_by_teams, lambda { |teams|
|
scope :accessible_by_teams, lambda { |teams|
|
||||||
left_outer_joins(:team_repositories)
|
left_outer_joins(:team_repositories)
|
||||||
.where('repositories.team_id IN (?) OR team_repositories.team_id IN (?)', teams, teams)
|
.where('repositories.team_id IN (?) OR team_repositories.team_id IN (?)', teams, teams)
|
||||||
.uniq.sort_by(&:created_at)
|
.distinct
|
||||||
|
.order(:created_at)
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.search(
|
def self.search(
|
||||||
|
|
Loading…
Add table
Reference in a new issue