diff --git a/Gemfile b/Gemfile index 92333274c73..8e415c3b503 100644 --- a/Gemfile +++ b/Gemfile @@ -132,7 +132,7 @@ gem "aws-sdk-s3" # Used to resize user images gem "image_processing" -# Used to provide clean urls like /microcosm/mappingdc +# Used to provide clean urls like /community/mappingdc gem "friendly_id" # Gems useful for development diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 5ec56cae19a..6f4d061fa7b 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -18,7 +18,7 @@ def initialize(user) can :index, ChangesetComment can [:confirm, :confirm_resend, :confirm_email], :confirmation can [:index, :rss, :show, :comments], DiaryEntry - can [:index], MicrocosmLink + can [:index], CommunityLink can [:index], Note can [:lost_password, :reset_password], :password can [:index, :show], Redaction @@ -32,7 +32,7 @@ def initialize(user) can [:history, :version], OldNode can [:history, :version], OldWay can [:history, :version], OldRelation - can [:index, :show], Microcosm + can [:index, :show], Community end if user&.active? @@ -56,9 +56,9 @@ def initialize(user) can [:new, :create], Report can [:mine, :new, :create, :edit, :update, :destroy], Trace can [:account, :go_public], User - can [:create, :new], Microcosm - can [:edit, :update], Microcosm, { :organizer_id => user.id } - can [:edit, :create, :destroy, :new, :update], MicrocosmLink, { :microcosm => { :organizer_id => user.id } } + can [:create, :new], Community + can [:edit, :update], Community, :organizer_id => user.id + can [:edit, :create, :destroy, :new, :update], CommunityLink, :community => { :organizer_id => user.id } if user.moderator? can [:hide, :hidecomment], DiaryEntry diff --git a/app/assets/javascripts/communities.js b/app/assets/javascripts/communities.js new file mode 100644 index 00000000000..42ef8954b26 --- /dev/null +++ b/app/assets/javascripts/communities.js @@ -0,0 +1,10 @@ +/*global showMap,formMapInput*/ + + +$(document).ready(function () { + if ($("#community_map_form").length) { + formMapInput("community_map_form", "community"); + } else if ($("#community_map").length) { + showMap("community_map"); + } +}); diff --git a/app/assets/javascripts/microcosms.js b/app/assets/javascripts/microcosms.js deleted file mode 100644 index ccd587a62f1..00000000000 --- a/app/assets/javascripts/microcosms.js +++ /dev/null @@ -1,10 +0,0 @@ -/*global showMap,formMapInput*/ - - -$(document).ready(function () { - if ($("#microcosm_map_form").length) { - formMapInput("microcosm_map_form", "microcosm"); - } else if ($("#microcosm_map").length) { - showMap("microcosm_map"); - } -}); diff --git a/app/assets/stylesheets/microcosms.scss b/app/assets/stylesheets/communities.scss similarity index 63% rename from app/assets/stylesheets/microcosms.scss rename to app/assets/stylesheets/communities.scss index 00da4e4fcd6..367b97dbdb7 100644 --- a/app/assets/stylesheets/microcosms.scss +++ b/app/assets/stylesheets/communities.scss @@ -1,8 +1,8 @@ -// Place all the styles related to the Microcosms controller here. +// Place all the styles related to the Communities controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: https://sass-lang.com/ -.mic_details { +.community_details { label { font-weight: bold; } diff --git a/app/controllers/microcosms_controller.rb b/app/controllers/communities_controller.rb similarity index 68% rename from app/controllers/microcosms_controller.rb rename to app/controllers/communities_controller.rb index 241bb6cc444..cc0c3b4ebd4 100644 --- a/app/controllers/microcosms_controller.rb +++ b/app/controllers/communities_controller.rb @@ -1,8 +1,8 @@ -class MicrocosmsController < ApplicationController +class CommunitiesController < ApplicationController layout "site" before_action :authorize_web - before_action :set_microcosm, :only => [:edit, :show, :update] + before_action :set_community, :only => [:edit, :show, :update] helper_method :recent_changesets @@ -15,44 +15,44 @@ def index @user = User.active.where(:display_name => display_name).first if @user @title = t ".title", :display_name => @user.display_name - @microcosms_organized = @user.microcosms_organized + @communities_organized = @user.communities_organized else render_unknown_user display_name return end elsif current_user @title = t ".title", :display_name => current_user.display_name - @microcosms_organized = current_user.microcosms_organized + @communities_organized = current_user.communities_organized end # Using Arel.sql here because we're using known-safe values. - @all_microcosms = Microcosm.order(Arel.sql(sunniest_communities)) + @all_communities = Community.order(Arel.sql(sunniest_communities)) end - # GET /microcosms/mycity - # GET /microcosms/mycity.json + # GET /communities/mycity + # GET /communities/mycity.json def show; end def new @title = t ".title" - @microcosm = Microcosm.new + @community = Community.new end def edit; end def create - @microcosm = Microcosm.new(microcosm_params) - @microcosm.organizer = current_user - if @microcosm.save - redirect_to @microcosm, :notice => t(".success") + @community = Community.new(community_params) + @community.organizer = current_user + if @community.save + redirect_to @community, :notice => t(".success") else render "new" end end def update - if @microcosm.update(microcosm_params) - redirect_to @microcosm, :notice => t(".success") + if @community.update(community_params) + redirect_to @community, :notice => t(".success") else flash.now[:alert] = t(".failure") render :edit @@ -62,7 +62,7 @@ def update private def recent_changesets - bbox = @microcosm.bbox.to_scaled + bbox = @community.bbox.to_scaled Changeset .where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?", bbox.max_lon.to_i, bbox.min_lon.to_i, bbox.max_lat.to_i, bbox.min_lat.to_i) @@ -70,7 +70,7 @@ def recent_changesets end ## - # Build an ORDER BY clause that sorts microcosms such that the ones + # Build an ORDER BY clause that sorts communities such that the ones # getting the most sunlight are ranked highest. These are the groups # where people are awake and mapping. # @@ -81,19 +81,19 @@ def sunniest_communities minute_of_day = "(60 * EXTRACT(HOUR FROM current_timestamp) + EXTRACT(MINUTE FROM current_timestamp))::numeric" # longitude facing the sun lfts = "((#{brightest_minute_of_day} - #{minute_of_day}) / 4)" - # find shortest span between lfts and the microcosm longitude + # find shortest span between lfts and the community longitude # pg doesn't have mod for floats, so convert to numeric clockwise_delta = "((#{lfts} - longitude::numeric + 360) % 360)" anticlockwise_delta = "((longitude::numeric - #{lfts} + 360) % 360)" "least(#{clockwise_delta}, #{anticlockwise_delta})" end - def set_microcosm - @microcosm = Microcosm.friendly.find(params[:id]) + def set_community + @community = Community.friendly.find(params[:id]) end - def microcosm_params - params.require(:microcosm).permit( + def community_params + params.require(:community).permit( :name, :location, :latitude, :longitude, :min_lat, :max_lat, :min_lon, :max_lon, :description diff --git a/app/controllers/community_links_controller.rb b/app/controllers/community_links_controller.rb new file mode 100644 index 00000000000..87874ec55ab --- /dev/null +++ b/app/controllers/community_links_controller.rb @@ -0,0 +1,61 @@ +class CommunityLinksController < ApplicationController + layout "site" + before_action :authorize_web + + before_action :set_link, :only => [:destroy, :edit, :update] + + load_and_authorize_resource :except => [:create, :new] + authorize_resource + + def index + @community = Community.friendly.find(params[:community_id]) + @links = @community.community_links + end + + def new + return "missing parameter community_id" unless params.key?(:community_id) + + @community = Community.friendly.find(params[:community_id]) + @title = t ".title" + @link = CommunityLink.new + @link.community_id = params[:community_id] + end + + def edit; end + + def create + @community = Community.friendly.find(params[:community_id]) + @link = @community.community_links.build(link_params) + if @link.save + response.set_header("link_id", @link.id) # for testing + redirect_to @link.community, :notice => t(".success") + else + render "new" + end + end + + def update + if @link.update(link_params) + redirect_to @link.community, :notice => t(".success") + else + flash.now[:alert] = t(".failure") + render :edit + end + end + + def destroy + community_id = @link.community_id + @link.delete + redirect_to community_path(community_id) + end + + private + + def set_link + @link = CommunityLink.find(params[:id]) + end + + def link_params + params.require(:community_link).permit(:community_id, :site, :url) + end +end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 6a95926377b..ab229aa176f 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -14,7 +14,7 @@ def index @title = t ".title" @issue_types = [] - @issue_types.push("Microcosm", "Note") if current_user.moderator? + @issue_types.push("Community", "Note") if current_user.moderator? @issue_types.push("DiaryEntry", "DiaryComment", "User") if current_user.administrator? @users = User.joins(:roles).where(:user_roles => { :role => current_user.roles.map(&:role) }).distinct diff --git a/app/controllers/microcosm_links_controller.rb b/app/controllers/microcosm_links_controller.rb deleted file mode 100644 index 97c0796935b..00000000000 --- a/app/controllers/microcosm_links_controller.rb +++ /dev/null @@ -1,61 +0,0 @@ -class MicrocosmLinksController < ApplicationController - layout "site" - before_action :authorize_web - - before_action :set_link, :only => [:destroy, :edit, :update] - - load_and_authorize_resource :except => [:create, :new] - authorize_resource - - def index - @microcosm = Microcosm.friendly.find(params[:microcosm_id]) - @links = @microcosm.microcosm_links - end - - def new - return "missing parameter microcosm_id" unless params.key?(:microcosm_id) - - @microcosm = Microcosm.friendly.find(params[:microcosm_id]) - @title = t ".title" - @link = MicrocosmLink.new - @link.microcosm_id = params[:microcosm_id] - end - - def edit; end - - def create - @microcosm = Microcosm.friendly.find(params[:microcosm_id]) - @link = @microcosm.microcosm_links.build(link_params) - if @link.save - response.set_header("link_id", @link.id) # for testing - redirect_to @link.microcosm, :notice => t(".success") - else - render "new" - end - end - - def update - if @link.update(link_params) - redirect_to @link.microcosm, :notice => t(".success") - else - flash.now[:alert] = t(".failure") - render :edit - end - end - - def destroy - microcosm_id = @link.microcosm_id - @link.delete - redirect_to microcosm_path(microcosm_id) - end - - private - - def set_link - @link = MicrocosmLink.find(params[:id]) - end - - def link_params - params.require(:microcosm_link).permit(:microcosm_id, :site, :url) - end -end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 28021548266..0c96515ac5a 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -56,7 +56,7 @@ def issue_params def default_assigned_role case issue_params[:reportable_type] - when "Microcosm", "Note" + when "Community", "Note" "moderator" when "User" case report_params[:category] diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index d8c2092f962..29236dfeae1 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -7,8 +7,8 @@ def reportable_url(reportable) user_url(reportable) when DiaryComment diary_entry_url(reportable.diary_entry.user, reportable.diary_entry, :anchor => "comment#{reportable.id}") - when Microcosm - microcosm_url(reportable) + when Community + community_url(reportable) when Note note_url(reportable) end @@ -22,7 +22,7 @@ def reportable_title(reportable) reportable.display_name when DiaryComment I18n.t("issues.helper.reportable_title.diary_comment", :entry_title => reportable.diary_entry.title, :comment_id => reportable.id) - when Microcosm + when Community reportable.name when Note I18n.t("issues.helper.reportable_title.note", :note_id => reportable.id) diff --git a/app/models/microcosm.rb b/app/models/community.rb similarity index 90% rename from app/models/microcosm.rb rename to app/models/community.rb index 262fea548ee..a76864c51b4 100644 --- a/app/models/microcosm.rb +++ b/app/models/community.rb @@ -1,6 +1,6 @@ # == Schema Information # -# Table name: microcosms +# Table name: communities # # id :bigint(8) not null, primary key # name :string not null @@ -17,15 +17,15 @@ # created_at :datetime not null # updated_at :datetime not null # -# At this time a microcosm has one organizer. The first organizer is -# the user that created the microcosm. +# At this time a community has one organizer. The first organizer is +# the user that created the community. -class Microcosm < ApplicationRecord +class Community < ApplicationRecord extend FriendlyId friendly_id :name, :use => :slugged belongs_to :organizer, :class_name => "User" - has_many :microcosm_links + has_many :community_links validates :name, :presence => true, :length => 1..255, :characters => true validates :description, :presence => true, :length => 1..1023, :characters => true diff --git a/app/models/microcosm_link.rb b/app/models/community_link.rb similarity index 69% rename from app/models/microcosm_link.rb rename to app/models/community_link.rb index 5d0c9a1a106..95e7f1bba9b 100644 --- a/app/models/microcosm_link.rb +++ b/app/models/community_link.rb @@ -1,9 +1,9 @@ # == Schema Information # -# Table name: microcosm_links +# Table name: community_links # # id :bigint(8) not null, primary key -# microcosm_id :integer not null +# community_id :integer not null # site :string not null # url :string not null # created_at :datetime not null @@ -11,11 +11,11 @@ # # Indexes # -# index_microcosm_links_on_microcosm_id (microcosm_id) +# index_community_links_on_community_id (community_id) # -class MicrocosmLink < ApplicationRecord - belongs_to :microcosm +class CommunityLink < ApplicationRecord + belongs_to :community validates :site, :presence => true, :length => 1..255, :characters => true validates :url, :presence => true, :length => 1..255, :url => { :schemes => ["https"] } end diff --git a/app/models/issue.rb b/app/models/issue.rb index ee8daf67243..86732984979 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -86,7 +86,7 @@ def set_reported_user self.reported_user = case reportable.class.name when "User" reportable - when "Microcosm" + when "Community" reportable.organizer when "Note" reportable.author diff --git a/app/models/report.rb b/app/models/report.rb index 7d95a9a3977..d9babd0500c 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -31,7 +31,7 @@ class Report < ApplicationRecord def self.categories_for(reportable) case reportable.class.name when "DiaryEntry", "DiaryComment" then %w[spam offensive threat other] - when "Microcosm" then %w[spam offensive other] + when "Community" then %w[spam offensive other] when "User" then %w[spam offensive threat vandal other] when "Note" then %w[spam personal abusive other] else %w[other] diff --git a/app/models/user.rb b/app/models/user.rb index a4b3ea6f5ac..1bf54ef77dc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -83,7 +83,7 @@ class User < ApplicationRecord has_many :reports - has_many :microcosms_organized, :class_name => "Microcosm", :foreign_key => :organizer_id, :inverse_of => :organizer + has_many :communities_organized, :class_name => "Community", :foreign_key => :organizer_id, :inverse_of => :organizer scope :visible, -> { where(:status => %w[pending active confirmed]) } scope :active, -> { where(:status => %w[active confirmed]) } diff --git a/app/views/microcosms/_form.html.erb b/app/views/communities/_form.html.erb similarity index 51% rename from app/views/microcosms/_form.html.erb rename to app/views/communities/_form.html.erb index 5af06ce77ff..e21cf5335ca 100644 --- a/app/views/microcosms/_form.html.erb +++ b/app/views/communities/_form.html.erb @@ -1,33 +1,30 @@ -<%= stylesheet_link_tag "microcosms" %> -<%= javascript_include_tag "microcosms" %> +<%= stylesheet_link_tag "communities" %> +<%= javascript_include_tag "communities" %> -
- All fields are required. -
-<%= bootstrap_form_for @microcosm do |form| %> - <%= form.text_field :name, :id => :microcosm_name %> - <%= form.text_field :location, :id => :microcosm_location %> +<%= bootstrap_form_for @community do |form| %> + <%= form.text_field :name, :id => :community_name %> + <%= form.text_field :location, :id => :community_location %>
- <%= link_to microcosm.name, microcosm %>+<%= link_to community.name, community %>
- <%= microcosm.location %>
+ <%= community.location %>
- (<%= number_with_precision(microcosm.latitude) %>°, <%= number_with_precision(microcosm.longitude) %>°)
+ (<%= number_with_precision(community.latitude) %>°, <%= number_with_precision(community.longitude) %>°)
- <%= microcosm.description %> + <%= community.description %> |
- <%= link_to t(".edit"), edit_microcosm_link_path(link) %> - <%= link_to t(".delete"), microcosm_link_path(link), :method => :delete %> + <%= link_to t(".edit"), edit_community_link_path(link) %> + <%= link_to t(".delete"), community_link_path(link), :method => :delete %> | <% end %> diff --git a/app/views/microcosm_links/new.html.erb b/app/views/community_links/new.html.erb similarity index 100% rename from app/views/microcosm_links/new.html.erb rename to app/views/community_links/new.html.erb diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index de2a46ed92f..8b741b28c1d 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -44,8 +44,8 @@ <% end -%> <% end %> -