diff --git a/Gemfile.lock b/Gemfile.lock index bf1443fef..cde1846d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -133,7 +133,7 @@ GEM bigdecimal (4.0.1) bootsnap (1.21.1) msgpack (~> 1.2) - brakeman (8.0.1) + brakeman (8.0.2) racc builder (3.3.0) bullet (8.1.0) @@ -668,7 +668,7 @@ CHECKSUMS bigdecimal (4.0.1) sha256=8b07d3d065a9f921c80ceaea7c9d4ae596697295b584c296fe599dd0ad01c4a7 binding_of_caller (1.0.1) bootsnap (1.21.1) sha256=9373acfe732da35846623c337d3481af8ce77c7b3a927fb50e9aa92b46dbc4c4 - brakeman (8.0.1) sha256=c68ce0ac35a6295027c4eab8b4ac597d2a0bfc82f0d62dcd334bbf944d352f70 + brakeman (8.0.2) sha256=7b02065ce8b1de93949cefd3f2ad78e8eb370e644b95c8556a32a912a782426a builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f bullet (8.1.0) sha256=604b7e2636ec2137dcab3ba61a56248c39a0004a0c9405d58bad0686d23b98ff bundler-audit (0.9.3) sha256=81c8766c71e47d0d28a0f98c7eed028539f21a6ea3cd8f685eb6f42333c9b4e9 diff --git a/app/controllers/admin/analytics_controller.rb b/app/controllers/admin/analytics_controller.rb index 4ab57c745..1e02d86d5 100644 --- a/app/controllers/admin/analytics_controller.rb +++ b/app/controllers/admin/analytics_controller.rb @@ -14,7 +14,7 @@ def index @most_viewed_stories = decorate_with_counts(most_viewed_for_model(Story, time_scope), :view_count) @most_viewed_quotes = decorate_with_counts(most_viewed_for_model(Quote, time_scope), :view_count) @most_viewed_tutorials = decorate_with_counts(most_viewed_for_model(Tutorial, time_scope), :view_count) - @most_viewed_projects = decorate_with_counts(most_viewed_for_model(Project, time_scope), :view_count) + @most_viewed_organizations = decorate_with_counts(most_viewed_for_model(Organization, time_scope), :view_count) @most_viewed_events = decorate_with_counts(most_viewed_for_model(Event, time_scope), :view_count) @most_viewed_facilitators = decorate_with_counts(most_viewed_for_model(Facilitator, time_scope), :view_count) @@ -25,7 +25,7 @@ def index # @most_printed_workshop_variations = decorate_with_counts(most_printed_for_model(WorkshopVariation, time_scope), :print_count) # @most_printed_quotes = decorate_with_counts(most_printed_for_model(Quote, time_scope), :print_count) # @most_printed_tutorials = decorate_with_counts(most_printed_for_model(Tutorial, time_scope), :print_count) - # @most_printed_projects = decorate_with_counts(most_printed_for_model(Project, time_scope), :print_count) + # @most_printed_organizations = decorate_with_counts(most_printed_for_model(Organization, time_scope), :print_count) # @most_printed_events = decorate_with_counts(most_printed_for_model(Event, time_scope), :print_count) @most_downloaded_resources = decorate_with_counts(most_downloaded_for_model(Resource, time_scope), :download_count) @@ -67,9 +67,9 @@ def index views: view_count_for_model(Tutorial, time_scope), prints: print_count_for_model(Tutorial, time_scope) }, - projects: { - views: view_count_for_model(Project, time_scope), - prints: print_count_for_model(Project, time_scope) + organizations: { + views: view_count_for_model(Organization, time_scope), + prints: print_count_for_model(Organization, time_scope) }, facilitators: { views: view_count_for_model(Facilitator, time_scope) diff --git a/app/controllers/community_news_controller.rb b/app/controllers/community_news_controller.rb index 759b53138..e900d51e4 100644 --- a/app/controllers/community_news_controller.rb +++ b/app/controllers/community_news_controller.rb @@ -7,7 +7,7 @@ def index per_page = params[:number_of_items_per_page].presence || 12 unfiltered = current_user.super_user? ? CommunityNews.all : CommunityNews.published filtered = unfiltered.search_by_params(params) - @community_news = filtered&.includes([ :bookmarks, :primary_asset, :author, :project, author: :facilitator ]) + @community_news = filtered&.includes([ :bookmarks, :primary_asset, :author, :organization, author: :facilitator ]) &.paginate(page: params[:page], per_page: per_page)&.decorate @count_display = if filtered.count == unfiltered.count @@ -79,7 +79,7 @@ def destroy # Optional hooks for setting variables for forms or index def set_form_variables - @organizations = Project.pluck(:name, :id).sort_by(&:first) + @organizations = Organization.pluck(:name, :id).sort_by(&:first) @authors = User.active.or(User.where(id: @community_news.author_id)) .map { |u| [ u.full_name, u.id ] }.sort_by(&:first) end @@ -95,7 +95,7 @@ def community_news_params params.require(:community_news).permit( :title, :rhino_body, :published, :featured, :public, :public_featured, :reference_url, :youtube_url, - :project_id, + :organization_id, :author_id, :created_by_id, :updated_by_id ) end diff --git a/app/controllers/facilitators_controller.rb b/app/controllers/facilitators_controller.rb index 55024e94f..7da35082b 100644 --- a/app/controllers/facilitators_controller.rb +++ b/app/controllers/facilitators_controller.rb @@ -7,7 +7,7 @@ def index facilitators = Facilitator .searchable .search_by_params(params.to_unsafe_h) - .includes(:user, :avatar_attachment, :sectorable_items, user: [ :avatar_attachment, :projects ]).references(:user) + .includes(:user, :avatar_attachment, :sectorable_items, user: [ :avatar_attachment, :organizations ]).references(:user) .order(:first_name, :last_name) @count_display = facilitators.size @facilitators = facilitators.paginate(page: params[:page], per_page: per_page) @@ -82,14 +82,14 @@ def set_form_variables # @facilitator.build_user if @facilitator.user.blank? # Build a fresh one if missing if @facilitator.user - @facilitator.user.project_users.first || @facilitator.user.project_users.build + @facilitator.user.organization_users.first || @facilitator.user.organization_users.build end - projects = if current_user.super_user? - Project.active + organizations = if current_user.super_user? + Organization.active else - current_user.projects + current_user.organizations end - @projects_array = projects.order(:name).pluck(:name, :id) + @organizations_array = organizations.order(:name).pluck(:name, :id) end @@ -177,9 +177,9 @@ def facilitator_params :state2, :zip2, :notes, - project_users_attributes: [ + organization_users_attributes: [ :id, - :project_id, + :organization_id, :position, :title, :inactive, diff --git a/app/controllers/monthly_reports_controller.rb b/app/controllers/monthly_reports_controller.rb index 1aff7c7e2..aed686694 100644 --- a/app/controllers/monthly_reports_controller.rb +++ b/app/controllers/monthly_reports_controller.rb @@ -38,7 +38,7 @@ def create @form_builder = FormBuilder.find(@report.owner_id) build_month_and_year load_agencies - @agency_id = report_params["project_id"] + @agency_id = report_params["organization_id"] flash[:alert] = "There was a problem submitting your form: " + "#{@report.errors.full_messages.join(" ")}" @@ -61,7 +61,7 @@ def edit build_month_and_year find_form_builder @report = Report.find(params[:id]) - @agencies = current_user.projects. + @agencies = current_user.organizations. where(windows_type_id: @report.windows_type_id) @month = @report.date.month @year = @report.date.year @@ -85,7 +85,7 @@ def update flash[:notice] = "Thanks for reporting on a update report. " redirect_to root_path else - @agencies = current_user.projects. + @agencies = current_user.organizations. where(windows_type_id: @report.windows_type_id) flash[:alert] = "ERROR!!!!!!!!!!!!!!" @@ -102,7 +102,7 @@ def show @answers = @monthly_report.report_form_field_answers if @monthly_report - if current_user.super_user? || (@monthly_report.project && current_user.project_ids.include?(@monthly_report.project.id)) + if current_user.super_user? || (@monthly_report.organization && current_user.organization_ids.include?(@monthly_report.organization.id)) render :show else redirect_to root_path, error: "You do not have permission to view this page." @@ -116,7 +116,7 @@ def show private def load_agencies - @agencies = current_user.projects. + @agencies = current_user.organizations. where(windows_type_id: @form_builder.windows_type_id).uniq end @@ -143,7 +143,7 @@ def find_form_builder .decorate end - agency = params[:agency_id] ? Project.find(params[:agency_id]) : current_user.projects.where(windows_type_id: @form_builder.windows_type).first + agency = params[:agency_id] ? Organization.find(params[:agency_id]) : current_user.organizations.where(windows_type_id: @form_builder.windows_type).first @agency_id = agency.id unless agency.nil? end @@ -196,7 +196,7 @@ def build_report_form_fields end def find_workshop_logs - @workshop_logs = current_user.project_monthly_workshop_logs( + @workshop_logs = current_user.organization_monthly_workshop_logs( @report.date, @report.windows_type ) @@ -207,7 +207,7 @@ def find_workshop_logs def find_combined_workshop_logs(agency_id) combined_windows_type = WindowsType.where(short_name: "COMBINED").first - @combined_workshop_logs = current_user.project_workshop_logs( + @combined_workshop_logs = current_user.organization_workshop_logs( @report.date, combined_windows_type, agency_id) end @@ -225,7 +225,7 @@ def report_params end params.require(:report).permit( - :type, :project_id, :date, :owner_id, :workshop_id, + :type, :organization_id, :date, :owner_id, :workshop_id, :owner_type, :windows_type_id, :other_description, media_files_attributes: [ :file ], report_form_field_answers_attributes: diff --git a/app/controllers/organization_statuses_controller.rb b/app/controllers/organization_statuses_controller.rb new file mode 100644 index 000000000..bf7441d60 --- /dev/null +++ b/app/controllers/organization_statuses_controller.rb @@ -0,0 +1,68 @@ +class OrganizationStatusesController < Admin::BaseController + before_action :set_organization_status, only: [ :show, :edit, :update, :destroy ] + + def index + per_page = params[:number_of_items_per_page].presence || 25 + unfiltered = OrganizationStatus.all + @count_display = unfiltered.count + @organization_statuses = unfiltered.paginate(page: params[:page], per_page: per_page).decorate + end + + def show + @organization_status = @organization_status.decorate + end + + def new + @organization_status = OrganizationStatus.new.decorate + set_form_variables + end + + def edit + @organization_status = @organization_status.decorate + set_form_variables + end + + def create + @organization_status = OrganizationStatus.new(organization_status_params) + + if @organization_status.save + redirect_to organization_statuses_path, notice: "Organization status was successfully created." + else + @organization_status = OrganizationStatus.new.decorate + set_form_variables + render :new, status: :unprocessable_content + end + end + + def update + if @organization_status.update(organization_status_params) + redirect_to organization_statuses_path, notice: "Organization status was successfully updated.", status: :see_other + else + @organization_status = OrganizationStatus.new.decorate + set_form_variables + render :edit, status: :unprocessable_content + end + end + + def destroy + @organization_status.destroy! + redirect_to organization_statuses_path, notice: "Organization status was successfully destroyed." + end + + # Optional hooks for setting variables for forms or index + def set_form_variables + end + + private + + def set_organization_status + @organization_status = OrganizationStatus.find(params[:id]) + end + + # Strong parameters + def organization_status_params + params.require(:organization_status).permit( + :name + ) + end +end diff --git a/app/controllers/organization_users_controller.rb b/app/controllers/organization_users_controller.rb new file mode 100644 index 000000000..400a3db27 --- /dev/null +++ b/app/controllers/organization_users_controller.rb @@ -0,0 +1,13 @@ +class OrganizationUsersController < ApplicationController + def destroy + organization_user = OrganizationUser.find(params[:id]) + user = organization_user.user + + if organization_user.destroy + flash[:notice] = "Organization user has been deleted." + else + flash[:alert] = "Unable to delete organization user. Please contact AWBW." + end + redirect_to generate_facilitator_user_path(user) + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/organizations_controller.rb similarity index 56% rename from app/controllers/projects_controller.rb rename to app/controllers/organizations_controller.rb index 7138afcf1..bc38312b2 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -1,40 +1,39 @@ -class ProjectsController < ApplicationController +class OrganizationsController < ApplicationController include AhoyTracking - before_action :set_project, only: [ :show, :edit, :update, :destroy ] + before_action :set_organization, only: [ :show, :edit, :update, :destroy ] def index per_page = params[:number_of_items_per_page].presence || 25 - unpaginated = Project.includes(:logo_attachment, :windows_type, :project_status).search_by_params(params).order(:name) - @projects_count = unpaginated.count - @projects = unpaginated.paginate(page: params[:page], per_page: per_page) + unpaginated = Organization.includes(:logo_attachment, :windows_type, :organization_status) + .search_by_params(params).order(:name) + @organizations_count = unpaginated.count + @organizations = unpaginated.paginate(page: params[:page], per_page: per_page) set_index_variables end def show - track_view(@project) + track_view(@organization) - workshop_logs = WorkshopLog.where(project_id: @project.id) + workshop_logs = WorkshopLog.where(organization_id: @organization.id) @month_year_options = workshop_logs.group("DATE_FORMAT(COALESCE(date, created_at, NOW()), '%Y-%m')") - .select("DATE_FORMAT(COALESCE(date, created_at, NOW()), '%Y-%m') AS ym, + .select("DATE_FORMAT(COALESCE(date, created_at, NOW()), '%Y-%m') AS ym, MAX(COALESCE(date, created_at)) AS max_dt") - .order("max_dt DESC") - .map { |record| [ Date.strptime(record.ym, "%Y-%m").strftime("%B %Y"), record.ym ] } + .order("max_dt DESC") + .map { |record| [ Date.strptime(record.ym, "%Y-%m").strftime("%B %Y"), record.ym ] } @year_options = workshop_logs.pluck( Arel.sql("DISTINCT EXTRACT(YEAR FROM COALESCE(date, created_at, NOW()))") ).sort.reverse - @projects = Project.where(id: @project.id) + @organizations = Organization.where(id: @organization.id) @per_page = params[:per_page] || 10 @workshop_logs_unpaginated = workshop_logs @workshop_logs_count = @workshop_logs_unpaginated.size @workshop_logs = @workshop_logs_unpaginated.paginate(page: params[:page], per_page: @per_page) - user_ids = @workshop_logs_unpaginated.select(:user_id) - @workshops = Workshop.includes(:windows_type) .published .references(:windows_type) .order("workshops.title ASC, windows_types.name ASC") - + user_ids = @workshop_logs_unpaginated.select(:user_id) @facilitators = User.active .or(User.where(id: user_ids)) .distinct @@ -42,7 +41,7 @@ def show end def new - @project = Project.new + @organization = Organization.new set_form_variables end @@ -51,10 +50,10 @@ def edit end def create - @project = Project.new(project_params) + @organization = Organization.new(organization_params) - if @project.save - redirect_to projects_path, notice: "Organization was successfully created." + if @organization.save + redirect_to organizations_path, notice: "Organization was successfully created." else set_form_variables render :new, status: :unprocessable_content @@ -62,8 +61,8 @@ def create end def update - if @project.update(project_params) - redirect_to projects_path, notice: "Organization was successfully updated.", status: :see_other + if @organization.update(organization_params) + redirect_to organizations_path, notice: "Organization was successfully updated.", status: :see_other else set_form_variables render :edit, status: :unprocessable_content @@ -71,44 +70,43 @@ def update end def destroy - @project.destroy! - redirect_to projects_path, notice: "Organization was successfully destroyed." + @organization.destroy! + redirect_to organizations_path, notice: "Organization was successfully destroyed." end # Optional hooks for setting variables for forms or index def set_form_variables - @project_statuses = ProjectStatus.all - @facilitators_array = Facilitator.includes(:user) - .joins(:user) + @organization_statuses = OrganizationStatus.all + @facilitators_array = Facilitator.joins(:user) .order(:first_name, :last_name) .map { |f| [ f.name, f.user.id ] } - @project.project_users = @project.project_users - .includes(:project) - .sort_by { |pu| pu.user.facilitator&.name.to_s.downcase } + @organization.organization_users = @organization.organization_users + .includes(:organization) + .sort_by { |ou| ou.user.facilitator&.name.to_s.downcase } end def set_index_variables - @project_statuses = ProjectStatus.all + @organization_statuses = OrganizationStatus.all end private - def set_project - @project = Project.find(params[:id]) + def set_organization + @organization = Organization.find(params[:id]) end # Strong parameters - def project_params - params.require(:project).permit( + def organization_params + params.require(:organization).permit( :name, :description, :start_date, :end_date, :mission_vision_values, :internal_id, :inactive, :logo, :notes, :agency_type, :agency_type_other, :website_url, - :project_status_id, :location_id, :windows_type_id, + :organization_status_id, :location_id, :windows_type_id, sectorable_items_attributes: [ :id, :sector_id, :_destroy ], - project_users_attributes: [ + organization_users_attributes: [ :id, :user_id, :inactive, diff --git a/app/controllers/project_statuses_controller.rb b/app/controllers/project_statuses_controller.rb deleted file mode 100644 index c3abc4319..000000000 --- a/app/controllers/project_statuses_controller.rb +++ /dev/null @@ -1,68 +0,0 @@ -class ProjectStatusesController < Admin::BaseController - before_action :set_project_status, only: [ :show, :edit, :update, :destroy ] - - def index - per_page = params[:number_of_items_per_page].presence || 25 - unfiltered = ProjectStatus.all - @count_display = unfiltered.count - @project_statuses = unfiltered.paginate(page: params[:page], per_page: per_page).decorate - end - - def show - @project_status = @project_status.decorate - end - - def new - @project_status = ProjectStatus.new.decorate - set_form_variables - end - - def edit - @project_status = @project_status.decorate - set_form_variables - end - - def create - @project_status = ProjectStatus.new(project_status_params) - - if @project_status.save - redirect_to project_statuses_path, notice: "Project status was successfully created." - else - @project_status = ProjectStatus.new.decorate - set_form_variables - render :new, status: :unprocessable_content - end - end - - def update - if @project_status.update(project_status_params) - redirect_to project_statuses_path, notice: "Project status was successfully updated.", status: :see_other - else - @project_status = ProjectStatus.new.decorate - set_form_variables - render :edit, status: :unprocessable_content - end - end - - def destroy - @project_status.destroy! - redirect_to project_statuses_path, notice: "Project status was successfully destroyed." - end - - # Optional hooks for setting variables for forms or index - def set_form_variables - end - - private - - def set_project_status - @project_status = ProjectStatus.find(params[:id]) - end - - # Strong parameters - def project_status_params - params.require(:project_status).permit( - :name - ) - end -end diff --git a/app/controllers/project_users_controller.rb b/app/controllers/project_users_controller.rb deleted file mode 100644 index e0e7d535a..000000000 --- a/app/controllers/project_users_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -class ProjectUsersController < ApplicationController - def destroy - project_user = ProjectUser.find(params[:id]) - user = project_user.user - - if project_user.destroy - flash[:notice] = "Project user has been deleted." - else - flash[:alert] = "Unable to delete project user. Please contact AWBW." - end - redirect_to generate_facilitator_user_path(user) - end -end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 0e75dac83..b52fcc83e 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -27,7 +27,7 @@ def share_story @report.owner_type = "FormBuilder" @report.owner_id = 7 - @agencies = current_user.projects + @agencies = current_user.organizations end def render_form @@ -46,7 +46,7 @@ def edit build_month_and_year find_form_builder @report = current_user.submitted_monthly_report(@date, @form_builder.windows_type) - @agencies = current_user.projects. + @agencies = current_user.organizations. where(windows_type_id: @report.windows_type_id) @month = @report.date.month @year = @report.date.year @@ -60,7 +60,7 @@ def edit_story .order(title: :asc) @report = Report.find(params[:id]) - @agencies = current_user.projects. + @agencies = current_user.organizations. where(windows_type_id: @report.windows_type_id) end @@ -79,7 +79,7 @@ def update_story flash[:notice] = "Thanks for reporting on a update report. " redirect_to root_path else - @agencies = current_user.projects. + @agencies = current_user.organizations. where(windows_type_id: @report.windows_type_id) flash[:alert] = "ERROR!!!!!!!!!!!!!!" @@ -105,7 +105,7 @@ def update flash[:notice] = "Thanks for reporting on a update report. " redirect_to root_path else - @agencies = current_user.projects. + @agencies = current_user.organizations. where(windows_type_id: @report.windows_type_id) flash[:alert] = "ERROR!!!!!!!!!!!!!!" @@ -159,7 +159,7 @@ def create_story @report.windows_type_id = Workshop.find(@report.workshop_id).windows_type_id else @report.workshop_id = nil - @report.windows_type_id = @report.project.windows_type_id + @report.windows_type_id = @report.organization.windows_type_id end if @report.save @@ -233,7 +233,7 @@ def build_report_form_fields end def find_workshop_logs - @workshop_logs = current_user.project_monthly_workshop_logs( + @workshop_logs = current_user.organization_monthly_workshop_logs( @report.date, @report.windows_type ) @@ -256,7 +256,7 @@ def report_params end params.require(:report).permit( - :image, :form_file, :type, :project_id, :date, :workshop_name, :owner_id, :workshop_id, + :image, :form_file, :type, :organization_id, :date, :workshop_name, :owner_id, :workshop_id, :owner_type, :windows_type_id, report_form_field_answers_attributes: [ :form_field_id, :answer_option_id, :answer, :_create ], media_files_attributes: [ :file ], diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 63ca6e7ca..5f7042106 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -6,7 +6,7 @@ def index if turbo_frame_request? per_page = params[:number_of_items_per_page].presence || 12 unpaginated = current_user.super_user? ? Story.all : Story.published - filtered = unpaginated.includes(:windows_type, :project, :workshop, :created_by, :bookmarks, :primary_asset) + filtered = unpaginated.includes(:windows_type, :organization, :workshop, :created_by, :bookmarks, :primary_asset) .search_by_params(params) .order(created_at: :desc) @stories = filtered.paginate(page: params[:page], per_page: per_page).decorate @@ -90,7 +90,7 @@ def destroy def set_form_variables @story_idea = StoryIdea.find(params[:story_idea_id]) if params[:story_idea_id].present? @user = User.find(params[:user_id]) if params[:user_id].present? - @projects = (@user || current_user).projects.order(:name) + @organizations = (@user || current_user).organizations.order(:name) @story_ideas = StoryIdea.includes(:created_by) .references(:users) .order(:created_at) @@ -111,7 +111,7 @@ def set_story def story_params params.require(:story).permit( :title, :rhino_body, :featured, :published, :public, :public_featued, :youtube_url, :website_url, - :windows_type_id, :project_id, :workshop_id, :external_workshop_title, + :windows_type_id, :organization_id, :workshop_id, :external_workshop_title, :created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id ) end @@ -119,7 +119,7 @@ def story_params def set_story_attributes_from(idea) { rhino_body: idea.body, - project_id: idea.project.id, + organization_id: idea.organization.id, workshop_id: idea.workshop_id, external_workshop_title: idea.external_workshop_title, windows_type_id: idea.windows_type_id, diff --git a/app/controllers/story_ideas_controller.rb b/app/controllers/story_ideas_controller.rb index ff58bfa9e..77dc75824 100644 --- a/app/controllers/story_ideas_controller.rb +++ b/app/controllers/story_ideas_controller.rb @@ -6,7 +6,7 @@ def index per_page = params[:number_of_items_per_page].presence || 25 - story_ideas = StoryIdea.includes(:windows_type, :project, :workshop, :created_by, :updated_by) + story_ideas = StoryIdea.includes(:windows_type, :organization, :workshop, :created_by, :updated_by) @story_ideas = story_ideas.order(created_at: :desc) .paginate(page: params[:page], per_page: per_page).decorate @@ -64,7 +64,7 @@ def destroy # Optional hooks for setting variables for forms or index def set_form_variables @user = User.find(params[:user_id]) if params[:user_id].present? - @projects = (@user || current_user).projects.order(:name) + @organizations = (@user || current_user).organizations.order(:name) @windows_types = WindowsType.all @workshops = Workshop.all.order(:title) @users = User.active.or(User.where(id: @story_idea.created_by_id)) @@ -82,7 +82,7 @@ def story_idea_params params.require(:story_idea).permit( :title, :body, :youtube_url, :permission_given, :publish_preferences, :promoted_to_story, - :windows_type_id, :project_id, :workshop_id, :external_workshop_title, + :windows_type_id, :organization_id, :workshop_id, :external_workshop_title, :created_by_id, :updated_by_id, ) end diff --git a/app/controllers/taggings_controller.rb b/app/controllers/taggings_controller.rb index c5c192d79..6252eb5f0 100644 --- a/app/controllers/taggings_controller.rb +++ b/app/controllers/taggings_controller.rb @@ -13,7 +13,7 @@ def index community_news: params[:community_news_page], events: params[:events_page], facilitators: params[:facilitators_page], - projects: params[:projects_page], + organizations: params[:organizations_page], quotes: params[:quotes_page] } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0419fbbac..4fa69bf00 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -153,13 +153,13 @@ def set_facilitator def set_form_variables set_facilitator - @user.project_users.first || @user.project_users.build - projects = if current_user.super_user? - Project.active + @user.organization_users.first || @user.organization_users.build + organizations = if current_user.super_user? + Organization.active else - current_user.projects + current_user.organizations end - @projects_array = projects.order(:name).pluck(:name, :id) + @organizations_array = organizations.order(:name).pluck(:name, :id) end def password_param @@ -178,7 +178,7 @@ def user_params :notes, :primary_address, :avatar, :subscribecode, :agency_id, :facilitator_id, :created_by_id, :updated_by_id, :confirmed, :inactive, :super_user, :legacy, :legacy_id, - project_users_attributes: [ :id, :project_id, :position, :title, :inactive, :_destroy ] + organization_users_attributes: [ :id, :organization_id, :position, :title, :inactive, :_destroy ] ) end end diff --git a/app/controllers/workshop_log_creation_wizard_controller.rb b/app/controllers/workshop_log_creation_wizard_controller.rb index b07a34106..bd8980769 100644 --- a/app/controllers/workshop_log_creation_wizard_controller.rb +++ b/app/controllers/workshop_log_creation_wizard_controller.rb @@ -6,7 +6,7 @@ class WorkshopLogCreationWizardController < ApplicationController def show @user = current_user - @agencies = current_user.projects + @agencies = current_user.organizations windows_type_id = params[:windows_type_id] || WindowsType.where(short_name: "COMBINED") @windows_type = WindowsType.find(windows_type_id) if windows_type_id send(step) @@ -15,7 +15,7 @@ def show def update @user = current_user - @agencies = current_user.projects + @agencies = current_user.organizations windows_type_id = params["workshop"]["workshop_logs_attributes"].values[0]["windows_type_id"] @windows_type = WindowsType.find(windows_type_id) send("update_#{step}") @@ -155,7 +155,7 @@ def workshop_params :title, :date, :windows_type_id, workshop_logs_attributes: [ :user_id, :rating, :reaction, :similarities, :is_embodied_art_workshop, :successes, :challenges, :differences, :date, - :suggestions, :questions, :lead_similar, :project_id, + :suggestions, :questions, :lead_similar, :organization_id, :num_participants_on_going, :num_participants_first_time, report_form_field_answers_attributes: [ :form_field_id, :answer_option_id, :answer, :_create ] diff --git a/app/controllers/workshop_logs_controller.rb b/app/controllers/workshop_logs_controller.rb index 888ac75d2..bef8e0228 100644 --- a/app/controllers/workshop_logs_controller.rb +++ b/app/controllers/workshop_logs_controller.rb @@ -9,7 +9,7 @@ def index WorkshopLog.all else WorkshopLog.where(created_by_id: current_user.id) - .or(WorkshopLog.project_id(current_user.project_ids)) + .or(WorkshopLog.organization_id(current_user.organization_ids)) end @workshop_logs_unpaginated = permitted_logs.includes(:workshop, :user, :windows_type) .search(params) @@ -83,7 +83,7 @@ def show @answers = @workshop_log.report_form_field_answers if @workshop_log - if current_user.super_user? || (@workshop_log.project && current_user.project_ids.include?(@workshop_log.project.id)) + if current_user.super_user? || (@workshop_log.organization && current_user.organization_ids.include?(@workshop_log.organization.id)) render :show else redirect_to root_path, error: "You do not have permission to view this page." @@ -104,7 +104,7 @@ def edit def validate_new @date = Date.new(params[:year].to_i, params[:month].to_i) @windows_type = WindowsType.find(params[:windows_type]) - @report = current_user.submitted_monthly_report(@date, @windows_type, params[:project_id]) + @report = current_user.submitted_monthly_report(@date, @windows_type, params[:organization_id]) render json: { validate: @report.nil? }.to_json end @@ -124,11 +124,11 @@ def set_index_variables # needs to not be private .joins(:workshop_logs) .distinct .order(:last_name, :first_name) - @projects = if current_user.super_user? - # Project.where(id: @workshop_logs_unpaginated.pluck(:project_id)).order(:name) - Project.active.order(:name) + @organizations = if current_user.super_user? + # Organization.where(id: @workshop_logs_unpaginated.pluck(:organization_id)).order(:name) + Organization.active.order(:name) else - current_user.projects.order(:name) + current_user.organizations.order(:name) end @workshops = Workshop.where(id: @workshop_logs_unpaginated.select(:workshop_id).distinct) .order(:title) @@ -182,11 +182,11 @@ def set_form_variables end @agencies = - Project.where(id: current_user.projects.select(:id)) - .or(Project.where(id: @workshop_log.project_id)) - .distinct - .order(:name) - agency = params[:agency_id].present? ? Project.where(id: params[:agency_id]).last : @agencies.first + Organization.where(id: current_user.organizations.select(:id)) + .or(Organization.where(id: @workshop_log.organization_id)) + .distinct + .order(:name) + agency = params[:agency_id].present? ? Organization.where(id: params[:agency_id]).last : @agencies.first @agency_id = agency.id if agency end @@ -210,7 +210,7 @@ def set_workshop def workshop_log_params params.require(:workshop_log).permit( :children_ongoing, :children_first_time, :teens_ongoing, :teens_first_time, - :adults_ongoing, :adults_first_time, :owner_id, :owner_type, :user_id, :project_id, :date, + :adults_ongoing, :adults_first_time, :owner_id, :owner_type, :user_id, :organization_id, :date, :workshop_name, :workshop_id, :windows_type_id, :other_description, # :user, quotable_item_quotes_attributes: [ :id, :quotable_type, :quotable_id, :_destroy, diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb index 6b4bd05c9..6953dbcff 100644 --- a/app/controllers/workshops_controller.rb +++ b/app/controllers/workshops_controller.rb @@ -34,7 +34,7 @@ def summary types = reports.map do |r| r.windows_type end - @workshop_logs = current_user.project_monthly_workshop_logs( + @workshop_logs = current_user.organization_monthly_workshop_logs( reports.first.date, *types, ) @@ -43,7 +43,7 @@ def summary @total_first_time = logs.reduce(0) { |sum, l| sum += l.num_first_time } combined_windows_type = WindowsType.where(short_name: "COMBINED").first - @combined_workshop_logs = current_user.project_workshop_logs( + @combined_workshop_logs = current_user.organization_workshop_logs( @report.date, combined_windows_type, current_user.agency_id ) end diff --git a/app/decorators/facilitator_decorator.rb b/app/decorators/facilitator_decorator.rb index c0fb138b6..8ddbbabfb 100644 --- a/app/decorators/facilitator_decorator.rb +++ b/app/decorators/facilitator_decorator.rb @@ -4,7 +4,7 @@ def title end def detail(length: nil) - text = user.project_users.active.map { |pu| "#{pu.title.presence || pu.position}, #{pu.project.name}" }.join(", ") if user + text = user.organization_users.active.map { |pu| "#{pu.title.presence || pu.position}, #{pu.organization.name}" }.join(", ") if user length ? text&.truncate(length) : text end diff --git a/app/decorators/project_decorator.rb b/app/decorators/organization_decorator.rb similarity index 95% rename from app/decorators/project_decorator.rb rename to app/decorators/organization_decorator.rb index 4ac3de12a..7f8a76095 100644 --- a/app/decorators/project_decorator.rb +++ b/app/decorators/organization_decorator.rb @@ -1,4 +1,4 @@ -class ProjectDecorator < ApplicationDecorator +class OrganizationDecorator < ApplicationDecorator def detail(length: nil) length ? description&.truncate(length) : description end diff --git a/app/decorators/organization_status_decorator.rb b/app/decorators/organization_status_decorator.rb new file mode 100644 index 000000000..5c8d0ac80 --- /dev/null +++ b/app/decorators/organization_status_decorator.rb @@ -0,0 +1,3 @@ +class OrganizationStatusDecorator < Draper::Decorator + delegate_all +end diff --git a/app/decorators/organization_user_decorator.rb b/app/decorators/organization_user_decorator.rb new file mode 100644 index 000000000..ff7bd9386 --- /dev/null +++ b/app/decorators/organization_user_decorator.rb @@ -0,0 +1,5 @@ +class OrganizationUserDecorator < ApplicationDecorator + def detail(length: nil) + "#{user.full_name}: #{title.presence || position} - #{organization.name}" + end +end diff --git a/app/decorators/project_status_decorator.rb b/app/decorators/project_status_decorator.rb deleted file mode 100644 index b295e8491..000000000 --- a/app/decorators/project_status_decorator.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ProjectStatusDecorator < Draper::Decorator - delegate_all -end diff --git a/app/decorators/project_user_decorator.rb b/app/decorators/project_user_decorator.rb deleted file mode 100644 index eeeb34ac7..000000000 --- a/app/decorators/project_user_decorator.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ProjectUserDecorator < ApplicationDecorator - def detail(length: nil) - "#{user.full_name}: #{title.presence || position} - #{project.name}" - end -end diff --git a/app/decorators/workshop_decorator.rb b/app/decorators/workshop_decorator.rb index e04655de4..9d91fb57b 100644 --- a/app/decorators/workshop_decorator.rb +++ b/app/decorators/workshop_decorator.rb @@ -143,7 +143,7 @@ def labels_spanish creation_spanish: "Creación", closing_spanish: "Clausura", misc_instructions_spanish: "Instrucciones de misceláneos", - project_spanish: "Projecto", + organization_spanish: "Organización", description_spanish: "Descripción", notes_spanish: "Notas", tips_spanish: "Consejos", diff --git a/app/decorators/workshop_idea_decorator.rb b/app/decorators/workshop_idea_decorator.rb index 1a9d09081..477d7fd89 100644 --- a/app/decorators/workshop_idea_decorator.rb +++ b/app/decorators/workshop_idea_decorator.rb @@ -33,7 +33,7 @@ def labels_spanish creation_spanish: "Creación", closing_spanish: "Clausura", misc_instructions_spanish: "Instrucciones de misceláneos", - project_spanish: "Projecto", + organization_spanish: "Organización", description_spanish: "Descripción", notes_spanish: "Notas", tips_spanish: "Consejos" diff --git a/app/helpers/admin_cards_helper.rb b/app/helpers/admin_cards_helper.rb index aa91949e0..88e8f4792 100644 --- a/app/helpers/admin_cards_helper.rb +++ b/app/helpers/admin_cards_helper.rb @@ -13,7 +13,7 @@ def system_cards custom_card("Tagging counts", taggings_matrix_path, icon: "🧮", color: :lime), model_card(:resources, icon: "📚"), model_card(:workshops, icon: "🎨"), - model_card(:projects, icon: "🏫"), + model_card(:organizations, icon: "🏫"), model_card(:users, icon: "👥", title: "User accounts") ] end @@ -50,7 +50,7 @@ def reference_cards intensity: 100, title: "Service populations", params: { published_search: true }), - custom_card("Project statuses", project_statuses_path, icon: "🧮", color: :emerald, intensity: 100), + custom_card("Organization statuses", organization_statuses_path, icon: "🧮", color: :emerald, intensity: 100), custom_card("Windows types", windows_types_path, icon: "🪟") ] end diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 80e6ee0bf..9bca85ad3 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -2,7 +2,7 @@ class Bookmark < ApplicationRecord belongs_to :user belongs_to :bookmarkable, polymorphic: true - BOOKMARKABLE_MODELS = [ "CommunityNews", "Event", "Facilitator", "Project", "Resource", "Story", "StoryIdea", + BOOKMARKABLE_MODELS = [ "CommunityNews", "Event", "Facilitator", "Organization", "Resource", "Story", "StoryIdea", "Workshop", "WorkshopIdea", "WorkshopLog", "WorkshopVariation" ] scope :for_workshops, -> { where(bookmarkable_type: "Workshop") } @@ -55,7 +55,7 @@ def self.sort_by_title LEFT JOIN community_news ON community_news.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'CommunityNews' LEFT JOIN events ON events.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Event' LEFT JOIN facilitators ON facilitators.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Facilitator' - LEFT JOIN projects ON projects.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Project' + LEFT JOIN organizations ON organizations.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Organization' LEFT JOIN resources ON resources.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Resource' LEFT JOIN stories ON stories.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Story' LEFT JOIN story_ideas ON story_ideas.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'StoryIdea' @@ -70,7 +70,7 @@ def self.sort_by_title community_news.title, events.title, CONCAT(facilitators.first_name, ' ', facilitators.last_name), - projects.name, + organizations.name, resources.title, stories.title, story_ideas.title, @@ -93,7 +93,7 @@ def self.title(title) LEFT JOIN community_news ON community_news.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'CommunityNews' LEFT JOIN events ON events.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Event' LEFT JOIN facilitators ON facilitators.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Facilitator' - LEFT JOIN projects ON projects.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Project' + LEFT JOIN organizations ON organizations.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Organization' LEFT JOIN resources ON resources.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Resource' LEFT JOIN stories ON stories.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Story' LEFT JOIN story_ideas ON story_ideas.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'StoryIdea' @@ -105,7 +105,7 @@ def self.title(title) bookmarks.where( "community_news.title LIKE :title OR events.title LIKE :title OR facilitators.first_name LIKE :title OR - facilitators.last_name LIKE :title OR projects.name LIKE :title OR resources.title LIKE :title OR + facilitators.last_name LIKE :title OR organizations.name LIKE :title OR resources.title LIKE :title OR stories.title LIKE :title OR workshops.title LIKE :title OR workshop_ideas.title LIKE :title OR story_ideas.body LIKE :title OR -- searching body for story ideas (title exists but isn't used in UI) DATE_FORMAT(workshop_logs.date, '%Y-%m-%d') LIKE :title OR -- no title on workshop_logs diff --git a/app/models/community_news.rb b/app/models/community_news.rb index a9772e8a4..2d330b541 100644 --- a/app/models/community_news.rb +++ b/app/models/community_news.rb @@ -1,7 +1,7 @@ class CommunityNews < ApplicationRecord include TagFilterable, Trendable, WindowsTypeFilterable, RichTextSearchable - belongs_to :project, optional: true + belongs_to :organization, optional: true belongs_to :windows_type, optional: true belongs_to :author, class_name: "User", optional: true belongs_to :created_by, class_name: "User" diff --git a/app/models/facilitator.rb b/app/models/facilitator.rb index 51e4834ea..6ce5f5614 100644 --- a/app/models/facilitator.rb +++ b/app/models/facilitator.rb @@ -57,10 +57,10 @@ class Facilitator < ApplicationRecord scope :published, -> { active.searchable } scope :published, ->(published = nil) { published ? active.searchable(published) : active.searchable } scope :searchable, ->(searchable = nil) { searchable ? where(profile_is_searchable: searchable) : where(profile_is_searchable: true) } - scope :project_name, ->(project_name) { - return all if project_name.blank? - left_joins(user: { project_users: :project }) - .where("projects.name LIKE ?", "%#{sanitize_sql_like(project_name)}%") + scope :organization_name, ->(organization_name) { + return all if organization_name.blank? + left_joins(user: { organization_users: :organization }) + .where("organizations.name LIKE ?", "%#{sanitize_sql_like(organization_name)}%") .distinct } scope :category_names, ->(names) { tag_names(:categories, names) } scope :sector_names, ->(names) { tag_names(:sectors, names) } @@ -70,7 +70,7 @@ def self.search_by_params(params) results = results.search(params[:contact_info]) if params[:contact_info].present? results = results.sector_names(params[:sector_names]) if params[:sector_names].present? results = results.sector_names(params[:category_names]) if params[:category_names].present? - results = results.project_name(params[:project_name]) if params[:project_name].present? + results = results.organization_name(params[:organization_name]) if params[:organization_name].present? results = results.windows_type_name(params[:windows_type_name]) if params[:windows_type_name].present? results end diff --git a/app/models/project.rb b/app/models/organization.rb similarity index 67% rename from app/models/project.rb rename to app/models/organization.rb index febe5528c..50fe80d1a 100644 --- a/app/models/project.rb +++ b/app/models/organization.rb @@ -1,14 +1,14 @@ -class Project < ApplicationRecord +class Organization < ApplicationRecord include TagFilterable, Trendable, WindowsTypeFilterable - belongs_to :project_status - belongs_to :project_obligation, optional: true + belongs_to :organization_status + belongs_to :organization_obligation, optional: true belongs_to :location, optional: true # TODO - remove Location if unused belongs_to :windows_type, optional: true has_many :addresses, as: :addressable, dependent: :destroy has_many :bookmarks, as: :bookmarkable, dependent: :destroy - has_many :project_users, dependent: :restrict_with_error - has_many :users, through: :project_users + has_many :organization_users, dependent: :restrict_with_error + has_many :users, through: :organization_users has_many :reports, through: :users has_many :workshop_logs, through: :users @@ -26,12 +26,12 @@ class Project < ApplicationRecord content_type: %w[image/png image/jpeg image/webp], size: { less_than: 5.megabytes } validates :name, presence: true - validates :project_status_id, presence: true + validates :organization_status_id, presence: true # Nested attributes accepts_nested_attributes_for :addresses, allow_destroy: true, reject_if: :all_blank accepts_nested_attributes_for :sectorable_items, allow_destroy: true, reject_if: :all_blank - accepts_nested_attributes_for :project_users, allow_destroy: true, reject_if: :all_blank + accepts_nested_attributes_for :organization_users, allow_destroy: true, reject_if: :all_blank # SearchCop include SearchCop @@ -60,20 +60,21 @@ class Project < ApplicationRecord wildcard: wildcard, exact: exact) end scope :active, ->(active = nil) { active ? where(inactive: !active) : where(inactive: false) } - scope :project_ids, ->(project_ids) { where(id: project_ids.to_s.split("-").map(&:to_i)) } + scope :by_most_viewed, ->(limit = 10) { order(view_count: :desc).limit(limit) } + scope :organization_ids, ->(organization_ids) { where(id: organization_ids.to_s.split("-").map(&:to_i)) } scope :published, ->(published = nil) { published ? active(published) : active } scope :category_names, ->(names) { tag_names(:categories, names) } scope :sector_names, ->(names) { tag_names(:sectors, names) } def self.search_by_params(params) - projects = self.all - projects = projects.search(params[:query]) if params[:query].present? - projects = projects.sector_names(params[:sector_names]) if params[:sector_names].present? - projects = projects.category_names(params[:category_names]) if params[:category_names].present? - projects = projects.address(params[:address]) if params[:address].present? - projects = projects.windows_type_name(params[:windows_type_name]) if params[:windows_type_name].present? - projects = projects.project_ids(params[:project_ids]) if params[:project_ids].present? - projects + organizations = self.all + organizations = organizations.search(params[:query]) if params[:query].present? + organizations = organizations.sector_names(params[:sector_names]) if params[:sector_names].present? + organizations = organizations.category_names(params[:category_names]) if params[:category_names].present? + organizations = organizations.address(params[:address]) if params[:address].present? + organizations = organizations.windows_type_name(params[:windows_type_name]) if params[:windows_type_name].present? + organizations = organizations.organization_ids(params[:organization_ids]) if params[:organization_ids].present? + organizations end # Methods @@ -101,6 +102,6 @@ def sector_list private def leader - project_users.find_by(position: 2) + organization_users.find_by(position: 2) end end diff --git a/app/models/project_obligation.rb b/app/models/organization_obligation.rb similarity index 79% rename from app/models/project_obligation.rb rename to app/models/organization_obligation.rb index 0eed854e9..2203d1df7 100644 --- a/app/models/project_obligation.rb +++ b/app/models/organization_obligation.rb @@ -1,4 +1,4 @@ -class ProjectObligation < ApplicationRecord +class OrganizationObligation < ApplicationRecord OBLIGATION_TYPES = [ "Current Grant Funded", "Previous Grant Funded", "Voluntary Reporting", "Intermittent Reporting", "Active Non-Reporting" ] diff --git a/app/models/organization_status.rb b/app/models/organization_status.rb new file mode 100644 index 000000000..fde753171 --- /dev/null +++ b/app/models/organization_status.rb @@ -0,0 +1,7 @@ +class OrganizationStatus < ApplicationRecord + ORGANIZATION_STATUSES = [ "Active", "Inactive", "Pending", "Reinstate", "Suspended", "Unknown" ] + + has_many :organizations + + validates :name, presence: true, uniqueness: true +end diff --git a/app/models/project_user.rb b/app/models/organization_user.rb similarity index 63% rename from app/models/project_user.rb rename to app/models/organization_user.rb index 8e9716f74..e41e72dee 100644 --- a/app/models/project_user.rb +++ b/app/models/organization_user.rb @@ -1,10 +1,9 @@ -class ProjectUser < ApplicationRecord - belongs_to :project +class OrganizationUser < ApplicationRecord + belongs_to :organization belongs_to :user # Validations - validates_presence_of :project_id - validates_presence_of :title + validates_presence_of :organization_id # Enum enum :position, { default: 0, liaison: 1, leader: 2, assistant: 3 } diff --git a/app/models/project_status.rb b/app/models/project_status.rb deleted file mode 100644 index 0e1d6a949..000000000 --- a/app/models/project_status.rb +++ /dev/null @@ -1,7 +0,0 @@ -class ProjectStatus < ApplicationRecord - PROJECT_STATUSES = [ "Active", "Inactive", "Pending", "Reinstate", "Suspended", "Unknown" ] - - has_many :projects - - validates :name, presence: true, uniqueness: true -end diff --git a/app/models/report.rb b/app/models/report.rb index a569d5851..a7261d851 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,7 +1,7 @@ class Report < ApplicationRecord belongs_to :owner, polymorphic: true, optional: true belongs_to :user - belongs_to :project + belongs_to :organization belongs_to :windows_type has_one :form, as: :owner has_many :bookmarks, as: :bookmarkable, dependent: :destroy @@ -152,8 +152,8 @@ def set_has_attachment end def set_windows_type - return unless project && windows_type.nil? - update(windows_type_id: project.windows_type.id) + return unless organization && windows_type.nil? + update(windows_type_id: organization.windows_type.id) end def create_notification diff --git a/app/models/story.rb b/app/models/story.rb index 6320c1a9b..35072ba95 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -4,7 +4,7 @@ class Story < ApplicationRecord belongs_to :created_by, class_name: "User" belongs_to :updated_by, class_name: "User" belongs_to :windows_type - belongs_to :project, optional: true + belongs_to :organization, optional: true belongs_to :spotlighted_facilitator, class_name: "Facilitator", foreign_key: "spotlighted_facilitator_id", optional: true belongs_to :story_idea, optional: true @@ -73,15 +73,15 @@ def name end def organization_name - project&.name + organization&.name end def organization_locality - project&.organization_locality + organization&.organization_locality end def organization_description - project&.organization_description + organization&.organization_description end def attach_assets_from_idea! diff --git a/app/models/story_idea.rb b/app/models/story_idea.rb index 757b79390..fe37ea1d5 100644 --- a/app/models/story_idea.rb +++ b/app/models/story_idea.rb @@ -7,7 +7,7 @@ class StoryIdea < ApplicationRecord belongs_to :created_by, class_name: "User" belongs_to :updated_by, class_name: "User" - belongs_to :project + belongs_to :organization belongs_to :windows_type belongs_to :workshop, optional: true has_many :bookmarks, as: :bookmarkable, dependent: :destroy @@ -23,7 +23,7 @@ class StoryIdea < ApplicationRecord # Validations validates :created_by_id, presence: true validates :updated_by_id, presence: true - validates :project_id, presence: true + validates :organization_id, presence: true validates :windows_type_id, presence: true validates :body, presence: true validates :permission_given, presence: true @@ -57,14 +57,14 @@ def author_credit end def organization_name - project.name + organization.name end def organization_locality - project&.organization_locality + organization&.organization_locality end def organization_description - project&.organization_description + organization&.organization_description end end diff --git a/app/models/tag.rb b/app/models/tag.rb index e2d60052e..afbb6b258 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -30,10 +30,10 @@ class Tag path: -> { Rails.application.routes.url_helpers.facilitators_path }, klass: Facilitator }, - projects: { + organizations: { icon: "🏫", - path: -> { Rails.application.routes.url_helpers.projects_path }, - klass: ::Project + path: -> { Rails.application.routes.url_helpers.organizations_path }, + klass: Organization }, quotes: { icon: "💬", diff --git a/app/models/user.rb b/app/models/user.rb index 4c9fa87d9..b86f1c8df 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,7 +14,7 @@ class User < ApplicationRecord has_many :bookmarks, dependent: :destroy has_many :event_registrations, foreign_key: :registrant_id, dependent: :destroy has_many :notifications, as: :noticeable - has_many :project_users, dependent: :destroy + has_many :organization_users, dependent: :destroy has_many :reports has_many :resources has_many :user_forms, dependent: :destroy @@ -32,30 +32,30 @@ class User < ApplicationRecord has_many :bookmarked_workshops, through: :bookmarks, source: :bookmarkable, source_type: "Workshop" has_many :bookmarked_resources, through: :bookmarks, source: :bookmarkable, source_type: "Resource" has_many :bookmarked_events, through: :bookmarks, source: :bookmarkable, source_type: "Event" - has_many :colleagues, -> { select(:user_id, :position, :project_id).distinct }, - through: :projects, source: :project_users - has_many :communal_reports, through: :projects, source: :reports + has_many :colleagues, -> { select(:user_id, :position, :organization_id).distinct }, + through: :organizations, source: :organization_users + has_many :communal_reports, through: :organizations, source: :reports has_many :events, through: :event_registrations - has_many :projects, through: :project_users + has_many :organizations, through: :organization_users has_many :user_form_form_fields, through: :user_forms, dependent: :destroy - has_many :windows_types, through: :projects + has_many :windows_types, through: :organizations # Images has_one_attached :avatar # Nested attributes accepts_nested_attributes_for :user_forms - accepts_nested_attributes_for :project_users, allow_destroy: true, - reject_if: proc { |attrs| attrs["project_id"].blank? && attrs["title"].blank? } + accepts_nested_attributes_for :organization_users, allow_destroy: true, + reject_if: proc { |attrs| attrs["organization_id"].blank? || attrs["title"].blank? } # Validations validates :email, presence: true, uniqueness: { case_sensitive: false } - validates_associated :project_users + validates_associated :organization_users # Search Cop include SearchCop search_scope :search do attributes [ :email, :first_name, :last_name, :phone ] - attributes user: "projects.name" + attributes user: "organizations.name" end scope :active, -> { where(inactive: false) } @@ -72,8 +72,8 @@ def admin? super_user end - def has_liasion_position_for?(project_id) - !project_users.where(project_id: project_id, position: 1).first.nil? + def has_liasion_position_for?(organization_id) + !organization_users.where(organization_id: organization_id, position: 1).first.nil? end def active_for_authentication? @@ -100,8 +100,8 @@ def devise_email_name facilitator&.first_name.presence || first_name.presence || email end - def submitted_monthly_report(submitted_date = Date.today, windows_type, project_id) - Report.where(project_id: project_id, type: "MonthlyReport", date: submitted_date, + def submitted_monthly_report(submitted_date = Date.today, windows_type, organization_id) + Report.where(organization_id: organization_id, type: "MonthlyReport", date: submitted_date, windows_type: windows_type).last end @@ -123,11 +123,11 @@ def recent_activity(activity_limit = 10) recent.sort_by { |item| item.try(:updated_at) || item.created_at }.reverse.first(activity_limit * 8) end - def project_monthly_workshop_logs(date, *windows_type) + def organization_monthly_workshop_logs(date, *windows_type) where = windows_type.map { |wt| "windows_type_id = ?" } - logs = projects.map do |project| - project.workshop_logs.where(where.join(" OR "), *windows_type) + logs = organizations.map do |organization| + organization.workshop_logs.where(where.join(" OR "), *windows_type) end.flatten logs = logs.select do |log| log.date && log.date.month == date.month.to_i && @@ -136,9 +136,9 @@ def project_monthly_workshop_logs(date, *windows_type) logs.uniq.group_by { |log| log.date } end - def project_workshop_logs(date, windows_type, project_id) - if project_id - logs = workshop_logs.where(project_id: project_id, windows_type_id: windows_type.id) + def organization_workshop_logs(date, windows_type, organization_id) + if organization_id + logs = workshop_logs.where(organization_id: organization_id, windows_type_id: windows_type.id) logs = logs.select do |log| log.date && log.date.month == date.month.to_i && log.date.year == date.year.to_i diff --git a/app/models/workshop_log.rb b/app/models/workshop_log.rb index 9bab0523a..cb7b80d66 100644 --- a/app/models/workshop_log.rb +++ b/app/models/workshop_log.rb @@ -14,7 +14,7 @@ class WorkshopLog < Report # Scopes scope :workshop_id, ->(workshop_id) { where(workshop_id: workshop_id) if workshop_id.present? } - scope :project_id, ->(project_id) { where(project_id: project_id) if project_id.present? } + scope :organization_id, ->(organization_id) { where(organization_id: organization_id) if organization_id.present? } scope :user_id, ->(user_id) { where(user_id: user_id.to_i) if user_id.present? } scope :month_and_year, ->(month_and_year) { if month_and_year.present? @@ -34,7 +34,7 @@ def self.search(params) logs = logs.month_and_year(params[:month_and_year]) if params[:month_and_year].present? logs = logs.year(params[:year]) if params[:year].present? logs = logs.workshop_id(params[:workshop_id]) if params[:workshop_id].present? - logs = logs.project_id(params[:project_id]) if params[:project_id].present? + logs = logs.organization_id(params[:organization_id]) if params[:organization_id].present? logs.ordered_by_date end diff --git a/app/services/facilitator_from_user_service.rb b/app/services/facilitator_from_user_service.rb index 1e6976817..e1c57a69c 100644 --- a/app/services/facilitator_from_user_service.rb +++ b/app/services/facilitator_from_user_service.rb @@ -12,7 +12,7 @@ def call hydrate_facilitator hydrate_addresses hydrate_contact_methods - hydrate_projects + hydrate_organizations facilitator end @@ -30,7 +30,7 @@ def hydrate_facilitator ) end - def hydrate_projects + def hydrate_organizations # t.integer "agency_id" end diff --git a/app/services/tagging_search_service.rb b/app/services/tagging_search_service.rb index 0c3eabfe7..1f4a35bde 100644 --- a/app/services/tagging_search_service.rb +++ b/app/services/tagging_search_service.rb @@ -61,13 +61,13 @@ def self.call(sector_names:, category_names: nil, .paginate(page: pages[:facilitators] || 1, per_page: number_of_items_per_page) .decorate, - projects: Project + organizations: Organization .includes(:sectors) .published .sector_names(sector_names) .category_names(category_names) .order(:name) - .paginate(page: pages[:projects] || 1, per_page: number_of_items_per_page) + .paginate(page: pages[:organizations] || 1, per_page: number_of_items_per_page) .decorate, quotes: Quote diff --git a/app/views/admin/analytics/index.html.erb b/app/views/admin/analytics/index.html.erb index 67a2638a1..101354e1d 100644 --- a/app/views/admin/analytics/index.html.erb +++ b/app/views/admin/analytics/index.html.erb @@ -162,11 +162,11 @@ <%= render "admin/analytics/popular_list", - title: "Projects", - records: @most_viewed_projects, - path_method: :project_path, + title: "Organizations", + records: @most_viewed_organizations, + path_method: :organization_path, metric: :view_count, - color: :projects + color: :organizations %> diff --git a/app/views/community_news/_community_news_results.html.erb b/app/views/community_news/_community_news_results.html.erb index b5f8d60df..efc60fbef 100644 --- a/app/views/community_news/_community_news_results.html.erb +++ b/app/views/community_news/_community_news_results.html.erb @@ -6,7 +6,7 @@
By: <%= @community_news.created_by.full_name %>
-Organization Name: <%= @community_news.project&.name %>
+Organization Name: <%= @community_news.organization&.name %>
Facilitator: <%= @monthly_report.user&.name || "—" %>
-Organization: <%= @monthly_report.project&.name || "—" %>
+Organization: <%= @monthly_report.organization&.name || "—" %>
Report date: <%= @monthly_report.date&.strftime("%B %d, %Y") || "—" %>
diff --git a/app/views/project_statuses/_form.html.erb b/app/views/organization_statuses/_form.html.erb similarity index 60% rename from app/views/project_statuses/_form.html.erb rename to app/views/organization_statuses/_form.html.erb index a69ea4067..22afb4ff3 100644 --- a/app/views/project_statuses/_form.html.erb +++ b/app/views/organization_statuses/_form.html.erb @@ -1,12 +1,12 @@ -<%= simple_form_for(@project_status) do |f| %> +<%= simple_form_for(@organization_status) do |f| %>- No <%= ProjectStatus.model_name.human.pluralize.downcase %> found. + No <%= OrganizationStatus.model_name.human.pluralize.downcase %> found.
<% end %>Name:
-<%= @project_status.name %>
+<%= @organization_status.name %>
- No projects are currently associated with this status. + No organizations are currently associated with this status.
<% end %>| - <%= link_to project_path(project) do %> - <% if project.logo.attached? %> + <%= link_to organization_path(organization) do %> + <% if organization.logo.attached? %> <%= image_tag( - project.logo, + organization.logo, class: "w-10 h-10 rounded-full object-cover border border-gray-300 shadow-sm mx-auto" ) %> <% else %> - <%= link_to project_path(project) do %> + <%= link_to organization_path(organization) do %> |