Skip to content

Commit

Permalink
Rename Microcosms to Communities.
Browse files Browse the repository at this point in the history
  • Loading branch information
openbrian committed Apr 14, 2023
1 parent 5829b28 commit 7c500e0
Show file tree
Hide file tree
Showing 49 changed files with 902 additions and 904 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/communities.js
Original file line number Diff line number Diff line change
@@ -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");
}
});
10 changes: 0 additions & 10 deletions app/assets/javascripts/microcosms.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -62,15 +62,15 @@ 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)
.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags, :comments)
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.
#
Expand All @@ -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
Expand Down
61 changes: 61 additions & 0 deletions app/controllers/community_links_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 0 additions & 61 deletions app/controllers/microcosm_links_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/issues_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions app/models/microcosm.rb → app/models/community.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: microcosms
# Table name: communities
#
# id :bigint(8) not null, primary key
# name :string not null
Expand All @@ -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
Expand Down
Loading

0 comments on commit 7c500e0

Please sign in to comment.