Changeset 11
- Timestamp:
- 08/29/2006 08:57:16 AM (2 years ago)
- Files:
-
- trunk/auto-admin/lib/auto_admin_controller.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/auto-admin/lib/auto_admin_controller.rb
r5 r11 33 33 34 34 valid_user = false 35 if session[:user]36 if permit_user_to_access_admin( session[:user])35 if user 36 if permit_user_to_access_admin( user ) 37 37 valid_user = true 38 38 else … … 51 51 private :permit_user_to_access_admin 52 52 53 def user_history_includes 54 :user 55 end 56 def user_history_identity 57 { :user_id => (user && user.id) } 58 end 59 def user_history_items(num=10) 60 conditions = [] 61 condition_values = [] 62 user_history_identity.each {|k,v| conditions << "#{k} = ?"; condition_values << v } 63 AdminHistory.find( :all, 64 :conditions => [conditions.join(' AND '), *condition_values], 65 :order => 'created_at DESC', :limit => num ) 66 end 67 private :user_history_items 68 53 69 def index 54 70 @no_crumbs = true 55 @history_items = AdminHistory.find( :all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 10 )if has_history?71 @history_items = user_history_items if has_history? 56 72 end 57 73 def login … … 152 168 153 169 if has_history? 154 history = { :user_id => session[:user].id, :object_label => @object.to_label, :model => params[:model], :obj_id => @object.id } 170 history = { :object_label => @object.to_label, :model => params[:model], :obj_id => @object.id } 171 history.update user_history_identity 155 172 if params[:id] 156 173 history.update :change => 'edit', :description => 'Record modified' … … 178 195 def history 179 196 @object = params[:id] ? model.find( params[:id] ) : model.new 180 @histories = AdminHistory.find :all, :conditions => ['model = ? AND obj_id = ?', params[:model], params[:id]], :order => 'admin_histories.created_at DESC', :limit => 50, :include => [ :user]197 @histories = AdminHistory.find :all, :conditions => ['model = ? AND obj_id = ?', params[:model], params[:id]], :order => 'admin_histories.created_at DESC', :limit => 50, :include => [*user_history_includes] 181 198 end 182 199 … … 186 203 object = model.find( params[:id] ) 187 204 label = @object.to_label 188 hist = AdminHistory.new( :user_id => session[:user].id, :object_label => @object.to_label, :model => params[:model], :obj_id => params[:id], :change => 'delete', :description => 'Record deleted' ) if has_history? 205 if has_history? 206 history_hash = { :object_label => @object.to_label, :model => params[:model], :obj_id => params[:id], :change => 'delete', :description => 'Record deleted' } 207 history_obj = AdminHistory.new( history_hash ) 208 end 189 209 object.destroy 190 210 flash[:notice] = "The #{human_model.downcase} \"#{object.to_label}\" was deleted successfully." 191 hist .save! if hist211 history_obj.save! if history_obj 192 212 redirect_to list_page_for_current 193 213 end
