This patchset creates a logs/ page that displays event history. It should work even without soft deletion implemented; although once soft deletiion is implemented, the changes will automatically be reflected.
This revision of the patchset implements many suggestions from matty_dubs and jprovazn, including:
- increasing the readability of the filter code in load_logs - updating the haml to match current standards - permission checks - dealing with legacy data - many minor stylistic fixes
I didn't include tests, as the bulk of the interesting tests deal with soft deletion, which is not included in this patchset. That other patchset (RM 3144) will include tests.
Mainn
--- src/config/routes.rb | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/config/routes.rb b/src/config/routes.rb index a95389f..265f752 100644 --- a/src/config/routes.rb +++ b/src/config/routes.rb @@ -156,6 +156,10 @@ Conductor::Application.routes.draw do post :filter, :on => :collection end
+ resources :logs do + post :filter, :on => :collection + end + resources :config_servers do member do get 'test'
--- src/app/controllers/logs_controller.rb | 114 ++++++++++++++++++++++++++++++++ 1 files changed, 114 insertions(+), 0 deletions(-) create mode 100644 src/app/controllers/logs_controller.rb
diff --git a/src/app/controllers/logs_controller.rb b/src/app/controllers/logs_controller.rb new file mode 100644 index 0000000..8f417a3 --- /dev/null +++ b/src/app/controllers/logs_controller.rb @@ -0,0 +1,114 @@ +# +# Copyright 2012 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class LogsController < ApplicationController + before_filter :require_user + + def index + clear_breadcrumbs + save_breadcrumb(logs_path) + + load_headers + load_options + load_logs + respond_to do |format| + format.html + end + end + + def filter + redirect_to_original({"source_type" => params[:source_type], "pool_select" => params[:pool_select], "provider_select" => params[:provider_select], "owner_id" => params[:owner_id]}) + end + + protected + + def load_logs + @source_type = params[:source_type].nil? ? "" : params[:source_type] + @pool_select = params[:pool_select].nil? ? "" : params[:pool_select] + @provider_select = params[:provider_select].nil? ? "" : params[:provider_select] + @owner_id = params[:owner_id].nil? ? "" : params[:owner_id] + + conditions = [] + if @source_type.present? + conditions += ["source_type = ?", @source_type] + end + + @events = Event.unscoped.find(:all, + :include => {:source => [:pool_family, :pool, :owner]}, + :conditions => conditions + ) + deployments = Deployment.unscoped.list_for_user(current_user, Privilege::VIEW) + instances = Instance.unscoped.list_for_user(current_user, Privilege::VIEW) + + @events = @events.find_all{|event| + source_class = event.source.class.name + + # permission checks + next if source_class == "Deployment" and !deployments.include?(event.source) + next if source_class == "Instance" and !instances.include?(event.source) + + # filter by user + next if @owner_id.present? && event.source.owner_id.to_s != @owner_id + + # filter by pool + if @pool_select.present? + pool_option, pool_option_id = @pool_select.split(":") + next if pool_option == "pool_family" && event.source.pool_family_id.to_s != pool_option_id + next if pool_option == "pool" && event.source.pool_id.to_s != pool_option_id + end + + # filter by provider + if @provider_select.present? + event_provider_account = event.source.provider_account + next if event_provider_account.nil? + + provider_option, provider_option_id = @provider_select.split(":") + next if provider_option == "provider" && event.source.provider_account.provider.id.to_s != provider_option_id + next if provider_option == "provider_account" && event.source.provider_account.id.to_s != provider_option_id + end + + true + } + + @events = paginate_collection(@events, params[:page], PER_PAGE) + end + + def load_options + @source_type_options = [[t('logs.options.default_event_types'), ""], t('logs.options.deployment_event_type'), t('logs.options.instance_event_type')] + @pool_options = [[t('logs.options.default_pools'), ""]] + PoolFamily.find(:all, :include => :pools, :order => "name", :select => ["id", "name"]).each do |pool_family| + @pool_options << [pool_family.name, "pool_family:" + pool_family.id.to_s] + @pool_options += pool_family.pools.map{|x| [" -- " + x.name, "pool:" + x.id.to_s]} + end + @provider_options = [[t('logs.options.default_providers'), ""]] + Provider.find(:all, :include => :provider_accounts, :order => "name", :select => ["id", "name"]).each do |provider| + @provider_options << [provider.name, "provider:" + provider.id.to_s] + @provider_options += provider.provider_accounts.map{|x| [" -- " + x.name, "provider_account:" + x.id.to_s]} + end + @owner_options = [[t('logs.options.default_users'), ""]] + User.find(:all, :order => "login", :select => ["id", "login"]).map{|x| [x.login, x.id]} + end + + def load_headers + @header = [ + { :name => t('logs.index.event_time'), :sortable => false }, + { :name => t('logs.index.deployment'), :sortable => false }, + { :name => t('logs.index.pool'), :sortable => false }, + { :name => t('logs.index.provider'), :sortable => false }, + { :name => t('logs.index.owner'), :sortable => false }, + { :name => t('logs.index.summary'), :sortable => false }, + ] + end +end
--- src/app/views/logs/index.html.haml | 40 ++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-) create mode 100644 src/app/views/logs/index.html.haml
diff --git a/src/app/views/logs/index.html.haml b/src/app/views/logs/index.html.haml new file mode 100644 index 0000000..de354dc --- /dev/null +++ b/src/app/views/logs/index.html.haml @@ -0,0 +1,40 @@ += render :partial => 'layouts/admin_nav' + +%section.content-section + %header + %h2#users.users= @title + + .content + - content_for :filter_controls do + %li + = label_tag "source_type", t('filter_table.viewing') + = hidden_field_tag :current_path, request.fullpath + = select_tag "source_type", options_for_select(@source_type_options, @source_type) + = select_tag "pool_select", options_for_select(@pool_options, @pool_select) + = select_tag "provider_select", options_for_select(@provider_options, @provider_select) + = select_tag "owner_id", options_for_select(@owner_options, @owner_id) + = restful_submit_tag t("filter_table.apply_filters"), "index", filter_logs_path, 'POST', :class => 'button', :id => 'apply_logs_filter' + %span.label.badge.dark= @events.count + + = filter_table(@header, @events) do |event| + - source = event.source + - provider_account = source.nil? ? nil : source.provider_account + %tr{:class => cycle('nostripe','stripe')} + %td= event.event_time.strftime("%d-%b-%Y %H:%M:%S") + - if source.nil? + %td= t('logs.index.not_available') + - else + %td= link_to source.name, source + - if source.nil? + %td= t('logs.index.not_available') + - else + %td= source.pool_family.name + "/" + source.pool.name + - if provider_account.nil? + %td= t('logs.index.not_available') + - else + %td= provider_account.provider.name + "/" + provider_account.name + - if source.nil? + %td= t('logs.index.not_available') + - else + %td= source.owner.login + %td= event.summary
--- src/config/locales/en.yml | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml index f6d3623..11793d3 100644 --- a/src/config/locales/en.yml +++ b/src/config/locales/en.yml @@ -10,6 +10,23 @@ en: other: "%{count} hours" search: no_results: "No matching results." + logs: + options: + default_users: All Users + default_event_types: All Event Types + deployment_event_type: Deployment + instance_event_type: Instance + default_pools: All Pools + default_providers: All Providers + index: + not_available: N/A + event_time: Time + deployment: Deployment/Instance + pool: Pool + provider: Provider + owner: Owner + summary: Summary + details: Details users: users: "Users" return_to: "Return to:"
aeolus-devel@lists.fedorahosted.org