Skip to content

Commit

Permalink
newgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
bborn committed Oct 6, 2009
1 parent 6ba70f0 commit 8acb0bb
Show file tree
Hide file tree
Showing 31 changed files with 400 additions and 654 deletions.
53 changes: 10 additions & 43 deletions README
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
CommunityEngine Groups
======================
Groups
======

This is a CommunityEngine plugin. It's designed to work with the CommunityEngine social networking platform, and won't work unless CE is properly installed.

NOTE: This plugin is in super-alpha-please-be-careful-with-me form. It's very rough, but hopefully will help give people an idea of how to develop CE plugins, and also evolve into a more mature groups functionality for CE.

YOUR HELP IS NEEDED TO IMPROVE THIS PLUGIN! Please fork it, add tests, add documentation, add code, and send me pull requests. Thanks,
Bruno

Installation
============

1. Install the plugin into your vendor directory:

script/plugin install git://github.com/bborn/community_engine_groups.git

2. Create and run its migrations:

script/generate plugin_migration
rake db:migrate

3. Run tests (more tests needed please!): rake community_engine_groups:test

4. Start your server.

Go to /groups to see what's available. Administrators can create new groups.

THANKS
======

Special thanks to LeviRosol, who contributed the bulk of this initial codebase.


TO DO
=====
- test coverage (lots of it)
- general refactoring (lots of stuff left over from copying from User object)
- track activities (group created, group joined)
- make membership approval optional
- add group descriptions




Copyright (c) 2009 Bruno Bornsztein, released under the MIT license

How To Build Your CE Plugin
===========================

Start building the functionality of your plugin by adding models and controllers in the plugin's app directory. This plugin will be loaded after the rest of CE, so you can override CE models and controllers here.


Copyright (c) 2009 [name of plugin creator], released under the MIT license
36 changes: 36 additions & 0 deletions app/controllers/group_memberships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class GroupMembershipsController < BaseController
before_filter :find_group

def create
@user = current_user
@group.add_member(@user)

flash[:notice] = :user_joined_group.l

redirect_to @group
end

def destroy
group_membership = @group.group_memberships.find(params[:id])
group_membership.destroy

if @group.is_owned_by?(current_user)
flash[:notice] = :user_was_removed_by_group_owner.l
else
flash[:notice] = :user_left_group.l
end

redirect_to @group
end

def index
@group_memberships = @group.group_memberships
end


private
def find_group
@group = Group.find(params[:group_id])
end

end
22 changes: 22 additions & 0 deletions app/controllers/group_photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class GroupPhotosController < BaseController
resource_controller
belongs_to :group

def object_name
'photo'
end

def model_name
'photo'
end

def resource_name
'photo'
end

def route_name
'photo'
end


end
188 changes: 18 additions & 170 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,180 +1,28 @@
class GroupsController < BaseController
include Viewable
cache_sweeper :taggable_sweeper, :only => [:activate, :update, :destroy]

uses_tiny_mce(:options => AppConfig.default_mce_options.merge({:editor_selector => "rich_text_editor"}),
:only => [:new, :create, :update, :edit, :show])

before_filter :admin_required, :except => [:index, :show]


def index
cond, @search, @metro_areas, @states = Group.paginated_groups_conditions_with_search(params)

@groups = Group.find(:all,
:conditions => cond.to_sql,
:include => [:tags],
:page => {:current => params[:page], :size => 20}
)

setup_metro_areas_for_cloud

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @groups }
end
end

def show
@group = Group.find(params[:id])
@groupphotos = @group.groupphotos.find(:all, :limit => 5)
@comments = @group.comments.find(:all, :limit => 10, :order => 'created_at DESC')

@is_group_owner = @group.owner.eql?(current_user)

@member_count = @group.accepted_memberships.count
@accepted_memberships = @group.accepted_memberships.find(:all, :limit => 5).collect{|f| f.member }
@pending_memberships_count = @group.pending_memberships.count()

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @group }
end
end

# GET /groups/new
# GET /groups/new.xml
def new
@group = Group.new
@membership = Membership.new
@group_permission = GroupPermission.new
@metro_areas = MetroArea.find(:all)
@states = State.find(:all)

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @group }
end
end
resource_controller
before_filter :login_required, :except => [:index, :show]
uses_tiny_mce(:options => AppConfig.simple_mce_options, :only => [:new, :edit, :create, :update, :show])

# GET /groups/1/edit
def edit
@group = Group.find(params[:id])
@metro_areas, @states = setup_locations_for(@group)
@avatar = Groupphoto.new

@groupphotos = @group.groupphotos.find(:all, :limit => 5)
@is_group_owner = @group.owner.eql?(current_user)
update.before do
@object.add_avatar(object_params[:avatar_upload]) if object_params
end

# POST /groups
# POST /groups.xml
def create
@group = Group.new(params[:group])

#here we add the current user to the membership collection of the group
@membership = @group.memberships.build(params[:membership])
@membership.group = @group
@membership.user = current_user
@membership.initiator = false
@membership.membership_status_id = 2

#and here we set the current_user as the owner of the group
@group_permission = @group.group_permissions.build(params[:group_permission])
@group_permission.membership = @membership
@group_permission.group_role = GroupRole.find_by_name('Owner')
show.before do
@comments = @group.comments.find(:all, :page => {:size => 10, :current => params[:page]})
end

@group.metro_area = MetroArea.find(params[:metro_area_id])
@group.state = (@group.metro_area && @group.metro_area.state) ? @group.metro_area.state : nil
@group.country = @group.metro_area.country if (@group.metro_area && @group.metro_area.country)

respond_to do |format|
if @group.save
flash[:notice] = 'Group was successfully created.'
format.html { redirect_to(@group) }
else
format.html { render :action => "new" }
end
end

end

# PUT /groups/1
# PUT /groups/1.xml
def update
@group = Group.find(params[:id])

unless params[:metro_area_id].blank?
@group.metro_area = MetroArea.find(params[:metro_area_id])
@group.state = (@group.metro_area && @group.metro_area.state) ? @group.metro_area.state : nil
@group.country = @group.metro_area.country if (@group.metro_area && @group.metro_area.country)
else
@group.metro_area = @group.state = @group.country = nil
end

@avatar = Groupphoto.new(params[:avatar])
@avatar.group = @group

@group.avatar = @avatar if @avatar.save

respond_to do |format|
if @group.update_attributes(params[:group])
flash[:notice] = 'Group was successfully updated.'
format.html { redirect_to(@group) }
else
format.html { render :action => "edit" }
end
end
end

def destroy
Group.destroy(params[:id])

respond_to do |format|
format.html { redirect_to(groups_url) }
end
end
private

def metro_area_update
return unless request.xhr?

country = Country.find(params[:country_id]) unless params[:country_id].blank?
state = State.find(params[:state_id]) unless params[:state_id].blank?
states = country ? country.states.sort_by{|s| s.name} : []

if states.any?
metro_areas = state ? state.metro_areas.all(:order => "name") : []
else
metro_areas = country ? country.metro_areas : []
def collection
@collection ||= end_of_association_chain.find(:all, :page => {:size => 10, :current => params[:page]})
end

render :partial => 'shared/group_location_chooser', :locals => {
:states => states,
:metro_areas => metro_areas,
:selected_country => params[:country_id].to_i,
:selected_state => params[:state_id].to_i,
:selected_metro_area => nil }
end

def roster
@group = Group.find(params[:id])
end

protected
def setup_metro_areas_for_cloud
@metro_areas_for_cloud = MetroArea.find(:all, :conditions => "groups_count > 0", :order => "groups_count DESC", :limit => 100)
@metro_areas_for_cloud = @metro_areas_for_cloud.sort_by{|m| m.name}
end

def setup_locations_for(group)
metro_areas = states = []

states = group.country.states if group.country

metro_areas = group.state.metro_areas.all(:order => "name") if group.state

return metro_areas, states
def build_object
@object ||= current_user.groups.build object_params
@object.add_owner(current_user)
@object.add_avatar(object_params[:avatar_upload]) if object_params
@object
end


end

end
25 changes: 8 additions & 17 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
class Comment < ActiveRecord::Base

# def self.find_groupphoto_comments_for(group)
# Comment.find(:all, :conditions => ["recipient_id = ? AND commentable_type = ?", group.owner.id, 'Groupphoto'], :order => 'created_at DESC')
# end
#
# def self.find_group_comments_for(group)
# Comment.find(:all, :conditions => ["recipient_id = ? AND commentable_type = ?", group.owner.id, 'Group'], :order => 'created_at DESC')
# end
#
# def self.find_comments_by_group(group, *args)
# options = args.extract_options!
# find(:all,
# :conditions => ["commentable_id = ?", group.id],
# :order => "created_at DESC",
# :limit => options[:limit]
# )
# end

def can_be_deleted_by(person)
if person
return true if (person.admin? || person.id.eql?(user_id) || person.id.eql?(recipient_id) )
return true if commentable_type.eql?('Group') && commentable.is_owned_by?(person)
end
false
end

end
Loading

0 comments on commit 8acb0bb

Please sign in to comment.