Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: paid subscriptions system and articles #467

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
01e20d1
wip: begin of migration creation
DioFun Jun 20, 2024
5a8e0df
feat: creating migration (work in progress)
benoitlx Jun 20, 2024
f76fb69
fix: relations that wasn't well defined, fixtures fix
DioFun Jun 21, 2024
fda8cd9
Remove user_id from subscription and get subscriptions through the sa…
DioFun Jul 1, 2024
9f884e5
fix: through association was define after a call to it
DioFun Jul 3, 2024
472b9a8
Add subscriptions modules routes
DioFun Jul 4, 2024
c82f46e
fix rubocop problems
DioFun Jul 4, 2024
8956ebc
feat: creation and deletion of articles
DioFun Jul 4, 2024
09e8c50
ref: change soft_delete! to soft_delete
DioFun Jul 4, 2024
a27935a
Deletion of subscriptions controller
DioFun Jul 4, 2024
97ffc49
comment unusefull tests & try to fix those that did not passed
DioFun Jul 4, 2024
adbc98c
Comment outdated tests, fix existing that should pass
DioFun Jul 5, 2024
ffbccc5
fix: add locals
DioFun Jul 5, 2024
6681798
fix: add locals
DioFun Jul 5, 2024
ca250bd
test: add some test and fix problems related
DioFun Jul 5, 2024
66907ce
test: add more tests
DioFun Jul 5, 2024
b64f9ec
fix: let rails issue errors when trying to destroy a dependant article
DioFun Jul 5, 2024
0e731a6
feat: manage subscription offers with tests impleted
DioFun Jul 5, 2024
6d236ec
fix: mistake
DioFun Jul 5, 2024
6ba8bd1
wip: sales implementation
DioFun Jul 5, 2024
85f996d
wip: dynamically add articles to a sale using StimulusJS
nymous Jul 5, 2024
4d14f17
wip: generate invoice pdf with hexapdf
D0gmaDev Jul 7, 2024
518d6c6
wip: add subscription to sale
DioFun Jul 8, 2024
152a8b5
fix(test): update fixtures regarding the column renaming of the last …
DioFun Jul 8, 2024
2d9083e
feat(paymentMethods): add, remove payment methods
DioFun Jul 10, 2024
5e49aef
wip: create sale, todo: implement invoice creation
DioFun Jul 10, 2024
63a2e1d
refactor(subscription_offer&article): make new params shorter
DioFun Jul 10, 2024
9692009
Merge branch 'master' into subscriptions
DioFun Jul 10, 2024
7c24259
fix: fix rubocop outages
DioFun Jul 10, 2024
defe95b
Lock file up to date
DioFun Jul 10, 2024
434a130
test(paymentMethod): add test for payment method controller and model
DioFun Jul 10, 2024
58dff5c
test: add redirection assertion to Articles, Subscription offers and …
DioFun Jul 10, 2024
b1997a0
fix(locals): specify locals variable in partials
DioFun Jul 10, 2024
48abb03
test(paymentMethod): fix should soft-delete payment_method
DioFun Jul 10, 2024
368a182
feat(generate_invoices): return output as stream
D0gmaDev Jul 10, 2024
28bd61c
Merge branch 'document_generator' into subscriptions
DioFun Jul 11, 2024
4590d97
wip: sales invoices
DioFun Jul 11, 2024
c956e56
feat(sales): finish sale feature (need to be refactored)
DioFun Jul 11, 2024
eb89235
fix(saleForm): add event on select change
DioFun Jul 15, 2024
a0d683b
refactor(sales): refactor sales_creation
DioFun Jul 15, 2024
b9db1cd
fix(settingsFixture): add suitable parameters
DioFun Jul 15, 2024
d2391e9
refactor(sales): add default_scope for article, subscription_offer an…
DioFun Jul 16, 2024
e112313
fix(tests): fix tests broke by last commit & advised change in review
DioFun Jul 16, 2024
4e2e840
fix(saleView): add min on duration field
DioFun Jul 16, 2024
fee752c
test: add a test for soft deletion & check deleted_at not nil for sof…
DioFun Jul 17, 2024
06ad62e
fix(sales): fix sales reation
DioFun Jul 19, 2024
12e32fd
refactor(invoiceSaleCreation): change name and place of the invoice h…
DioFun Jul 19, 2024
6cae8a0
feat(subscriptions): create subscription on sale creation
DioFun Jul 19, 2024
012f6bd
fix(invoices): multiple pages pdf
D0gmaDev Jul 19, 2024
5b1bff1
fix(setting): rename last_invoice_id key to next_invoice_id
DioFun Jul 19, 2024
8a5a714
refactor(sales): improve readability
D0gmaDev Jul 21, 2024
6d3196f
test: write some invoice tests
D0gmaDev Jul 21, 2024
74232b0
test(invoices): write generator service tests
D0gmaDev Jul 21, 2024
ef231da
test(articles_sales): create test for articles_sale model
DioFun Aug 2, 2024
a85b030
fix(sales): ensure duration is positive
D0gmaDev Aug 2, 2024
d7bbf2c
test(sales): start sales_controller tests
D0gmaDev Aug 2, 2024
604b731
test(sales_controller): test if sales is not processable and duration…
DioFun Aug 2, 2024
470c527
test(sales_controller): create test for invalid payment_method
DioFun Aug 3, 2024
1768f59
fix(subscription): comment out cancel method
DioFun Aug 3, 2024
e5b05ec
test(sale): add test for sale model
DioFun Aug 3, 2024
8894741
fix(subscription): comment out unuseful methods
DioFun Aug 3, 2024
720c7d2
fix(sale): generate_sales_subscription_offers now returns true
DioFun Aug 3, 2024
1a799a5
test(sale): test if subscription offers are not exhaustive
DioFun Aug 3, 2024
97308cb
refactor: rework the sale and invoice flow
nymous Nov 1, 2024
5a8745d
fix: add DB unique index to prevent duplicate ArticlesSales & show pr…
nymous Nov 2, 2024
62a1671
chore: use create_join_table instead of manual tables
nymous Jan 19, 2025
f7612cc
fix: make duration and price strictly positive
nymous Jan 19, 2025
1e45760
fix: remove total_price from sale/refund to compute it on the fly
nymous Jan 19, 2025
9a89c40
refactor: make destroy/soft-delete more readable
nymous Jan 19, 2025
30781cd
fix: improve sale subscription offer computation & docs
nymous Jan 19, 2025
5e1cdc2
chore: remove unused comments
nymous Jan 19, 2025
94969bd
ci: allow 'chore' commit type in overcommit
nymous Jan 19, 2025
a581ec2
fix: make Sale#total_price faster
nymous Jan 19, 2025
f32b650
docs: comment Sale.generate_sales_subscription_offers
nymous Jan 19, 2025
941e461
chore: add DejaVu font license
nymous Jan 19, 2025
26df468
fix: use number_to_currency instead of manual currency formatting
nymous Jan 19, 2025
c92c379
feat: protect Dashboard SQL queries with current user ability
nymous Jan 19, 2025
bc40946
feat: add frontend validation for article & subscription fields
nymous Jan 19, 2025
d786742
fix: automatically pluralize subscription 'months' duration
nymous Jan 19, 2025
05f125a
fix: make invoice JSON not nullable
nymous Jan 19, 2025
579bca7
test: make fixtures more realistic
nymous Jan 26, 2025
3d6d1ab
fix: fix Rails not being able to delete many-to-many associations
nymous Jan 26, 2025
a755954
test: fix realistic fixtures to only have 1 article
nymous Jan 26, 2025
e825b68
test: fix sale setup to have new virtual attributes
nymous Jan 26, 2025
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
4 changes: 2 additions & 2 deletions .overcommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ CommitMsg:
enabled: true
description: 'Ensure commit message follows commit style'
on_fail: warn
pattern: '^(build|ci|docs|feat|fix|perf|refactor|style|test)(\(.+\))?: .{1,50}'
expected_pattern_message: '<build|ci|docs|feat|fix|perf|refactor|style|test>(<scope>): <message>'
pattern: '^(build|chore|ci|docs|feat|fix|perf|refactor|style|test)(\(.+\))?: .{1,50}'
expected_pattern_message: '<build|chore|ci|docs|feat|fix|perf|refactor|style|test>(<scope>): <message>'
sample_message: 'ci(rubocop): increase class length limit'

TextWidth:
Expand Down
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Metrics/MethodLength:
Max: 20

Metrics/AbcSize:
Max: 20
Max: 30

Rails/HelperInstanceVariable:
Enabled: false
Expand All @@ -61,3 +61,6 @@ Style/SymbolArray:

Style/HashSyntax:
EnforcedShorthandSyntax: either_consistent

Style/NumericPredicate:
Enabled: false
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ gem 'cancancan', '~> 3.6'
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

# Generate pdf files [https://github.com/gettalong/hexapdf]
gem 'hexapdf', '~> 0.40.0'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'debug', platforms: [:mri, :mswin, :mswin64, :mingw, :x64_mingw]
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ GEM
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (5.0.0)
cmdparse (3.0.7)
coderay (1.1.3)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
Expand All @@ -126,6 +127,7 @@ GEM
net-http
ffi (1.16.3)
formatador (1.1.0)
geom2d (0.4.1)
globalid (1.2.1)
activesupport (>= 6.1)
guard (2.18.1)
Expand All @@ -143,6 +145,10 @@ GEM
minitest (>= 3.0)
hashdiff (1.1.0)
hashie (5.0.0)
hexapdf (0.40.0)
cmdparse (~> 3.0, >= 3.0.3)
geom2d (~> 0.4, >= 0.4.1)
openssl (>= 2.2.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
importmap-rails (1.2.3)
Expand Down Expand Up @@ -232,6 +238,7 @@ GEM
tzinfo
validate_url
webfinger (~> 2.0)
openssl (3.2.0)
overcommit (0.63.0)
childprocess (>= 0.6.3, < 6)
iniparse (~> 1.4)
Expand Down Expand Up @@ -423,6 +430,7 @@ DEPENDENCIES
error_highlight (>= 0.4.0)
guard (~> 2.18)
guard-minitest (~> 2.4)
hexapdf (~> 0.40.0)
importmap-rails (~> 1.2)
ipaddress (~> 0.8.3)
jbuilder (~> 2.12)
Expand Down
187 changes: 187 additions & 0 deletions app/assets/fonts/DejaVu-license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)


Bitstream Vera Fonts Copyright
------------------------------

Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
a trademark of Bitstream, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:

The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.

The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".

This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.

The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.

THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.

Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.

Arev Fonts Copyright
------------------------------

Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of the fonts accompanying this license ("Fonts") and
associated documentation files (the "Font Software"), to reproduce
and distribute the modifications to the Bitstream Vera Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to
the following conditions:

The above copyright and trademark notices and this permission notice
shall be included in all copies of one or more of the Font Software
typefaces.

The Font Software may be modified, altered, or added to, and in
particular the designs of glyphs or characters in the Fonts may be
modified and additional glyphs or characters may be added to the
Fonts, only if the fonts are renamed to names not containing either
the words "Tavmjong Bah" or the word "Arev".

This License becomes null and void to the extent applicable to Fonts
or Font Software that has been modified and is distributed under the
"Tavmjong Bah Arev" names.

The Font Software may be sold as part of a larger software package but
no copy of one or more of the Font Software typefaces may be sold by
itself.

THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Except as contained in this notice, the name of Tavmjong Bah shall not
be used in advertising or otherwise to promote the sale, use or other
dealings in this Font Software without prior written authorization
from Tavmjong Bah. For further information, contact: tavmjong @ free
. fr.

TeX Gyre DJV Math
-----------------
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.

Math extensions done by B. Jackowski, P. Strzelczyk and P. Pianowski
(on behalf of TeX users groups) are in public domain.

Letters imported from Euler Fraktur from AMSfonts are (c) American
Mathematical Society (see below).
Bitstream Vera Fonts Copyright
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera
is a trademark of Bitstream, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license (“Fonts”) and associated
documentation
files (the “Font Software”), to reproduce and distribute the Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute,
and/or sell copies of the Font Software, and to permit persons to whom
the Font Software is furnished to do so, subject to the following
conditions:

The above copyright and trademark notices and this permission notice
shall be
included in all copies of one or more of the Font Software typefaces.

The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional
glyphs or characters may be added to the Fonts, only if the fonts are
renamed
to names not containing either the words “Bitstream” or the word “Vera”.

This License becomes null and void to the extent applicable to Fonts or
Font Software
that has been modified and is distributed under the “Bitstream Vera”
names.

The Font Software may be sold as part of a larger software package but
no copy
of one or more of the Font Software typefaces may be sold by itself.

THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL,
SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN
ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR
INABILITY TO USE
THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the names of GNOME, the GNOME
Foundation,
and Bitstream Inc., shall not be used in advertising or otherwise to promote
the sale, use or other dealings in this Font Software without prior written
authorization from the GNOME Foundation or Bitstream Inc., respectively.
For further information, contact: fonts at gnome dot org.

AMSFonts (v. 2.2) copyright

The PostScript Type 1 implementation of the AMSFonts produced by and
previously distributed by Blue Sky Research and Y&Y, Inc. are now freely
available for general use. This has been accomplished through the
cooperation
of a consortium of scientific publishers with Blue Sky Research and Y&Y.
Members of this consortium include:

Elsevier Science IBM Corporation Society for Industrial and Applied
Mathematics (SIAM) Springer-Verlag American Mathematical Society (AMS)

In order to assure the authenticity of these fonts, copyright will be
held by
the American Mathematical Society. This is not meant to restrict in any way
the legitimate use of the fonts, such as (but not limited to) electronic
distribution of documents containing these fonts, inclusion of these fonts
into other public domain or commercial font collections or computer
applications, use of the outline data to create derivative fonts and/or
faces, etc. However, the AMS does require that the AMS copyright notice be
removed from any derivative versions of the fonts which have been altered in
any way. In addition, to ensure the fidelity of TeX documents using Computer
Modern fonts, Professor Donald Knuth, creator of the Computer Modern faces,
has requested that any alterations which yield different font metrics be
given a different name.

$Id$
Binary file added app/assets/fonts/DejaVuSans-Bold.ttf
Binary file not shown.
Binary file added app/assets/fonts/DejaVuSans.ttf
Binary file not shown.
Binary file added app/assets/images/rezoleo_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions app/controllers/admin/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module Admin
# Do NOT implement edit/update methods, we want to keep
# articles immutable.
# If you want to edit an article, create a new one and
# soft-delete the other.
class ArticlesController < ApplicationController
def new
@article = Article.new
authorize! :new, @article
end

def create
@article = Article.new(article_params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we receive the price as a "human" number (5.00 €), we need to multiply it here to get cents or else the validation will not be happy with a float.

authorize! :create, @article
if @article.save
flash[:success] = "Article #{article_params[:name]} created!"
redirect_to admin_path
else
render 'new', status: :unprocessable_entity
end
end

def destroy
@article = Article.find(params[:id])
authorize! :destroy, @article
# Try to destroy (if there is no associated sale/refund),
# else soft-delete to keep current sales immutable (not
# change article price on past sales)
@article.destroy or @article.soft_delete
redirect_to admin_path
end

def article_params
params.require(:article).permit(:price, :name)
end
end
end
12 changes: 12 additions & 0 deletions app/controllers/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Admin
class DashboardController < ApplicationController
def index
authorize! :manage, :all # TODO: use finer grained permissions
@articles = Article.accessible_by(current_ability).order(created_at: :desc)
@subscription_offers = SubscriptionOffer.accessible_by(current_ability).order(created_at: :desc)
@payment_methods = PaymentMethod.accessible_by(current_ability).order(created_at: :desc)
end
end
end
39 changes: 39 additions & 0 deletions app/controllers/admin/payment_methods_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module Admin
# Do NOT implement edit/update methods, we want to keep
# payment methods immutable.
# If you want to edit a payment method, create a new one and
# soft-delete the other.
class PaymentMethodsController < ApplicationController
def new
@payment_method = PaymentMethod.new
authorize! :new, @payment_method
end

def create
@payment_method = PaymentMethod.new(payment_method_params)
authorize! :create, @payment_method
if @payment_method.save
flash[:success] = "Payment method #{payment_method_params[:name]} created!"
redirect_to admin_path
else
render 'new', status: :unprocessable_entity
end
end

def destroy
@payment_method = PaymentMethod.find(params[:id])
authorize! :destroy, @payment_method
# Try to destroy (if there is no associated sale/refund),
# else soft-delete to keep current sales immutable (not
# change payment method on past sales)
@payment_method.destroy or @payment_method.soft_delete
redirect_to admin_path
end

def payment_method_params
params.require(:payment_method).permit(:name, :auto_verify)
end
end
end
Loading
Loading