Commit 2efbb1ae authored by azul's avatar azul
Browse files

track request to destroy group in controller

parent dee772cc
......@@ -110,8 +110,9 @@ module Common::Requests
end
end
def track_activity
super @req.event, @req.event_attrs
def track_activity(event = nil, options = {})
event ||= @req.event
super event, @req.event_attrs.merge(options)
end
def create_notices
......
......@@ -13,6 +13,8 @@ class Groups::RequestsController < Groups::BaseController
# permissions handled by model:
guard create: :allow, update: :allow, destroy: :allow
after_filter :track_activity, only: :create
rescue_render create: :index
def index
......@@ -38,11 +40,18 @@ class Groups::RequestsController < Groups::BaseController
protected
REQUEST_TYPES = {
destroy_group: 'RequestToDestroyOurGroup',
create_council: 'RequestToCreateCouncil'
}.with_indifferent_access
def requested_class
if params[:type] == 'destroy_group'
RequestToDestroyOurGroup
elsif params[:type] == 'create_council'
RequestToCreateCouncil
REQUEST_TYPES[params[:type]].try.constantize
end
def track_activity
if REQUEST_TYPES.has_key? params[:type]
super "request_to_#{params[:type]}"
end
end
......
......@@ -41,6 +41,7 @@ class Activity < ActiveRecord::Base
create_group: ['GroupCreatedActivity', 'UserCreatedGroupActivity'],
create_membership: ['GroupGainedUserActivity', 'UserJoinedGroupActivity'],
destroy_membership: ['GroupLostUserActivity', 'UserLeftGroupActivity'],
request_to_destroy_group: ['UserProposedToDestroyGroupActivity'],
create_friendship: ['FriendActivity']
}
......
class RequestToDestroyOurGroupObserver < ActiveRecord::Observer
def after_create(request)
key = rand(Time.now.to_i)
request.group.users.each do |user|
UserProposedToDestroyGroupActivity.create!(user: request.created_by, group: request.group, key: key)
end
end
end
......@@ -49,7 +49,6 @@ module Crabgrass
#config.active_record.whitelist_attributes = true
config.active_record.observers = :relationship_observer,
:request_to_destroy_our_group_observer,
"tracking/page_observer", "tracking/post_observer", "tracking/wiki_observer",
"tracking/user_participation_observer", "tracking/group_participation_observer"
......
......@@ -24,5 +24,8 @@ class Groups::RequestsControllerTest < ActionController::TestCase
get :create, group_id: @group.to_param, type: 'destroy_group'
end
assert_response :redirect
assert activity = UserProposedToDestroyGroupActivity.last
assert_equal @user, activity.user
assert_equal @group, activity.group
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment