Skip to content

Commit

Permalink
allow to queue some github handles into the organization
Browse files Browse the repository at this point in the history
  • Loading branch information
evsasse committed Dec 13, 2024
1 parent c4545d9 commit 5e372d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class User < ApplicationRecord
devise :database_authenticatable, :omniauthable, :trackable, omniauth_providers: [ :github ]
validates :handle, :email, presence: true, uniqueness: true

after_create_commit :check_organization_queues

# Called by the `omniauth_callbacks_controller.rb`
def self.from_omniauth(auth)
find_or_create_by(provider: auth.provider, uid: auth.uid) do |user|
Expand All @@ -20,4 +22,17 @@ def self.from_omniauth(auth)
def self.find_by_handle(handle)
find_by("handle LIKE ?", handle)
end

private

def check_organization_queues
# TODO: Could be obviously improved with some SQL...
Organization.all.each do |organization|
next unless organization.user_queue.include?(self.handle)

OrganizationUser.create!(organization:, user: self)
organization.user_queue.delete(self.handle)
organization.save!
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20241213203004_add_org_user_queue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOrgUserQueue < ActiveRecord::Migration[8.0]
def change
add_column :organizations, :user_queue, :jsonb, null: false, default: []
end
end

0 comments on commit 5e372d4

Please sign in to comment.