diff --git a/app/controllers/accounts/join_codes_controller.rb b/app/controllers/accounts/join_codes_controller.rb index 52e909de8..b6f08bf3c 100644 --- a/app/controllers/accounts/join_codes_controller.rb +++ b/app/controllers/accounts/join_codes_controller.rb @@ -1,10 +1,10 @@ class Accounts::JoinCodesController < ApplicationController def show - render svg: RQRCode::QRCode.new(join_url(Current.account.join_code)).as_svg(viewbox: true, fill: :white, color: :black) + render svg: RQRCode::QRCode.new(join_url(Account.sole.join_code)).as_svg(viewbox: true, fill: :white, color: :black) end def update - Current.account.reset_join_code - redirect_to account_users_path + Account.sole.reset_join_code + redirect_to users_path end end diff --git a/app/controllers/accounts/users_controller.rb b/app/controllers/accounts/users_controller.rb index 7243677de..1ee4a15c6 100644 --- a/app/controllers/accounts/users_controller.rb +++ b/app/controllers/accounts/users_controller.rb @@ -3,22 +3,22 @@ class Accounts::UsersController < ApplicationController before_action :ensure_permission_to_administer_user, only: %i[ update destroy ] def index - @users = Current.account.users.active + @users = User.active end def update @user.update(role_params) - redirect_to account_users_path + redirect_to users_path end def destroy @user.deactivate - redirect_to account_users_path + redirect_to users_path end private def set_user - @user = Current.account.users.active.find(params[:id]) + @user = User.active.find(params[:id]) end def ensure_permission_to_administer_user diff --git a/app/controllers/cards/stagings_controller.rb b/app/controllers/cards/stagings_controller.rb index af524fa52..02cbd61af 100644 --- a/app/controllers/cards/stagings_controller.rb +++ b/app/controllers/cards/stagings_controller.rb @@ -3,7 +3,7 @@ class Cards::StagingsController < ApplicationController def create if params[:stage_id].present? - @card.toggle_stage Current.account.stages.find(params[:stage_id]) + @card.toggle_stage Stage.find(params[:stage_id]) else @card.update!(stage: nil) end diff --git a/app/controllers/cards/taggings_controller.rb b/app/controllers/cards/taggings_controller.rb index f75681c9d..bf17628fd 100644 --- a/app/controllers/cards/taggings_controller.rb +++ b/app/controllers/cards/taggings_controller.rb @@ -2,7 +2,7 @@ class Cards::TaggingsController < ApplicationController include CardScoped def new - @tags = Current.account.tags.alphabetically + @tags = Tag.alphabetically end def create diff --git a/app/controllers/collections/workflows_controller.rb b/app/controllers/collections/workflows_controller.rb index 963feb595..31a8cb715 100644 --- a/app/controllers/collections/workflows_controller.rb +++ b/app/controllers/collections/workflows_controller.rb @@ -11,6 +11,6 @@ class Collections::WorkflowsController < ApplicationController private def set_workflow - @workflow = Current.account.workflows.find(params.expect(collection: [ :workflow_id ]).require(:workflow_id)) + @workflow = Workflow.find(params.expect(collection: [ :workflow_id ]).require(:workflow_id)) end end diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 3eb8cb507..36698afdf 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -2,11 +2,11 @@ class CollectionsController < ApplicationController before_action :set_collection, except: %i[ new create ] def new - @collection = Current.account.collections.build + @collection = Collection.new end def create - @collection = Current.account.collections.create! collection_params + @collection = Collection.create! collection_params redirect_to cards_path(collection_ids: [ @collection ]) end @@ -37,7 +37,7 @@ class CollectionsController < ApplicationController end def grantees - Current.account.users.active.where id: grantee_ids + User.active.where id: grantee_ids end def revokees diff --git a/app/controllers/concerns/events_timeline.rb b/app/controllers/concerns/events_timeline.rb index 0946907bb..0d50d2093 100644 --- a/app/controllers/concerns/events_timeline.rb +++ b/app/controllers/concerns/events_timeline.rb @@ -29,7 +29,7 @@ module EventsTimeline end def user_events - Event.where(card: user_cards, creator: Current.account.users) + Event.where(card: user_cards) end def user_cards diff --git a/app/controllers/concerns/workflow_scoped.rb b/app/controllers/concerns/workflow_scoped.rb index ca2e7398c..8e358733a 100644 --- a/app/controllers/concerns/workflow_scoped.rb +++ b/app/controllers/concerns/workflow_scoped.rb @@ -7,6 +7,6 @@ module WorkflowScoped private def set_workflow - @workflow = Current.account.workflows.find params[:workflow_id] + @workflow = Workflow.find(params[:workflow_id]) end end diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 1c2af5a53..35e587a99 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -5,7 +5,8 @@ class UploadsController < ApplicationController before_action :set_attachment, only: :show def create - @upload = Current.account.uploads_attachments.create! blob: create_blob! + # FIXME: Try to get upload attachments on root + @upload = Account.first.uploads_attachments.create! blob: create_blob! end def show diff --git a/app/controllers/users/avatars_controller.rb b/app/controllers/users/avatars_controller.rb index e48a1f7f2..46deb691e 100644 --- a/app/controllers/users/avatars_controller.rb +++ b/app/controllers/users/avatars_controller.rb @@ -24,7 +24,7 @@ class Users::AvatarsController < ApplicationController end def set_user - @user = Current.account.users.find(params[:user_id]) + @user = User.find(params[:user_id]) end def render_avatar_or_initials diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 32e5c340c..f460b4d5c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,11 +5,11 @@ class UsersController < ApplicationController before_action :set_account_from_join_code, only: %i[ new create ] def new - @user = @account.users.build + @user = User.new end def create - user = @account.users.create!(user_params) + user = User.create!(user_params) start_new_session_for user redirect_to root_path end @@ -21,8 +21,8 @@ class UsersController < ApplicationController end def update - @user.update user_params - redirect_to user_path(@user) + @user.update! user_params + redirect_to @user end private @@ -31,7 +31,7 @@ class UsersController < ApplicationController end def set_user - @user = Current.account.users.active.find(params[:id]) + @user = User.active.find(params[:id]) end def user_params diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb index 390cedcdb..fb2682988 100644 --- a/app/controllers/workflows_controller.rb +++ b/app/controllers/workflows_controller.rb @@ -2,15 +2,15 @@ class WorkflowsController < ApplicationController before_action :set_workflow, only: %i[ show edit update destroy ] def index - @workflows = Current.account.workflows + @workflows = Workflow.all end def new - @workflow = Current.account.workflows.new + @workflow = Workflow.new end def create - @workflow = Current.account.workflows.create! workflow_params + @workflow = Workflow.create! workflow_params # FIXME: this should definitely change. [ "Triage", "In progress", "On Hold", "Review" ].each { |name| @workflow.stages.create! name: name } redirect_to workflows_path @@ -34,10 +34,10 @@ class WorkflowsController < ApplicationController private def set_workflow - @workflow = Current.account.workflows.find params[:id] + @workflow = Workflow.find params[:id] end def workflow_params - params.expect workflow: [ :name ] + params.expect workflow: :name end end diff --git a/app/models/account.rb b/app/models/account.rb index 10ba9f773..f562ef665 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,21 +1,5 @@ class Account < ApplicationRecord - include ClosureReasons, Joinable - - has_many :collections, dependent: :destroy - has_many :cards, through: :collections - - has_many :users, dependent: :destroy do - def system - find_or_create_system_user(proxy_association.owner) - end - end - - has_many :comments, through: :users - - has_many :workflows, dependent: :destroy - has_many :stages, through: :workflows, class_name: "Workflow::Stage" - - has_many :tags, dependent: :destroy + include Joinable has_many_attached :uploads end diff --git a/app/models/account/closure_reasons.rb b/app/models/account/closure_reasons.rb deleted file mode 100644 index e5bdf25a1..000000000 --- a/app/models/account/closure_reasons.rb +++ /dev/null @@ -1,29 +0,0 @@ -module Account::ClosureReasons - extend ActiveSupport::Concern - - DEFAULT_LABELS = [ - "Completed", - "Duplicate", - "Maybe later", - "Working as intended" - ] - - FALLBACK_LABEL = "Done" - - included do - has_many :closure_reasons, dependent: :destroy, class_name: "Closure::Reason" do - def labels - pluck(:label).presence || [ FALLBACK_LABEL ] - end - end - - after_create :create_default_closure_reasons - end - - private - def create_default_closure_reasons - DEFAULT_LABELS.each do |label| - closure_reasons.create! label: label - end - end -end diff --git a/app/models/card/closeable.rb b/app/models/card/closeable.rb index 3f98cb719..ce0a63e33 100644 --- a/app/models/card/closeable.rb +++ b/app/models/card/closeable.rb @@ -16,7 +16,7 @@ module Card::Closeable class_methods do def auto_close_all_due due_to_be_closed.find_each do |card| - card.close(user: card.collection.account.users.system, reason: "Closed") + card.close(user: User.system, reason: "Closed") end end end @@ -41,7 +41,7 @@ module Card::Closeable closure&.created_at end - def close(user: Current.user, reason: Account::ClosureReasons::FALLBACK_LABEL) + def close(user: Current.user, reason: Closure::Reason::FALLBACK_LABEL) unless closed? transaction do create_closure! user: user, reason: reason diff --git a/app/models/card/taggable.rb b/app/models/card/taggable.rb index a419a4cae..5ad75a593 100644 --- a/app/models/card/taggable.rb +++ b/app/models/card/taggable.rb @@ -9,7 +9,7 @@ module Card::Taggable end def toggle_tag_with(title) - tag = collection.account.tags.find_or_create_by!(title: title) + tag = Tag.find_or_create_by!(title: title) transaction do if tagged_with?(tag) diff --git a/app/models/closure/reason.rb b/app/models/closure/reason.rb index aa1f0161b..1472d09d1 100644 --- a/app/models/closure/reason.rb +++ b/app/models/closure/reason.rb @@ -1,3 +1,22 @@ class Closure::Reason < ApplicationRecord - belongs_to :account + DEFAULT_LABELS = [ + "Completed", + "Duplicate", + "Maybe later", + "Working as intended" + ] + + FALLBACK_LABEL = "Done" + + class << self + def labels + pluck(:label).presence || [ FALLBACK_LABEL ] + end + + def create_defaults + DEFAULT_LABELS.each do |label| + create! label: label + end + end + end end diff --git a/app/models/collection.rb b/app/models/collection.rb index 3820af5a1..319b2bb7d 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -1,7 +1,6 @@ class Collection < ApplicationRecord include Accessible, Broadcastable, Filterable - belongs_to :account belongs_to :creator, class_name: "User", default: -> { Current.user } belongs_to :workflow, optional: true diff --git a/app/models/collection/accessible.rb b/app/models/collection/accessible.rb index 81ed9b5b1..fc99cc217 100644 --- a/app/models/collection/accessible.rb +++ b/app/models/collection/accessible.rb @@ -34,6 +34,6 @@ module Collection::Accessible private def grant_access_to_everyone - accesses.grant_to(account.users) if all_access_previously_changed?(to: true) + accesses.grant_to(User.all) if all_access_previously_changed?(to: true) end end diff --git a/app/models/collection/broadcastable.rb b/app/models/collection/broadcastable.rb index 5e36898d6..82d548f33 100644 --- a/app/models/collection/broadcastable.rb +++ b/app/models/collection/broadcastable.rb @@ -3,6 +3,6 @@ module Collection::Broadcastable included do broadcasts_refreshes - broadcasts_refreshes_to ->(collection) { [ collection.account, :collections ] } + broadcasts_refreshes_to ->(collection) { :collections } end end diff --git a/app/models/current.rb b/app/models/current.rb index e5546b93b..a4d0f0864 100644 --- a/app/models/current.rb +++ b/app/models/current.rb @@ -2,5 +2,4 @@ class Current < ActiveSupport::CurrentAttributes attribute :session delegate :user, to: :session, allow_nil: true - delegate :account, to: :user, allow_nil: true end diff --git a/app/models/first_run.rb b/app/models/first_run.rb index 4115b8715..aeee8c8a2 100644 --- a/app/models/first_run.rb +++ b/app/models/first_run.rb @@ -1,6 +1,7 @@ class FirstRun def self.create!(user_attributes) - account = Account.create!(name: "Fizzy") - account.users.member.create!(user_attributes) + Account.create!(name: "Fizzy") + User.member.create!(user_attributes) + Closure::Reason.create_defaults end end diff --git a/app/models/tag.rb b/app/models/tag.rb index 128a9aaac..eadaa72f9 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,8 +1,6 @@ class Tag < ApplicationRecord include Filterable - belongs_to :account, default: -> { Current.account }, touch: true - has_many :taggings, dependent: :destroy has_many :cards, through: :taggings diff --git a/app/models/user.rb b/app/models/user.rb index f1b6a0d1f..a22841c42 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,8 +1,6 @@ class User < ApplicationRecord include Accessor, Assignee, Avatar, Role, Transferable - belongs_to :account - has_many :sessions, dependent: :destroy has_secure_password validations: false diff --git a/app/models/user/accessor.rb b/app/models/user/accessor.rb index f6c902c50..89534b777 100644 --- a/app/models/user/accessor.rb +++ b/app/models/user/accessor.rb @@ -11,6 +11,6 @@ module User::Accessor private def grant_access_to_collections - Access.insert_all account.collections.all_access.pluck(:id).collect { |collection_id| { collection_id: collection_id, user_id: id } } + Access.insert_all Collection.all_access.pluck(:id).collect { |collection_id| { collection_id: collection_id, user_id: id } } end end diff --git a/app/models/user/role.rb b/app/models/user/role.rb index 625361037..1b5648679 100644 --- a/app/models/user/role.rb +++ b/app/models/user/role.rb @@ -10,10 +10,8 @@ module User::Role end class_methods do - def find_or_create_system_user(account) - account.users.find_or_create_by!(role: :system) do |user| - user.name = "System" - end + def system + find_or_create_by!(role: :system) { it.name = "System" } end end diff --git a/app/models/workflow.rb b/app/models/workflow.rb index 164d3eb47..df896cf09 100644 --- a/app/models/workflow.rb +++ b/app/models/workflow.rb @@ -1,4 +1,3 @@ class Workflow < ApplicationRecord - belongs_to :account has_many :stages, dependent: :delete_all end diff --git a/app/views/accounts/users/_invite.html.erb b/app/views/accounts/users/_invite.html.erb index e064d74bb..d6e99af78 100644 --- a/app/views/accounts/users/_invite.html.erb +++ b/app/views/accounts/users/_invite.html.erb @@ -1,5 +1,5 @@
- <% url = join_url(Current.account.join_code) %> + <% url = join_url(Account.sole.join_code) %>
- <% Current.account.users.active.order(:name).each do |user| %> + <% User.active.order(:name).each do |user| %> - <% Current.account.users.active.without(Current.user).order(:name).each do |user| %> + <% User.active.without(Current.user).order(:name).each do |user| %>