Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communities events #204

Open
wants to merge 4 commits into
base: communities-membership
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ gem "rails_param"
gem "rinku", ">= 2.0.6", :require => "rails_rinku"
gem "strong_migrations", "< 2.0.0"
gem "validates_email_format_of", ">= 1.5.1"
gem "validate_url"

# Native OSM extensions
gem "quad_tile", "~> 1.0.1"
Expand Down Expand Up @@ -144,6 +145,9 @@ gem "unicode-display_width"
# Keep ruby 3.0 compatibility
gem "multi_xml", "~> 0.6.0"

# Used to provide clean urls like /community/mappingdc
gem "friendly_id"

# Gems useful for development
group :development do
gem "better_errors"
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ GEM
ffi-libarchive (1.1.14)
ffi (~> 1.0)
file_exists (0.2.0)
friendly_id (5.4.2)
activerecord (>= 4.0.0)
frozen_record (0.27.2)
activemodel
fspath (3.1.2)
Expand Down Expand Up @@ -581,6 +583,9 @@ GEM
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
uri (0.13.0)
validate_url (1.0.15)
activemodel (>= 3.0.0)
public_suffix
validates_email_format_of (1.8.2)
i18n (>= 0.8.0)
simpleidn
Expand Down Expand Up @@ -638,6 +643,7 @@ DEPENDENCIES
faraday
ffi-libarchive
file_exists
friendly_id
frozen_record
gd2-ffij (>= 0.4.0)
htmlentities
Expand Down Expand Up @@ -700,6 +706,7 @@ DEPENDENCIES
terser
turbo-rails
unicode-display_width
validate_url
validates_email_format_of (>= 1.5.1)
vendorer
webmock
Expand Down
16 changes: 16 additions & 0 deletions app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ def initialize(user)
if Settings.status != "database_offline"
can [:index, :feed, :show], Changeset
can :index, ChangesetComment
can [:index, :show], Community
can [:index], CommunityLink
can [:index], CommunityMember
can [:confirm, :confirm_resend, :confirm_email], :confirmation
can [:index, :rss, :show], DiaryEntry
can :index, DiaryComment
can [:index, :show], Event
can [:index], Note
can [:new, :create, :edit, :update], :password
can [:index, :show], Redaction
Expand Down Expand Up @@ -47,6 +51,18 @@ def initialize(user)
can [:create], DiaryComment
can [:make_friend, :remove_friend], Friendship
can [:new, :create, :reply, :show, :inbox, :outbox, :muted, :mark, :unmute, :destroy], Message
user_is_community_organizer = {
:community_members => {
:user_id => user.id,
:role => CommunityMember::Roles::ORGANIZER
}
}
can [:create, :new, :step_up], Community
can [:edit, :update], Community, user_is_community_organizer
can [:edit, :create, :destroy, :new, :update], CommunityLink, :community => user_is_community_organizer
can [:create, :destroy], CommunityMember, :user_id => user.id
can [:destroy, :edit, :update], CommunityMember, :community => user_is_community_organizer
can [:create, :edit, :new, :update], Event, :community => user_is_community_organizer
can [:close, :reopen], Note
can [:show, :edit, :update], :preference
can [:edit, :update], :profile
Expand Down
68 changes: 68 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,71 @@ $(document).ready(function () {
$("#edit_tab")
.attr("title", I18n.t("javascripts.site.edit_disabled_tooltip"));
});

window.showMap = function (id) {
var params = $("#" + id).data();
var map = L.map(id, {
attributionControl: false,
zoomControl: false
});
map.addLayer(new L.OSM.Mapnik());
var show_marker = true;
if (!params.lon || !params.lat) {
params.lon = 0;
params.lat = 0;
params.zoom = 1;
show_marker = false;
}
map.setView([params.lat, params.lon], params.zoom);
if (show_marker) {
L.marker([params.lat, params.lon], { icon: OSM.getUserIcon() }).addTo(map);
}
};

window.formMapInput = function (id, type) {
var map = L.map(id, {
attributionControl: false
});
map.addLayer(new L.OSM.Mapnik());

var lat_field = document.getElementById(type + "_latitude");
var lon_field = document.getElementById(type + "_longitude");

if (lat_field.value) {
map.setView([lat_field.value, lon_field.value], 12);
} else {
map.setView([0, 0], 2);
}

L.Control.Watermark = L.Control.extend({
onAdd: function () {
var container = map.getContainer();
var img = L.DomUtil.create("img");
img.src = "/assets/marker-blue.png"; // 25x41 px
// img.style.width = '200px';
img.style["margin-left"] = ((container.offsetWidth / 2) - 12) + "px";
img.style["margin-bottom"] = ((container.offsetHeight / 2) - 20) + "px";
return img;
},
onRemove: function () {
// Nothing to do here
}
});
L.control.watermark = function (opts) {
return new L.Control.Watermark(opts);
};
L.control.watermark({ position: "bottomleft" }).addTo(map);

map.on("move", function () {
var center = map.getCenter();
$("#" + type + "_latitude").val(center.lat);
$("#" + type + "_longitude").val(center.lng);
if ($("#" + type + "_min_lat")) {
var bounds = map.getBounds();
$("#" + type + "_min_lat").val(bounds._southWest.lat);
$("#" + type + "_max_lat").val(bounds._northEast.lat);
$("#" + type + "_min_lon").val(bounds._southWest.lng);
$("#" + type + "_max_lon").val(bounds._northEast.lng);
}
});
};
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");
}
});
9 changes: 9 additions & 0 deletions app/assets/javascripts/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*global showMap,formMapInput*/

$(document).ready(function () {
if ($("#event_map_form").length) {
formMapInput("event_map_form", "event");
} else if ($("#event_map_show").length) {
showMap("event_map_show");
}
});
31 changes: 31 additions & 0 deletions app/assets/stylesheets/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,37 @@ img.user_thumbnail_tiny {
object-fit: contain;
}

.user_card {
@extend .card;
width: 100px;
display: inline-block;
> img {
@extend .card-img-top;
}
> div {
@extend .card-body;
/*
Some display_names are long and break the uniform display of user cards.
For now, hide the overflow. This does make some user names ambiguous.
TODO: Fix this.
*/
overflow: hidden;
white-space: nowrap;
padding: 0.5rem; /* override bootstrap's 1.25rem */
> h5 {
@extend .card-title;
font-size: 0.9rem; /* override bootstrap's 1.25 rem */
}
}
}


/* Rules for geo microformats */

abbr.geo {
border-bottom: none;
}

/* General styles for action lists / subnavs */

nav.secondary-actions {
Expand Down
12 changes: 12 additions & 0 deletions app/assets/stylesheets/communities.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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/

.community_details {
h1 {
margin-top: 0;
}
label {
font-weight: bold;
}
}
125 changes: 125 additions & 0 deletions app/controllers/communities_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
class CommunitiesController < ApplicationController
include UserMethods

layout "site"
before_action :authorize_web

before_action :set_community, :only => [:edit, :show, :step_up, :update]

helper_method :recent_changesets

load_and_authorize_resource :except => [:create, :new]
authorize_resource

def index
@critical_mass = 3
display_name = params[:user_display_name]
if display_name
@user = User.active.find_by(:display_name => display_name)
if @user
@title = t ".title", :display_name => @user.display_name
@communities_leading = @user.communities_lead
else
render_unknown_user display_name
return
end
elsif current_user
@title = t ".title", :display_name => current_user.display_name
@communities_leading = current_user.communities_lead
end

# Only list out communities that have at least n members in order to mitigate spam. In order to get
# a community listed, the organizer must find n members and give them the link to the page manually.
@all_communities = Community
.joins(:community_members)
.group("communities.id")
.having("COUNT(communities.id) >= #{@critical_mass}")

@my_communities = current_user ? current_user.communities : []
end

# GET /communities/mycity
# GET /communities/mycity.json
def show
# for existing or new member
@current_user_membership = CommunityMember.find_or_initialize_by(
:community => @community, :user_id => current_user&.id
)
end

def new
@title = t ".title"
@community = Community.new
end

def edit; end

def create
@community = Community.new(community_params)
@community.leader = current_user
if @community.save && add_first_organizer
redirect_to @community, :notice => t(".success")
else
render "new"
end
end

def update
if @community.update(community_params)
redirect_to @community, :notice => t(".success")
else
flash.now[:alert] = t(".failure")
render :edit
end
end

def step_up
message = nil
if @community.organizers.empty?
if @community.member?(current_user)
message = t ".you_have_stepped_up"
add_first_organizer
else
message = t ".only_members_can_step_up"
end
else
message = t ".already_has_organizer"
end
redirect_to @community, :notice => message
end

private

def add_first_organizer
membership = CommunityMember.new(
{
:community_id => @community.id,
:user_id => current_user.id,
:role => CommunityMember::Roles::ORGANIZER
}
)
membership.save
end

def recent_changesets
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

def set_community
@community = Community.friendly.find(params[:id])
rescue ActiveRecord::RecordNotFound
render "no_such_community", :status => :not_found
end

def community_params
params.require(:community).permit(
:name, :location, :latitude, :longitude,
:min_lat, :max_lat, :min_lon, :max_lon,
:description
)
end
end
Loading