diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index c043b3f52..1dba6c6bf 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -222,6 +222,9 @@ def set_form_variables .select { |type, _| type.nil? || (type.published? && !type.story_specific? && !type.profile_specific?) } .sort_by { |type, _| type&.name.to_s.downcase } @sectors = Sector.published.order(:name) + @authors = authorized_scope(User.has_access.or(User.where(id: @event.author_id))) + .includes(:person) + .map { |u| [ u.full_name, u.id ] }.sort_by(&:first) end def set_event @@ -230,6 +233,7 @@ def set_event def event_params params.require(:event).permit(:cost, + :author_id, :created_by_id, :location_id, :title, diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index a519531a7..d9c781e89 100644 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -149,10 +149,9 @@ def set_form_variables @resource.build_downloadable_asset if @resource.downloadable_asset.blank? @resource.gallery_assets.build @windows_types = WindowsType.all - @authors = authorized_scope(User.has_access.or(User.where(id: @resource.created_by_id))) + @authors = authorized_scope(User.has_access.or(User.where(id: @resource.author_id))) .includes(:person) - .order("people.first_name, people.last_name") - .map { |u| [ u.full_name, u.id ] } + .map { |u| [ u.full_name, u.id ] }.sort_by(&:first) @categories_grouped = Category .includes(:category_type) @@ -171,7 +170,7 @@ def resource_id_param def resource_params params.require(:resource).permit( :rhino_body, :kind, :male, :female, :title, :featured, :published, :publicly_visible, :publicly_featured, - :agency, :author, :filemaker_code, :windows_type_id, :position, + :agency, :author, :author_id, :filemaker_code, :windows_type_id, :position, primary_asset_attributes: [ :id, :file, :_destroy ], downloadable_asset_attributes: [ :id, :file, :_destroy ], gallery_assets_attributes: [ :id, :file, :_destroy ], diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 493cfcd3c..84c8cf5ab 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -9,7 +9,7 @@ def index if turbo_frame_request? per_page = params[:number_of_items_per_page].presence || 12 base_scope = authorized_scope(Story.includes(:windows_type, :organization, :workshop, - :created_by, :bookmarks, :primary_asset, + :author, :created_by, :bookmarks, :primary_asset, :story_idea)) filtered = base_scope.search_by_params(params) sortable = %w[title updated_at created_at windows_type workshop author organization] @@ -131,6 +131,9 @@ def set_form_variables .order(:created_at) @people = Person.order(Arel.sql("LOWER(first_name), LOWER(last_name)")) @users = User.has_access.includes(:person).left_joins(:person).order(Arel.sql("people.first_name IS NULL, LOWER(people.first_name), LOWER(people.last_name), LOWER(users.email)")) + @authors = authorized_scope(User.has_access.or(User.where(id: @story.author_id))) + .includes(:person) + .map { |u| [ u.full_name, u.id ] }.sort_by(&:first) @windows_types = WindowsType.all @workshops = authorized_scope(Workshop.all).includes(:windows_type).order(:title) @categories_grouped = @@ -173,7 +176,7 @@ def apply_sort(scope, column, direction) scope.left_joins(:workshop) .reorder(Workshop.arel_table[:title].public_send(dir)) when "author" - scope.left_joins(created_by: :person) + scope.left_joins(author: :person) .reorder(Person.arel_table[:first_name].public_send(dir)) when "organization" scope.left_joins(:organization) @@ -188,7 +191,7 @@ def story_params params.require(:story).permit( :title, :rhino_body, :featured, :published, :publicly_visible, :publicly_featured, :youtube_url, :website_url, :windows_type_id, :organization_id, :workshop_id, :external_workshop_title, - :created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id, :author_credit_preference, + :author_id, :created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id, :author_credit_preference, category_ids: [], sector_ids: [], primary_asset_attributes: [ :id, :file, :_destroy ], diff --git a/app/controllers/tutorials_controller.rb b/app/controllers/tutorials_controller.rb index b6e2ddd15..ad6842a03 100644 --- a/app/controllers/tutorials_controller.rb +++ b/app/controllers/tutorials_controller.rb @@ -42,6 +42,7 @@ def edit def create @tutorial = Tutorial.new(tutorial_params) + @tutorial.created_by ||= current_user authorize! @tutorial success = false @@ -108,6 +109,9 @@ def set_form_variables .select { |type, _| type.nil? || type.published? } .sort_by { |type, _| type&.name.to_s.downcase } @sectors = Sector.published.order(:name) + @authors = authorized_scope(User.has_access.or(User.where(id: @tutorial.author_id))) + .includes(:person) + .map { |u| [ u.full_name, u.id ] }.sort_by(&:first) end private @@ -120,6 +124,7 @@ def set_tutorial def tutorial_params params.require(:tutorial).permit( :title, :body, :rhino_body, :position, :youtube_url, + :author_id, :created_by_id, :featured, :published, :publicly_visible, :publicly_featured, category_ids: [], sector_ids: [], diff --git a/app/models/event.rb b/app/models/event.rb index 8f67557f0..19668d69f 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -5,6 +5,7 @@ class Event < ApplicationRecord has_rich_text :rhino_header has_rich_text :rhino_description + belongs_to :author, class_name: "User", optional: true belongs_to :created_by, class_name: "User", optional: true belongs_to :location, optional: true has_many :bookmarks, as: :bookmarkable, dependent: :destroy diff --git a/app/models/resource.rb b/app/models/resource.rb index 0981c9fe0..80d154b10 100644 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -14,6 +14,7 @@ def self.mentionable_rich_text_fields has_rich_text :rhino_body + belongs_to :author, class_name: "User", optional: true belongs_to :created_by, class_name: "User" belongs_to :workshop, optional: true belongs_to :windows_type, optional: true diff --git a/app/models/story.rb b/app/models/story.rb index cf5833992..9e2768d74 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -4,6 +4,7 @@ class Story < ApplicationRecord has_rich_text :rhino_body + belongs_to :author, class_name: "User", optional: true belongs_to :created_by, class_name: "User" belongs_to :updated_by, class_name: "User" belongs_to :windows_type @@ -48,7 +49,7 @@ class Story < ApplicationRecord attributes person_first: "people.first_name", person_last: "people.last_name" options :all, type: :text, default: true, default_operator: :or - scope { join_rich_texts.left_joins(created_by: :person) } + scope { join_rich_texts.left_joins(author: :person) } attributes action_text_body: "action_text_rich_texts.plain_text_body" options :action_text_body, type: :text, default: true, default_operator: :or end diff --git a/app/models/tutorial.rb b/app/models/tutorial.rb index 88936a372..d03774d86 100644 --- a/app/models/tutorial.rb +++ b/app/models/tutorial.rb @@ -3,6 +3,9 @@ class Tutorial < ApplicationRecord has_rich_text :rhino_body + belongs_to :author, class_name: "User", optional: true + belongs_to :created_by, class_name: "User", optional: true + has_many :bookmarks, as: :bookmarkable, dependent: :destroy has_many :categorizable_items, dependent: :destroy, inverse_of: :categorizable, as: :categorizable has_many :sectorable_items, dependent: :destroy, inverse_of: :sectorable, as: :sectorable diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index fe725c838..bc02d545c 100644 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -411,8 +411,20 @@ <% end %> +