forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow multiple organizers per community. There is now just 1 leader of an community. Allow stepping up if there's no organizer. Add ability to remove memberships.
- Loading branch information
Showing
28 changed files
with
964 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
class CommunityMembersController < ApplicationController | ||
layout "site" | ||
before_action :authorize_web | ||
before_action :set_community_member, :only => [:destroy, :edit, :update] | ||
load_and_authorize_resource :except => [:create] | ||
authorize_resource | ||
|
||
def index | ||
@community = Community.friendly.find(params[:community_id]) | ||
@roles = CommunityMember::Roles::ALL_ROLES.map(&:pluralize) | ||
rescue ActiveRecord::RecordNotFound | ||
@not_found_community = params[:community_id] | ||
render :template => "communities/no_such_community", :status => :not_found | ||
end | ||
|
||
def edit; end | ||
|
||
def create | ||
# membership = CommunityMember.new(create_params) | ||
# If there's no given user, default to the current_user. | ||
membership = CommunityMember.new(create_params.reverse_merge!(:user_id => current_user.id)) | ||
membership.role = CommunityMember::Roles::MEMBER | ||
if membership.save | ||
redirect_to community_path(membership.community), :notice => t(".success") | ||
else | ||
# There are 2 reasons we may get here. | ||
# 1. database failure / disk full | ||
# 2. the community does not exist | ||
# Either way, sending the user to the communities list page is ok. | ||
redirect_to communities_path, :alert => t(".failure") | ||
end | ||
end | ||
|
||
def update | ||
if @community_member.update(update_params) | ||
redirect_to @community_member.community, :notice => t(".success") | ||
else | ||
flash.now[:alert] = t(".failure") | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
issues = @community_member.can_be_deleted | ||
if issues.empty? && @community_member.destroy | ||
redirect_to @community_member.community, :notice => t(".success") | ||
else | ||
issues = issues.map { |i| t("activerecord.errors.models.community_member.#{i}") } | ||
issues = issues.to_sentence.capitalize | ||
flash[:error] = "#{t('.failure')} #{issues}." | ||
redirect_to community_community_members_path(@community_member.community) | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_community_member | ||
@community_member = CommunityMember.find(params[:id]) | ||
end | ||
|
||
def create_params | ||
params.require(:community_member).permit(:community_id, :user_id) | ||
end | ||
|
||
def update_params | ||
params.require(:community_member).permit(:role) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# == Schema Information | ||
# | ||
# Table name: community_members | ||
# | ||
# id :bigint(8) not null, primary key | ||
# community_id :integer not null | ||
# user_id :integer not null | ||
# role :string(64) not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_community_members_on_community_id (community_id) | ||
# index_community_members_on_community_id_and_user_id_and_role (community_id,user_id,role) UNIQUE | ||
# index_community_members_on_user_id (user_id) | ||
# | ||
|
||
class CommunityMember < ApplicationRecord | ||
module Roles | ||
ORGANIZER = "organizer".freeze | ||
MEMBER = "member".freeze | ||
ALL_ROLES = [ORGANIZER, MEMBER].freeze | ||
end | ||
|
||
belongs_to :community | ||
belongs_to :user | ||
|
||
scope :organizers, -> { where(:role => Roles::ORGANIZER) } | ||
scope :members, -> { where(:role => Roles::MEMBER) } | ||
|
||
validates :community, :associated => true | ||
validates :user, :associated => true | ||
validates :role, :inclusion => { :in => Roles::ALL_ROLES } | ||
|
||
# TODO: validate uniqueness of user's role in each community. | ||
|
||
# We assume this user already belongs to this community. | ||
def can_be_deleted | ||
issues = [] | ||
# The user may also be an organizer under a separate membership. | ||
issues.append(:is_organizer) if CommunityMember.exists?(:community_id => community_id, :user_id => user_id, :role => Roles::ORGANIZER) | ||
|
||
issues | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% content_for :heading do %> | ||
<h1> | ||
<%= t ".heading", :community => @not_found_community %> | ||
</h1> | ||
<% end %> | ||
<p> | ||
<%= t ".body", :community => @not_found_community %> | ||
</p> |
Oops, something went wrong.