Skip to content
Merged
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
25 changes: 18 additions & 7 deletions app/controllers/widgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,30 @@ 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?

send_data(cached_widget_image, disposition: 'inline', type: image_mime_type, filename: image_filename, status: 200)
end

def cached_widget_image
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)
Rails.cache.fetch(cache_key, expires_in: 4.hours) { @widget.image }
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)
send_data(image, disposition: 'inline', type: image_mime_type, filename: image_filename, status: 406)
end

def image_mime_type
request.format.png? ? 'image/png' : 'image/gif'
end

def image_filename
request.format.png? ? 'widget.png' : 'widget.gif'
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
2 changes: 1 addition & 1 deletion test/controllers/positions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class PositionsControllerTest < ActionController::TestCase
assert_response :success
language = position.name_fact.primary_language.nice_name
_(unescaped_response_body).must_match "1\nCommit\n</a>in mostly\n#{language}"
_(unescaped_response_body).must_match position.name_fact.analysis.project.organization.name
_(unescaped_response_body).must_include position.name_fact.analysis.project.organization.name
assert_select 'div#all_projects.chart-with-data[data-value]', 1
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.
2 changes: 1 addition & 1 deletion test/helpers/widgets_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class WidgetsHelperTest < ActionView::TestCase

describe 'widget_iframe_style' do
it 'should return css' do
_(widget_iframe_style(widget)).must_equal 'height: 35px; width: 230px; border: none'
_(widget_iframe_style(widget)).must_equal 'height: 35px; width: 232px; border: none'
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/lib/widget_badge/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
result_blob = WidgetBadge::Account.create(options)
result_file = write_to_file(result_blob)

compare_images(result_file.path, expected_image_path, 0.1)
compare_images(result_file.path, expected_image_path, 0.15)
end

it 'must handle spaces and utf-8 characters in account names' do
Expand Down
4 changes: 2 additions & 2 deletions test/models/widget/account_widget/detailed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class DetailedTest < ActiveSupport::TestCase
let(:widget) { Widget::AccountWidget::Detailed.new(account_id: account.id) }

describe 'width' do
it 'should return 230' do
_(widget.width).must_equal 230
it 'should return 232' do
_(widget.width).must_equal 232
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/models/widget/account_widget/tiny_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class TinyTest < ActiveSupport::TestCase
end

describe 'height' do
it 'should return 15' do
_(widget.height).must_equal 15
it 'should return 16' do
_(widget.height).must_equal 16
end
end

Expand Down
Loading