Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified app/assets/images/widget_logos/OH_Partner_frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/controllers/account_widgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class AccountWidgetsController < WidgetsController
before_action :set_account
before_action :render_image_for_gif_format
before_action :render_image_for_image_format
before_action :account_context, only: :index

def index
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/organization_widgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class OrganizationWidgetsController < WidgetsController
before_action :set_organization
before_action :render_not_supported_for_gif_format
before_action :render_not_supported_for_image_format
before_action :render_iframe_for_js_format
before_action :organization_context, only: :index

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/project_widgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class ProjectWidgetsController < WidgetsController
helper :Projects, :Analyses
before_action :set_project
before_action :render_image_for_gif_format, only: %i[partner_badge thin_badge]
before_action :render_not_supported_for_gif_format, except: %i[partner_badge thin_badge index]
before_action :render_image_for_image_format, only: %i[partner_badge thin_badge]
before_action :render_not_supported_for_image_format, except: %i[partner_badge thin_badge index]
before_action :render_iframe_for_js_format
before_action :project_context, only: :index

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stack_widgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class StackWidgetsController < WidgetsController
before_action :set_widget
before_action :set_stack_and_account
before_action :render_not_supported_for_gif_format
before_action :render_not_supported_for_image_format
before_action :render_iframe_for_js_format
before_action :account_context, only: :index

Expand Down
18 changes: 12 additions & 6 deletions app/controllers/widgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ def set_widget
.new(permitted_params)
end

def render_image_for_gif_format
return unless request.format.gif?
def render_image_for_image_format
return unless request.format.gif? || request.format.png?

cache_key = "#{@widget.parent.class.name}/#{@widget.parent.id}/#{@widget.name}"
image = Rails.cache.fetch(cache_key, expires_in: 4.hours) { @widget.image }
send_data(image, disposition: 'inline', type: 'image/gif', filename: 'widget.gif', status: 200)
if request.format.png?
send_data(image, disposition: 'inline', type: 'image/png', filename: 'widget.png', status: 200)
else
send_data(image, disposition: 'inline', type: 'image/gif', filename: 'widget.gif', status: 200)
end
end

def render_not_supported_for_gif_format
return unless request.format.gif?
def render_not_supported_for_image_format
return unless request.format.gif? || request.format.png?

image = Rails.cache.fetch('not_supported_widget') { WidgetBadge::Thin.create([text: 'Not supported']) }
send_data(image, disposition: 'inline', type: 'image/gif', filename: 'widget.gif', status: 406)
mime_type = request.format.png? ? 'image/png' : 'image/gif'
filename = request.format.png? ? 'widget.png' : 'widget.gif'
send_data(image, disposition: 'inline', type: mime_type, filename: filename, status: 406)
end

def render_iframe_for_js_format
Expand Down
2 changes: 1 addition & 1 deletion app/models/widget/account_widget/detailed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Widget::AccountWidget::Detailed < Widget::AccountWidget
def width
230
232
end

def height
Expand Down
2 changes: 1 addition & 1 deletion app/models/widget/account_widget/tiny.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Widget::AccountWidget::Tiny < Widget::AccountWidget
def height
15
16
end

def width
Expand Down
1 change: 1 addition & 0 deletions lib/widget_badge/badge_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module ClassMethods
def setup_blank
image = MiniMagick::Image.open(IMAGE_DIR.join('OH_Partner_frame.png'))
image.background('white')
image.flatten
image
end

Expand Down
Binary file modified test/data/widget_badge/account/badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/widget_badge/account/new_text_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/widget_badge/account/text_without_name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/widget_badge/partner/add_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/widget_badge/partner/badge.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/widget_badge/partner/text_without_name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/widget_badge/thin/openhub_and_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.