From 0108cca6c5202a265c52ccbb56fbc11c8627f1cc Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Sat, 9 Dec 2023 10:23:02 +0100 Subject: [PATCH] Remove default scope in coder model --- app/controllers/coders_controller.rb | 5 +++-- app/controllers/pages_controller.rb | 6 ++++-- app/controllers/repositories_controller.rb | 3 ++- app/models/coder.rb | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/coders_controller.rb b/app/controllers/coders_controller.rb index 5038c6d..043055e 100644 --- a/app/controllers/coders_controller.rb +++ b/app/controllers/coders_controller.rb @@ -2,11 +2,12 @@ class CodersController < ApplicationController def index @sort_column = params[:order_by] @sort_column = 'score' unless %w[score commit_count additions deletions repository_count].include?(@sort_column) - @coders = Coder.extending(CommitStats).with_commit_stats.with_repository_count.order({ @sort_column => :desc }) + @coders = Coder.in_organisation.extending(CommitStats).with_commit_stats.with_repository_count.order({ @sort_column => :desc }) end def show - @coder = Coder.extending(CommitStats) + @coder = Coder.in_organisation + .extending(CommitStats) .with_commit_stats .with_repository_count .find(params[:id]) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index e32143a..066e461 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,6 +1,7 @@ class PagesController < ApplicationController def top4 - @coders = Coder.extending(CommitStats).with_commit_stats + @coders = Coder.in_organisation + .extending(CommitStats).with_commit_stats .where(commits: { committed_at: 1.week.ago.. }) .order(score: :desc) .limit(4) @@ -11,7 +12,8 @@ def top4 .take(4).map do |repo| [ repo, - Coder.extending(CommitStats).with_commit_stats + Coder.in_organisation + .extending(CommitStats).with_commit_stats .where(repositories: { id: repo.id }, commits: { committed_at: 1.week.ago.. }) .order(score: :desc) ] diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index ad16088..9bef3c2 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -10,7 +10,8 @@ def show @sort_column = params[:order_by] @sort_column = 'score' unless %w[score commit_count additions deletions].include?(@sort_column) - @coders = Coder.extending(CommitStats) + @coders = Coder.in_organisation + .extending(CommitStats) .with_commit_stats .where(commits: { repository_id: @repository.id }) .order({ @sort_column => :desc }) diff --git a/app/models/coder.rb b/app/models/coder.rb index 5f47c08..ff4f85a 100644 --- a/app/models/coder.rb +++ b/app/models/coder.rb @@ -17,13 +17,13 @@ class Coder < ApplicationRecord validates :github_name, uniqueness: true - default_scope -> { where(github_name: OrganisationMember.select(:github_name)) } + scope :in_organisation, -> { where(github_name: OrganisationMember.select(:github_name)) } def self.from_github(rc, repo) commit = Rails.application.config.github.repos.commits.get(repo.organisation, repo.name, rc.oid) return nil if commit.author&.login.blank? - Coder.unscoped.find_or_create_by(github_name: commit.author.login) do |c| + Coder.find_or_create_by(github_name: commit.author.login) do |c| Rails.application.config.github.users.get(user: commit.author.login).tap do |data| c.full_name = data.try(:name) || '' c.avatar_url = data.avatar_url