-
-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into cookies_banner
- Loading branch information
Showing
37 changed files
with
548 additions
and
61 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
app/assets/javascripts/darkswarm/controllers/authorised_shops_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
angular.module("Darkswarm").controller "AuthorisedShopsCtrl", ($scope, Customers, Shops) -> | ||
$scope.customers = Customers.index() | ||
$scope.shopsByID = Shops.byID |
10 changes: 10 additions & 0 deletions
10
app/assets/javascripts/darkswarm/directives/help_modal.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Darkswarm.directive "helpModal", ($modal, $compile, $templateCache)-> | ||
restrict: 'A' | ||
scope: | ||
helpText: "@helpModal" | ||
|
||
link: (scope, elem, attrs, ctrl)-> | ||
compiled = $compile($templateCache.get('help-modal.html'))(scope) | ||
|
||
elem.on "click", => | ||
$modal.open(controller: ctrl, template: compiled, scope: scope, windowClass: 'help-modal small') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/assets/javascripts/darkswarm/services/customer.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
angular.module("Darkswarm").factory 'Customer', ($resource, RailsFlashLoader) -> | ||
Customer = $resource('/api/customers/:id/:action.json', {}, { | ||
'index': | ||
method: 'GET' | ||
isArray: true | ||
'update': | ||
method: 'PUT' | ||
params: | ||
id: '@id' | ||
transformRequest: (data, headersGetter) -> | ||
angular.toJson(customer: data) | ||
}) | ||
|
||
Customer.prototype.update = -> | ||
@$update().then (response) => | ||
RailsFlashLoader.loadFlash({success: t('js.changes_saved')}) | ||
, (response) => | ||
RailsFlashLoader.loadFlash({error: response.data.error}) | ||
|
||
Customer |
14 changes: 14 additions & 0 deletions
14
app/assets/javascripts/darkswarm/services/customers.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
angular.module("Darkswarm").factory 'Customers', (Customer) -> | ||
new class Customers | ||
all: [] | ||
byID: {} | ||
|
||
index: (params={}) -> | ||
return @all if @all.length | ||
Customer.index params, (data) => @load(data) | ||
@all | ||
|
||
load: (customers) -> | ||
for customer in customers | ||
@all.push customer | ||
@byID[customer.id] = customer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
angular.module("Darkswarm").factory 'Shops', ($injector) -> | ||
new class Shops | ||
all: [] | ||
byID: {} | ||
|
||
constructor: -> | ||
if $injector.has('shops') | ||
@load($injector.get('shops')) | ||
|
||
load: (shops) -> | ||
for shop in shops | ||
@all.push shop | ||
@byID[shop.id] = shop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.row.help-icon | ||
.small-12.text-center | ||
%i.ofn-i_013-help | ||
.row.help-text | ||
.small-12.columns.text-center | ||
{{ helpText }} | ||
.row.text-center | ||
%button.primary.small{ ng: { click: '$close()' } } | ||
= t(:ok) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,12 @@ | |
margin-bottom: 0px; | ||
} | ||
} | ||
|
||
.authorised_shops{ | ||
table { | ||
width: 100%; | ||
} | ||
} | ||
} | ||
|
||
.orders { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.help-modal { | ||
.help-text { | ||
font-size: 1rem; | ||
margin: 20px 0px; | ||
} | ||
.help-icon { | ||
font-size: 4rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,9 @@ button.success, .button.success { | |
&.tiny { | ||
padding: 0rem; | ||
margin: 0; | ||
} | ||
|
||
&.right { | ||
float: right; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Base controller for OFN's API | ||
# Includes the minimum machinery required by ActiveModelSerializers | ||
module Api | ||
class BaseController < Spree::Api::BaseController | ||
# Need to include these because Spree::Api::BaseContoller inherits | ||
# from ActionController::Metal rather than ActionController::Base | ||
# and they are required by ActiveModelSerializers | ||
include ActionController::Serialization | ||
include ActionController::UrlFor | ||
include Rails.application.routes.url_helpers | ||
use_renderers :json | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Api | ||
class CustomersController < BaseController | ||
def index | ||
@customers = current_api_user.customers.of_regular_shops | ||
render json: @customers, each_serializer: CustomerSerializer | ||
end | ||
|
||
def update | ||
@customer = Customer.find(params[:id]) | ||
authorize! :update, @customer | ||
|
||
if @customer.update_attributes(params[:customer]) | ||
render json: @customer, serializer: CustomerSerializer, status: 200 | ||
else | ||
invalid_resource!(@customer) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Api | ||
class CustomerSerializer < ActiveModel::Serializer | ||
attributes :id, :enterprise_id, :name, :code, :email, :allow_charges | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Processes requests for pages embedded in iframes | ||
|
||
class EmbeddedPageService | ||
def initialize(params, session, request, response) | ||
@params = params | ||
@session = session | ||
@request = request | ||
@response = response | ||
|
||
@embedding_domain = @session[:embedding_domain] | ||
@use_embedded_layout = false | ||
end | ||
|
||
def embed! | ||
return unless embeddable? | ||
return if embedding_without_https? | ||
|
||
process_embedded_request | ||
set_response_headers | ||
set_embedded_layout | ||
end | ||
|
||
def use_embedded_layout? | ||
@use_embedded_layout | ||
end | ||
|
||
private | ||
|
||
def embeddable? | ||
return true if current_referer == @request.host | ||
|
||
domain = current_referer_without_www | ||
whitelist = Spree::Config[:embedded_shopfronts_whitelist] | ||
|
||
embedding_enabled? && whitelist.present? && domain.present? && whitelist.include?(domain) | ||
end | ||
|
||
def embedding_without_https? | ||
@request.referer && URI(@request.referer).scheme != 'https' && !Rails.env.test? && !Rails.env.development? | ||
end | ||
|
||
def process_embedded_request | ||
return unless @params[:embedded_shopfront] | ||
|
||
set_embedding_domain | ||
|
||
@session[:embedded_shopfront] = true | ||
set_logout_redirect | ||
end | ||
|
||
def set_response_headers | ||
@response.headers.delete 'X-Frame-Options' | ||
@response.headers['Content-Security-Policy'] = "frame-ancestors 'self' #{@embedding_domain}" | ||
end | ||
|
||
def set_embedding_domain | ||
return unless @params[:embedded_shopfront] | ||
return if current_referer == @request.host | ||
|
||
@embedding_domain = current_referer | ||
@session[:embedding_domain] = current_referer | ||
end | ||
|
||
def set_logout_redirect | ||
return unless enterprise_slug | ||
@session[:shopfront_redirect] = '/' + enterprise_slug + '/shop?embedded_shopfront=true' | ||
end | ||
|
||
def enterprise_slug | ||
return false unless @params[:controller] == 'enterprises' && @params[:action] == 'shop' && @params[:id] | ||
@params[:id] | ||
end | ||
|
||
def current_referer | ||
return if @request.referer.blank? | ||
URI(@request.referer).host.downcase | ||
end | ||
|
||
def current_referer_without_www | ||
return unless current_referer | ||
current_referer.start_with?('www.') ? current_referer[4..-1] : current_referer | ||
end | ||
|
||
def set_embedded_layout | ||
return unless @session[:embedded_shopfront] | ||
@use_embedded_layout = true | ||
end | ||
|
||
def embedding_enabled? | ||
Spree::Config[:enable_embedded_shopfronts] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%table | ||
%tr | ||
%th= t(:shop_title) | ||
%th= t(:allow_charges?) | ||
%tr.customer{ id: "customer{{ customer.id }}", ng: { repeat: "customer in customers" } } | ||
%td.shop{ ng: { bind: 'shopsByID[customer.enterprise_id].name' } } | ||
%td.allow_charges | ||
%input{ type: 'checkbox', | ||
name: 'allow_charges', | ||
ng: { model: 'customer.allow_charges', | ||
change: 'customer.update()', | ||
"true-value" => "true", | ||
"false-value" => "false" } } |
Oops, something went wrong.