Skip to content
Closed
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
7 changes: 6 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ ruby '2.4.1'
gemspec

gem 'faker'
gem 'stripe_event'
gem 'refile', require: 'refile/rails', git: 'https://github.com/manfe/refile.git'

gem 'elasticsearch-model', git: 'https://github.com/elasticsearch/elasticsearch-rails.git'
gem 'elasticsearch-rails', git: 'https://github.com/elasticsearch/elasticsearch-rails.git'
gem 'sidekiq'
gem 'aws-sdk'
gem 'doorkeeper', '4.3.2'
gem 'redis-objects'
gem 'stripe'

group :development, :test do
gem 'byebug', platform: :mri
Expand All @@ -27,6 +28,10 @@ group :development, :test do
gem 'awesome_print'
end

group :development do
gem 'ultrahook'
end

group :test do
gem 'database_cleaner'
gem 'poltergeist'
Expand Down
45 changes: 28 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ PATH
rails
rails-jquery-autocomplete
redis (< 4)
redis-objects
refile
rmagick
sidekiq
slim-rails
stripe
versionist
whenever

Expand Down Expand Up @@ -114,7 +114,7 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_model_serializers (0.10.7)
active_model_serializers (0.10.9)
actionpack (>= 4.1, < 6)
activemodel (>= 4.1, < 6)
case_transform (>= 0.2)
Expand Down Expand Up @@ -850,6 +850,7 @@ GEM
thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.0.2)
jsonapi-renderer (0.2.0)
kaminari (1.1.1)
activesupport (>= 4.1.0)
Expand Down Expand Up @@ -878,12 +879,14 @@ GEM
multi_json (1.13.1)
multipart-post (2.0.0)
mustermann (1.0.2)
net-http-persistent (3.0.0)
connection_pool (~> 2.2)
netrc (0.11.0)
nio4r (2.3.1)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
omniauth (1.8.1)
hashie (>= 3.4.6, < 3.6.0)
omniauth (1.9.0)
hashie (>= 3.4.6, < 3.7.0)
rack (>= 1.6.2, < 3)
paper_trail (9.2.0)
activerecord (>= 4.2, < 5.3)
Expand All @@ -902,7 +905,7 @@ GEM
activerecord (>= 3.0)
powerpack (0.1.2)
public_suffix (3.0.2)
pundit (2.0.0)
pundit (2.0.1)
activesupport (>= 3.0.0)
rack (2.0.5)
rack-cors (1.0.2)
Expand All @@ -927,7 +930,7 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rails-jquery-autocomplete (1.0.4)
rails-jquery-autocomplete (1.0.5)
rails (>= 3.2)
railties (5.1.6)
actionpack (= 5.1.6)
Expand All @@ -947,8 +950,6 @@ GEM
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
redis (3.3.5)
redis-objects (1.3.1)
redis (~> 3.3)
request_store (1.4.1)
rack (>= 1.4)
responders (2.4.0)
Expand All @@ -958,7 +959,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rmagick (2.16.0)
rmagick (3.0.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
Expand Down Expand Up @@ -1011,26 +1012,34 @@ GEM
rack (~> 2.0)
rack-protection (= 2.0.3)
tilt (~> 2.0)
slim (3.0.9)
slim (4.0.1)
temple (>= 0.7.6, < 0.9)
tilt (>= 1.3.3, < 2.1)
slim-rails (3.1.3)
tilt (>= 2.0.6, < 2.1)
slim-rails (3.2.0)
actionpack (>= 3.1)
railties (>= 3.1)
slim (~> 3.0)
slim (>= 3.0, < 5.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
temple (0.8.0)
stripe (4.9.0)
faraday (~> 0.13)
net-http-persistent (~> 3.0)
stripe_event (2.3.0)
activesupport (>= 3.1)
stripe (>= 2.8, < 6)
temple (0.8.1)
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
tzinfo (1.2.5)
thread_safe (~> 0.1)
ultrahook (0.1.5)
json (>= 1.8.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
Expand All @@ -1050,7 +1059,7 @@ GEM
chronic (>= 0.6.3)
xpath (3.1.0)
nokogiri (~> 1.8)
yard (0.9.16)
yard (0.9.24)

PLATFORMS
ruby
Expand All @@ -1074,18 +1083,20 @@ DEPENDENCIES
pg (~> 0.18)
poltergeist
rack-cors
redis-objects
refile!
rspec-rails
rubocop
rubocop-git
rubocop-rspec
shoulda-matchers!
sidekiq
stripe
stripe_event
ultrahook
webmock

RUBY VERSION
ruby 2.4.1p111

BUNDLED WITH
1.16.6
1.17.3
2 changes: 2 additions & 0 deletions app/assets/javascripts/active_admin.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#= require autocomplete-rails
#= require active_admin/achievement
#= require active_admin/reward
#= require active_admin/subscription


$ ->
COUNT = -1;
Expand Down
14 changes: 14 additions & 0 deletions app/assets/javascripts/active_admin/subscription.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$ ->
$('#owner_user_input').parent().hide()
$('#owner_organisation_input').parent().hide()

$('#subscription_owner_type').on 'change', (e)->
console.log $(e.target).val()

if $(e.target).val() == 'BeachApiCore::User'
$('#owner_user_input').parent().show()
$('#owner_organisation_input').parent().hide()

if $(e.target).val() == 'BeachApiCore::Organisation'
$('#owner_user_input').parent().hide()
$('#owner_organisation_input').parent().show()
10 changes: 10 additions & 0 deletions app/controllers/beach_api_core/concerns/v1/apipie_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ def apipie_user
@_apipie_user
end

def apipie_plan
@_apipie_subscription_plan ||= BeachApiCore::Plan.new(id: fake_id,
name: Faker::Name.title,
stripe_id: Faker::Lorem.word,
amount: Faker::Number.between(1000, 10000),
interval: %w(day month year).sample,
plan_for: %w(organisation user).sample
)
end

def apipie_asset
return @_apipie_asset if @_apipie_asset
@_apipie_asset = BeachApiCore::Asset.new(id: fake_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def apipie_user_response
).as_json
end

def apipie_plan_response
pretty BeachApiCore::PlanSerializer.new(apipie_plan)
end

def apipie_organisation_user_response
pretty BeachApiCore::OrganisationUserSerializer.new(
apipie_user, current_organisation: apipie_organisation
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/beach_api_core/v1/organisations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_current
private

def organisation_params
params.require(:organisation).permit(:name, logo_properties: logo_params, logo_image_attributes: %i(file base64))
params.require(:organisation).permit(:name, :email, logo_properties: logo_params, logo_image_attributes: %i(file base64))
end

def logo_params
Expand All @@ -109,7 +109,7 @@ def logo_params
def users_by_roles(users)
return users unless params[:roles].present?
filtered_users = users.joining { assignments }.where.has do |u|
(u.assignments.role_id.in params[:roles]) & (u.assignments.keeper_id == current_organisation.id) &
(u.assignments.keeper_id == current_organisation.id) &
( u.assignments.keeper_type == 'BeachApiCore::Organisation')
end
filtered_users.any? ? filtered_users : users
Expand Down
65 changes: 65 additions & 0 deletions app/controllers/beach_api_core/v1/plans_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module BeachApiCore
class V1::PlansController < BeachApiCore::V1::BaseController
include PlansDoc
include BeachApiCore::Concerns::V1::ResourceConcern

before_action :doorkeeper_authorize!

resource_description do
name I18n.t('api.resource_description.resources.plans')
end

def index
render_json_success(Plan.all, :ok,
each_serializer: PlanSerializer,
root: :plans)
end

def create
if admin
result = PlanCreate.call(params: plan_params)
if result.success?
render_json_success(result.plan, :ok, serializer: BeachApiCore::PlanSerializer, root: :plan)
else
render_json_error({ message: result.message }, result.status)
end
else
render_json_error({message: "Wrong permissions"})
end
end

def show
plan = Plan.find_by(id: params[:id])
if plan.nil?
render_json_error({message: "There are no such plan"})
else
render_json_success(plan)
end
end

def destroy
if admin
plan = Plan.find_by(id: params[:id])
if plan.nil?
render_json_error({message: "Could not remove plan"})
else
begin
if plan.destroy
head :no_content
else
render_json_error({message: "Could not remove plan"})
end
rescue => e
render_json_error({message: "Could not remove plan"})
end
end
end
end

private

def plan_params
params.require(:plan).permit(:name, :amount, :interval, :stripe_id, :plan_for, :currency, :trial_period_days, :amount_per_additional_user, :users_count)
end
end
end
Loading