<commit_before>module SwellSocial
	class UserPostsController < ApplicationController
		
		before_filter 	:authenticate_user!
		before_filter   :get_parent_obj, only: :create

		
		def admin
			authorize!( :admin, Comment )
			@posts = UserPost.order( created_at: :desc )
			render layout: 'admin'
		end


		def create
			@post = UserPost.new( parent_obj_id: @parent_obj.id, parent_obj_type: @parent_obj.class.name, user: current_user, content: params[:content] )

			if @post.save
				if @reply_to_comment = UserPost.find_by( id: params[:reply_to_id] )
					@post.move_to_child_of( @reply_to_comment )
				end
				set_flash 'Thanks for your comment'
				
				# throw site event
				record_user_event( 'comment', user: current_user, on: @parent_obj, content: "<i class='fa fa-comment'></i> commented on the #{@post.parent_obj.class.name.downcase} <a href='#{@post.parent_obj.url( ref: current_user )}'>#{@post.parent_obj.title}</a>!" ) # if defined?( SwellPlay )

			else
				set_flash 'Comment could not be saved', :error, @post
			end

			redirect_to :back
		end

		def destroy
			authorize!( :admin, UserPost )
			@post = UserPost.find( params[:id] )
			@post.update( status: 'deleted' )
			set_flash 'Comment Deleted'
			redirect_to :back
		end

		def edit
			authorize!( :admin, UserPost )
			@post = UserPost.find( params[:id] )
			render layout: 'admin'
		end

		def update
			authorize!( :admin, UserPost )
			@post = UserPost.find( params[:id] )
			if @post.update( comment_params )
				set_flash "Comment Updated"
			else
				set_flash "Comment could not be updated", :error, @post
			end
			redirect_to :back
		end


		private

			def comment_params
				params.require( :user_post ).permit( :title, :subject, :user_id, :content, :status )
			end

			def get_parent_obj
				if params[:type].present?
					@parent_obj = params[:type].constantize.where( id: params[:id] ).first 
				else
					set_flash 'Can not comment without parent', :error
					redirect_to :back
					return false
				end
			end

	end
end<commit_msg>user post can now specify subject and status in params<commit_after>module SwellSocial
	class UserPostsController < ApplicationController
		
		before_filter 	:authenticate_user!
		before_filter   :get_parent_obj, only: :create

		
		def admin
			authorize!( :admin, Comment )
			@posts = UserPost.order( created_at: :desc )
			render layout: 'admin'
		end


		def create
			@post = UserPost.new( parent_obj_id: @parent_obj.id, parent_obj_type: @parent_obj.class.name, user: current_user, subject: params[:subject], content: params[:content], status: ( params[:draft] ? 'draft' : nil ) )

			if @post.save
				if @reply_to_comment = UserPost.find_by( id: params[:reply_to_id] )
					@post.move_to_child_of( @reply_to_comment )
				end
				set_flash 'Thanks for your comment'
				
				# throw site event
				record_user_event( 'comment', user: current_user, on: @parent_obj, content: "<i class='fa fa-comment'></i> commented on the #{@post.parent_obj.class.name.downcase} <a href='#{@post.parent_obj.url( ref: current_user )}'>#{@post.parent_obj.title}</a>!" ) # if defined?( SwellPlay )

			else
				set_flash 'Comment could not be saved', :error, @post
			end

			redirect_to :back
		end

		def destroy
			authorize!( :admin, UserPost )
			@post = UserPost.find( params[:id] )
			@post.update( status: 'deleted' )
			set_flash 'Comment Deleted'
			redirect_to :back
		end

		def edit
			authorize!( :admin, UserPost )
			@post = UserPost.find( params[:id] )
			render layout: 'admin'
		end

		def update
			authorize!( :admin, UserPost )
			@post = UserPost.find( params[:id] )
			if @post.update( comment_params )
				set_flash "Comment Updated"
			else
				set_flash "Comment could not be updated", :error, @post
			end
			redirect_to :back
		end


		private

			def comment_params
				params.require( :user_post ).permit( :title, :subject, :user_id, :content, :status )
			end

			def get_parent_obj
				if params[:type].present?
					@parent_obj = params[:type].constantize.where( id: params[:id] ).first 
				else
					set_flash 'Can not comment without parent', :error
					redirect_to :back
					return false
				end
			end

	end
end
{'fraction_non_alphanumeric': 0.11612284069097889, 'fraction_numerical': 0.0, 'mean_word_length': 3.5813186813186815, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3430333', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1381, 'n_words': 378}