Skip to content

Commit

Permalink
Merge branch 'master' into update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez authored Jul 18, 2018
2 parents 108c4a7 + 7bf27ec commit d56698e
Show file tree
Hide file tree
Showing 95 changed files with 1,453 additions and 462 deletions.
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ context for others to understand it]
[In case this should be present in the release notes, please write them or
remove this section otherwise]

[To streamline the release process, please designate your PR with ONE of the following
categories, based on the specification from keepachangelog.com (and delete the others):]

Changelog Category: Added | Changed | Deprecated | Removed | Fixed | Security

#### How is this related to the Spree upgrade?

[Any known conflicts with the Spree Upgrade? explain them or remove this section
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ If you want to run the whole test suite, we recommend using a free CI service to

bundle exec rspec spec

## Internationalisation (i18n)

The locale `en` is maintained in the source code, but other locales are managed at [Transifex][ofn-transifex]. Read more about [internationalisation][i18n] in the developer wiki.

## Making a change

Make your changes to the codebase. We recommend using TDD. Add a test, make changes and get the test suite back to green.
Expand All @@ -36,7 +40,7 @@ Push your changes to a branch on your fork:

## Submitting a Pull Request

Use the GitHub UI to submit a [new pull request][pr] against upstream/master. To increase the chances that your pull request is swiftly accepted please have a look at our guide to [[making a great pull request]].
Use the GitHub UI to submit a [new pull request][pr] against upstream/master. To increase the chances that your pull request is swiftly accepted please have a look at our guide to [making a great pull request][great-pr].

TL;DR:
* Write tests
Expand All @@ -56,3 +60,5 @@ From here, your pull request will progress through the [Review, Test, Merge & De
[travis]: https://travis-ci.org/
[semaphore]: https://semaphoreci.com/
[slack-dev]: https://openfoodnetwork.slack.com/messages/C2GQ45KNU
[ofn-transifex]: https://www.transifex.com/open-food-foundation/open-food-network/
[i18n]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/i18n
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ angular.module("ofn.admin").factory "BulkProducts", (PagedFetcher, dataFetcher,
variantUnitValue: (product, variant) ->
if variant.unit_value?
if product.variant_unit_scale
variant.unit_value / product.variant_unit_scale
@divideAsInteger variant.unit_value, product.variant_unit_scale
else
variant.unit_value
else
null

# forces integer division to avoid javascript floating point imprecision
# using one billion as the multiplier so that it works for numbers with up to 9 decimal places
divideAsInteger: (a, b) ->
(a * 1000000000) / (b * 1000000000)
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
angular.module("admin.subscriptions").controller "DetailsController", ($scope, $http, CreditCardResource, StatusMessage) ->
angular.module("admin.subscriptions").controller "DetailsController", ($scope, $http, CustomerResource, StatusMessage) ->
$scope.cardRequired = false

$scope.registerNextCallback 'details', ->
$scope.subscription_form.$submitted = true
if $scope.subscription_details_form.$valid
$scope.subscription_form.$setPristine()
StatusMessage.clear()
$scope.setView('address')
else
StatusMessage.display 'failure', t('admin.subscriptions.details.invalid_error')
return unless $scope.validate()
$scope.subscription_form.$setPristine()
StatusMessage.clear()
$scope.setView('address')

$scope.$watch "subscription.customer_id", (newValue, oldValue) ->
return if !newValue?
$scope.loadAddresses(newValue) unless $scope.subscription.id?
$scope.loadCreditCards(newValue)
$scope.loadCustomer(newValue) unless $scope.subscription.id?

$scope.$watch "subscription.payment_method_id", (newValue, oldValue) ->
return if !newValue?
paymentMethod = ($scope.paymentMethods.filter (pm) -> pm.id == newValue)[0]
return unless paymentMethod?
if paymentMethod.type == "Spree::Gateway::StripeConnect"
$scope.cardRequired = true
else
$scope.cardRequired = false
$scope.subscription.credit_card_id = null
$scope.cardRequired = (paymentMethod.type == "Spree::Gateway::StripeConnect")
$scope.loadCustomer() if $scope.cardRequired && !$scope.customer

$scope.loadAddresses = (customer_id) ->
$http.get("/admin/customers/#{customer_id}/addresses")
.success (response) =>
delete response.bill_address.id
delete response.ship_address.id
angular.extend($scope.subscription.bill_address, response.bill_address)
angular.extend($scope.subscription.ship_address, response.ship_address)
$scope.shipAddressFromBilling() unless response.ship_address.address1?
$scope.loadCustomer = ->
params = { id: $scope.subscription.customer_id }
params.ams_prefix = 'subscription' unless $scope.subscription.id
$scope.customer = CustomerResource.get params, (response) ->
for address in ['bill_address','ship_address']
return unless response[address]
delete response[address].id
return if $scope.subscription[address].address1?
angular.extend($scope.subscription[address], response[address])
$scope.shipAddressFromBilling() unless response.ship_address?.address1?

$scope.loadCreditCards = (customer_id) ->
$scope.creditCards = CreditCardResource.index(customer_id: customer_id)
$scope.validate = ->
return true if $scope.subscription_details_form.$valid && $scope.creditCardOk()
StatusMessage.display 'failure', t('admin.subscriptions.details.invalid_error')
false

$scope.creditCardOk = ->
return true unless $scope.cardRequired
return false unless $scope.customer
return false unless $scope.customer.allow_charges
return false unless $scope.customer.default_card_present
true

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
angular.module("admin.subscriptions").factory 'CustomerResource', ($resource) ->
$resource '/admin/customers/:id.json'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
angular.module("admin.users").directive "resendUserEmailConfirmation", ($http) ->
template: "{{ 'js.admin.resend_user_email_confirmation.' + status | t }}"
scope:
email: "@resendUserEmailConfirmation"
link: (scope, element, attrs) ->
sent = false
scope.status = "resend"

element.bind "click", ->
return if sent
scope.status = "sending"
$http.post("/user/spree_user/confirmation", {spree_user: {email: scope.email}}).success (data) ->
sent = true
element.addClass "action--disabled"
scope.status = "done"
.error (data) ->
scope.status = "failed"
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 app/assets/javascripts/darkswarm/directives/help_modal.js.coffee
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')
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Darkswarm.directive "stripeElements", ($injector, StripeElements) ->
stripe = $injector.get('stripeObject')

card = stripe.elements().create 'card',
hidePostalCode: false
hidePostalCode: true
style:
base:
fontFamily: "Roboto, Arial, sans-serif"
Expand Down
20 changes: 20 additions & 0 deletions app/assets/javascripts/darkswarm/services/customer.js.coffee
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 app/assets/javascripts/darkswarm/services/customers.js.coffee
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
13 changes: 13 additions & 0 deletions app/assets/javascripts/darkswarm/services/shops.js.coffee
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
9 changes: 9 additions & 0 deletions app/assets/javascripts/templates/help-modal.html.haml
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)
1 change: 1 addition & 0 deletions app/assets/stylesheets/admin/icons.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import 'plugins/font-awesome';

.icon-refund:before { @extend .icon-ok:before }
.icon-credit:before { @extend .icon-ok:before }
8 changes: 8 additions & 0 deletions app/assets/stylesheets/admin/openfoodnetwork.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ a {
cursor:pointer;
}

a.action--disabled {
cursor: default;

&:hover {
color: #5498da;
}
}

form.order_cycle {
h2 {
margin-top: 2em;
Expand Down
6 changes: 6 additions & 0 deletions app/assets/stylesheets/darkswarm/account.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
margin-bottom: 0px;
}
}

.authorised_shops{
table {
width: 100%;
}
}
}

.orders {
Expand Down
9 changes: 9 additions & 0 deletions app/assets/stylesheets/darkswarm/help-modal.css.scss
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;
}
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/darkswarm/ui.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ button.success, .button.success {
&.tiny {
padding: 0rem;
margin: 0;
}

&.right {
float: right;
}

Expand Down
24 changes: 8 additions & 16 deletions app/controllers/admin/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def index
end
end

def show
render_as_json @customer, ams_prefix: params[:ams_prefix]
end

def create
@customer = Customer.new(params[:customer])
if user_can_create_customer?
Expand Down Expand Up @@ -55,22 +59,6 @@ def destroy
end
end

# GET /admin/customers/:id/addresses
# Used by subscriptions form to load details for selected customer
def addresses
finder = OpenFoodNetwork::AddressFinder.new(@customer, @customer.email)
bill_address = Api::AddressSerializer.new(finder.bill_address).serializable_hash
ship_address = Api::AddressSerializer.new(finder.ship_address).serializable_hash
render json: { bill_address: bill_address, ship_address: ship_address }
end

# GET /admin/customers/:id/cards
# Used by subscriptions form to load details for selected customer
def cards
cards = Spree::CreditCard.where(user_id: @customer.user_id)
render json: ActiveModel::ArraySerializer.new(cards, each_serializer: Api::CreditCardSerializer)
end

private

def collection
Expand All @@ -87,5 +75,9 @@ def user_can_create_customer?
spree_current_user.admin? ||
spree_current_user.enterprises.include?(@customer.enterprise)
end

def ams_prefix_whitelist
[:subscription]
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/order_cycles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Admin
class OrderCyclesController < ResourceController
include OrderCyclesHelper

prepend_before_filter :load_data_for_index, :only => :index
before_filter :load_data_for_index, only: :index
before_filter :require_coordinator, only: :new
before_filter :remove_protected_attrs, only: [:update]
before_filter :require_order_cycle_set_params, only: [:bulk_update]
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/api/base_controller.rb
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
19 changes: 19 additions & 0 deletions app/controllers/api/customers_controller.rb
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
2 changes: 1 addition & 1 deletion app/controllers/api/statuses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Api
class StatusesController < BaseController
class StatusesController < ::BaseController
respond_to :json

def job_queue
Expand Down
Loading

0 comments on commit d56698e

Please sign in to comment.