Skip to content

Commit

Permalink
Merge pull request Katello#241 from pitr-ch/808437-RFE-no_notificatio…
Browse files Browse the repository at this point in the history
…ns_for_CLI_actions_in_GUI

808437 rfe no notifications for cli actions in gui
  • Loading branch information
Petr Chalupa committed Jul 18, 2012
2 parents d466594 + 84ab040 commit f9fbf34
Show file tree
Hide file tree
Showing 69 changed files with 907 additions and 828 deletions.
35 changes: 18 additions & 17 deletions src/app/controllers/activation_keys_controller.rb
Expand Up @@ -111,11 +111,11 @@ def add_subscriptions
end
end
end
notice _("Subscriptions successfully added to Activation Key '%s'.") % @activation_key.name
notify.success _("Subscriptions successfully added to Activation Key '%s'.") % @activation_key.name
render :partial => "available_subscriptions_update.js.haml"

rescue Exception => error
notice error.to_s, {:level => :error}
notify.exception error
render :nothing => true
end
end
Expand All @@ -135,11 +135,11 @@ def remove_subscriptions
end
end
end
notice _("Subscriptions successfully removed from Activation Key '%s'.") % @activation_key.name
notify.success _("Subscriptions successfully removed from Activation Key '%s'.") % @activation_key.name
render :partial => "applied_subscriptions_update.js.haml"

rescue Exception => error
notice error.to_s, {:level => :error}
notify.exception error
render :nothing => true
end
end
Expand All @@ -157,10 +157,10 @@ def add_system_groups
@activation_key.system_group_ids = (@activation_key.system_group_ids + @system_groups.collect{|g| g.id}).uniq
@activation_key.save!
end
notice _("Activation key '%s' was updated.") % @activation_key["name"]
notify.success _("Activation key '%s' was updated.") % @activation_key["name"]
render :partial =>'system_group_items', :locals=>{:system_groups=>@system_groups.sort_by{|g| g.name}, :editable=>ActivationKey.manageable?(current_organization)} and return
rescue Exception => e
notice e, {:level => :error}
notify.exception e
render :text=>e, :status=>500
end

Expand All @@ -169,10 +169,10 @@ def remove_system_groups
@activation_key.system_group_ids = (@activation_key.system_group_ids - system_groups).uniq
@activation_key.save!

notice _("Activation key '%s' was updated.") % @activation_key["name"]
notify.success _("Activation key '%s' was updated.") % @activation_key["name"]
render :nothing => true
rescue Exception => e
notice e, {:level => :error}
notify.exception e
render :text=>e, :status=>500
end

Expand Down Expand Up @@ -217,17 +217,18 @@ def create
key.organization = current_organization
key.user = current_user
end
notice _("Activation key '%s' was created.") % @activation_key['name']
notify.success _("Activation key '%s' was created.") % @activation_key['name']

if search_validate(ActivationKey, @activation_key.id, params[:search])
render :partial=>"common/list_item", :locals=>{:item=>@activation_key, :accessor=>"id", :columns=>['name'], :name=>controller_display_name}
else
notice _("'%s' did not meet the current search criteria and is not being shown.") % @activation_key["name"], { :level => 'message', :synchronous_request => false }
notify.message _("'%s' did not meet the current search criteria and is not being shown.") %
@activation_key["name"]
render :json => { :no_match => true }
end
rescue Exception => error
Rails.logger.error error.to_s
notice error, {:level => :error}
notify.exception error
render :text => error, :status => :bad_request
end

Expand All @@ -245,7 +246,7 @@ def update

@activation_key.update_attributes!(params[:activation_key])

notice _("Activation key '%s' was updated.") % @activation_key["name"]
notify.success _("Activation key '%s' was updated.") % @activation_key["name"]

unless params[:activation_key][:system_template_id].nil? or params[:activation_key][:system_template_id].blank?
# template is being updated.. so return template name vs id...
Expand All @@ -254,13 +255,13 @@ def update
end

if not search_validate(ActivationKey, @activation_key.id, params[:search])
notice _("'%s' no longer matches the current search criteria.") % @activation_key["name"], { :level => :message, :synchronous_request => true }
notify.message _("'%s' no longer matches the current search criteria.") % @activation_key["name"]
end

render :text => escape_html(result)

rescue Exception => error
notice error, {:level => :error}
notify.exception error

respond_to do |format|
format.json { render :partial => "common/notification", :status => :bad_request, :content_type => 'text/html' and return}
Expand All @@ -272,14 +273,14 @@ def destroy
begin
@activation_key.destroy
if @activation_key.destroyed?
notice _("Activation key '#{@activation_key[:name]}' was deleted.")
notify.success _("Activation key '#{@activation_key[:name]}' was deleted.")
#render and do the removal in one swoop!
render :partial => "common/list_remove", :locals => {:id=>params[:id], :name=>controller_display_name}
else
raise
end
rescue Exception => e
notice e.to_s, {:level => :error}
notify.exception e
end
end

Expand All @@ -289,7 +290,7 @@ def find_activation_key
begin
@activation_key = ActivationKey.find(params[:id])
rescue Exception => error
notice error.to_s, {:level => :error}
notify.exception error

# flash_to_headers is an after_filter executed on the application controller;
# however, a render from within a before_filter will halt the filter chain.
Expand Down
2 changes: 1 addition & 1 deletion src/app/controllers/api/changesets_controller.rb
Expand Up @@ -64,7 +64,7 @@ def create
def promote
@changeset.state = Changeset::REVIEW
@changeset.save!
async_job = @changeset.promote(true)
async_job = @changeset.promote :async => true
render :json => async_job, :status => 202
end

Expand Down
2 changes: 1 addition & 1 deletion src/app/controllers/api/organizations_controller.rb
Expand Up @@ -58,7 +58,7 @@ def update
end

def destroy
async_job = current_user.destroy_organization_async(@organization)
async_job = OrganizationDestroyer.destroy @organization
render :json => async_job, :status => 202
end

Expand Down
24 changes: 11 additions & 13 deletions src/app/controllers/application_controller.rb
Expand Up @@ -11,14 +11,13 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'util/threadsession'
require 'util/notices'
require 'util/search'
require 'cgi'
require 'base64'

class ApplicationController < ActionController::Base
layout 'katello'
include Katello::Notices
include Notifications::ControllerHelper
include Profiling
clear_helpers

Expand Down Expand Up @@ -169,7 +168,7 @@ def require_user
return true
else
#user not logged
notice _("You must be logged in to access that page."), {:level => true, :persist => false}
notify.warning _("You must be logged in to access that page.")

#save original uri and redirect to login page
session[:original_uri] = request.fullpath
Expand All @@ -180,7 +179,7 @@ def require_user

def require_no_user
if current_user
notice _("Welcome Back") + ", " + current_user.username
notify.success _("Welcome Back") + ", " + current_user.username, :persist => false
execute_after_filters
redirect_to dashboard_index_url
return false
Expand Down Expand Up @@ -256,7 +255,9 @@ def render_404(exception = nil)
def render_bad_parameters(exception = nil)
if exception
logger.error _("Rendering 400:") + " #{exception.message}"
notice _("Invalid parameters sent in the request for this operation. Please contact a system administrator."), {:level => :error, :details => exception.message}
notify.exception(
_("Invalid parameters sent in the request for this operation. Please contact a system administrator."),
exception)
end
respond_to do |format|
#format.html { render :template => "common/400", :layout => "katello", :status => 400,
Expand All @@ -274,7 +275,7 @@ def render_bad_parameters(exception = nil)
def render_error(exception = nil)
if exception
logger.error _("Rendering 500:") + "#{exception.message}"
notice exception.to_s, {:level => :error}
notify.exception exception
end
respond_to do |format|
format.html { render :template => "common/500", :layout => "katello", :status => 500,
Expand Down Expand Up @@ -340,10 +341,6 @@ def setup_environment_selector org, accessible
end
end

def pp_exception(exception)
"#{exception.class}: #{exception.message}\n" << exception.backtrace.join("\n")
end

#verify if the specific object with the given id, matches a given search string
def search_validate(obj_class, id, search, default=:name)
obj_class.index.refresh
Expand Down Expand Up @@ -506,7 +503,7 @@ def render_panel_items(items, options, search, start)
def catch_exceptions
yield
rescue Exception => error
notice error, {:level => :error}
notify.exception error
#render :text => error, :status => :bad_request
render_error(error)
end
Expand Down Expand Up @@ -536,7 +533,7 @@ def execute_rescue exception, renderer
execute_after_filters
return false
else
notice _("You must be logged in to access that page."), {:level => :error, :persist => false}
notify.warning _("You must be logged in to access that page.")
execute_after_filters
redirect_to new_user_session_url and return false
end
Expand All @@ -546,7 +543,8 @@ def org_not_found_error exception
logger.error exception.message
execute_after_filters
logout
notice _("You current organization is no longer valid. It is possible that either the organization has been deleted or your permissions revoked, please log back in to continue."),{:level => :error, :persist => false}
message = _("You current organization is no longer valid. It is possible that either the organization has been deleted or your permissions revoked, please log back in to continue.")
notify.warning message
redirect_to new_user_session_url and return false
end

Expand Down
14 changes: 7 additions & 7 deletions src/app/controllers/changesets_controller.rb
Expand Up @@ -106,7 +106,7 @@ def create
begin
@changeset = Changeset.create!(:name=>params[:name], :description => params[:description],
:environment_id=>@environment.id)
notice _("Promotion Changeset '%s' was created.") % @changeset["name"]
notify.success _("Promotion Changeset '%s' was created.") % @changeset["name"]
bc = {}
add_crumb_node!(bc, changeset_bc_id(@changeset), '', @changeset.name, ['changesets'],
{:client_render => true}, {:is_new=>true})
Expand All @@ -117,7 +117,7 @@ def create
}
rescue Exception => error
Rails.logger.error error.to_s
notice error, {:level => :error}
notify.exception error
render :json=>error, :status=>:bad_request
end
end
Expand Down Expand Up @@ -209,7 +209,7 @@ def destroy
name = @changeset.name
id = @changeset.id
@changeset.destroy
notice _("Promotion Changeset '%s' was deleted.") % name
notify.success _("Promotion Changeset '%s' was deleted.") % name
render :text=>""
end

Expand All @@ -234,14 +234,14 @@ def promote
if !messages.empty?
to_ret[:warnings] = render_to_string(:partial=>'warning', :locals=>messages)
else
@changeset.promote
@changeset.promote :notify => true, :async => true
# remove user edit tracking for this changeset
ChangesetUser.destroy_all(:changeset_id => @changeset.id)
notice _("Started promotion of '%s' to %s environment") % [@changeset.name, @environment.name]
notify.success _("Started promotion of '%s' to %s environment") % [@changeset.name, @environment.name]
end
render :json=>to_ret
rescue Exception => e
notice "Failed to promote: #{e.to_s}", {:level => :error}
notify.exception "Failed to promote.", e
render :text=>e.to_s, :status=>500
end

Expand Down Expand Up @@ -277,7 +277,7 @@ def find_changeset
begin
@changeset = Changeset.find(params[:id])
rescue Exception => error
notice error.to_s, {:level => :error}
notify.exception error
execute_after_filters
render :text=>error.to_s, :status=>:bad_request
end
Expand Down
10 changes: 5 additions & 5 deletions src/app/controllers/environments_controller.rb
Expand Up @@ -78,7 +78,7 @@ def create
@environment = KTEnvironment.new env_params

@environment.save!
notice _("Environment '%s' was created.") % @environment.name
notify.success _("Environment '%s' was created.") % @environment.name
#this render just means return a 200 success
render :nothing => true

Expand All @@ -101,15 +101,15 @@ def update
result = params[:kt_environment].values.first
end

notice _("Environment '%s' was updated.") % @environment.name
notify.success _("Environment '%s' was updated.") % @environment.name

render :text =>escape_html(result)
end

# DELETE /environments/1
def destroy
@environment.destroy
notice _("Environment '%s' was deleted.") % @environment.name
notify.success _("Environment '%s' was deleted.") % @environment.name
render :partial => "common/post_delete_close_subpanel", :locals => {:path=>edit_organization_path(@organization.cp_key)}
end

Expand All @@ -131,15 +131,15 @@ def products
def find_organization
org_id = params[:organization_id] || params[:org_id]
@organization = Organization.first(:conditions => {:cp_key => org_id})
notice _("Couldn't find organization '%d'") % org_id, {:level => :error} if @organization.nil?
notify.error _("Couldn't find organization '%d'") % org_id if @organization.nil?
end

def find_environment
begin
env_id = (params[:id].blank? ? nil : params[:id]) || params[:env_id]
@environment = KTEnvironment.find env_id
rescue Exception => error
notice _("Couldn't find environment with ID=%d") % env_id, {:level => :error}
notify.error _("Couldn't find environment with ID=%d") % env_id
execute_after_filters
render :text => error, :status => :bad_request
end
Expand Down

0 comments on commit f9fbf34

Please sign in to comment.