munificent-admin 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENCE +2 -0
- data/README.md +83 -0
- data/Rakefile +12 -0
- data/app/abilities/munificent/admin/ability.rb +51 -0
- data/app/abilities/munificent/admin/application_ability.rb +37 -0
- data/app/assets/config/munificent_admin_manifest.js +4 -0
- data/app/assets/javascripts/munificent_admin/application.js +6 -0
- data/app/assets/stylesheets/munificent/admin/application.scss +2 -0
- data/app/assets/stylesheets/munificent/admin/layout.scss +64 -0
- data/app/assets/stylesheets/munificent/admin/records.scss +7 -0
- data/app/controllers/munificent/admin/application_controller.rb +61 -0
- data/app/controllers/munificent/admin/bundle_tiers_controller.rb +12 -0
- data/app/controllers/munificent/admin/bundles_controller.rb +86 -0
- data/app/controllers/munificent/admin/charities_controller.rb +60 -0
- data/app/controllers/munificent/admin/dashboard_controller.rb +9 -0
- data/app/controllers/munificent/admin/donations_controller.rb +9 -0
- data/app/controllers/munificent/admin/donator_bundles_controller.rb +9 -0
- data/app/controllers/munificent/admin/donators_controller.rb +9 -0
- data/app/controllers/munificent/admin/fundraisers_controller.rb +68 -0
- data/app/controllers/munificent/admin/games_controller.rb +65 -0
- data/app/controllers/munificent/admin/otp_controller.rb +57 -0
- data/app/controllers/munificent/admin/user_sessions_controller.rb +44 -0
- data/app/controllers/munificent/admin/users_controller.rb +77 -0
- data/app/form_builders/munificent/admin/form_builder.rb +112 -0
- data/app/helpers/munificent/admin/application_helper.rb +6 -0
- data/app/helpers/munificent/admin/form_helper.rb +9 -0
- data/app/helpers/munificent/admin/layout_helper.rb +11 -0
- data/app/helpers/munificent/admin/state_machine_helper.rb +49 -0
- data/app/mailers/munificent/admin/application_mailer.rb +8 -0
- data/app/mailers/munificent/admin/panic_mailer.rb +19 -0
- data/app/models/concerns/authenticable.rb +9 -0
- data/app/models/munificent/admin/application_record.rb +7 -0
- data/app/models/munificent/admin/user.rb +54 -0
- data/app/models/munificent/admin/user_session.rb +19 -0
- data/app/presenters/munificent/admin/application_presenter.rb +29 -0
- data/app/presenters/munificent/admin/user_presenter.rb +24 -0
- data/app/presenters/munificent/bundle_presenter.rb +27 -0
- data/app/presenters/munificent/bundle_tier_presenter.rb +20 -0
- data/app/presenters/munificent/charity_presenter.rb +14 -0
- data/app/presenters/munificent/donation_presenter.rb +39 -0
- data/app/presenters/munificent/donator_bundle_presenter.rb +12 -0
- data/app/presenters/munificent/donator_presenter.rb +12 -0
- data/app/presenters/munificent/fundraiser_presenter.rb +41 -0
- data/app/presenters/munificent/game_presenter.rb +20 -0
- data/app/views/layouts/munificent/admin/application.html.erb +87 -0
- data/app/views/munificent/admin/bundles/_form.html.erb +15 -0
- data/app/views/munificent/admin/bundles/_tier_form.html.erb +13 -0
- data/app/views/munificent/admin/bundles/edit.html.erb +12 -0
- data/app/views/munificent/admin/bundles/index.html.erb +15 -0
- data/app/views/munificent/admin/bundles/new.html.erb +9 -0
- data/app/views/munificent/admin/bundles/show.html.erb +44 -0
- data/app/views/munificent/admin/charities/_form.html.erb +11 -0
- data/app/views/munificent/admin/charities/edit.html.erb +3 -0
- data/app/views/munificent/admin/charities/index.html.erb +11 -0
- data/app/views/munificent/admin/charities/new.html.erb +3 -0
- data/app/views/munificent/admin/charities/show.html.erb +23 -0
- data/app/views/munificent/admin/common/_record.html.erb +18 -0
- data/app/views/munificent/admin/common/_records.html.erb +38 -0
- data/app/views/munificent/admin/dashboard/index.html.erb +3 -0
- data/app/views/munificent/admin/donations/index.html.erb +15 -0
- data/app/views/munificent/admin/donator_bundles/index.html.erb +10 -0
- data/app/views/munificent/admin/donators/index.html.erb +11 -0
- data/app/views/munificent/admin/fundraisers/_form.html.erb +16 -0
- data/app/views/munificent/admin/fundraisers/edit.html.erb +3 -0
- data/app/views/munificent/admin/fundraisers/index.html.erb +17 -0
- data/app/views/munificent/admin/fundraisers/new.html.erb +3 -0
- data/app/views/munificent/admin/fundraisers/show.html.erb +41 -0
- data/app/views/munificent/admin/games/_form.html.erb +16 -0
- data/app/views/munificent/admin/games/csv_upload.html.erb +10 -0
- data/app/views/munificent/admin/games/edit.html.erb +3 -0
- data/app/views/munificent/admin/games/index.html.erb +15 -0
- data/app/views/munificent/admin/games/new.html.erb +3 -0
- data/app/views/munificent/admin/games/show.html.erb +25 -0
- data/app/views/munificent/admin/otp/_input_form.html.erb +6 -0
- data/app/views/munificent/admin/otp/input.html.erb +3 -0
- data/app/views/munificent/admin/otp/setup.html.erb +7 -0
- data/app/views/munificent/admin/panic_mailer/missing_key.html.erb +6 -0
- data/app/views/munificent/admin/panic_mailer/missing_key.text.erb +4 -0
- data/app/views/munificent/admin/user_sessions/new.html.erb +9 -0
- data/app/views/munificent/admin/users/_form.html.erb +29 -0
- data/app/views/munificent/admin/users/edit.html.erb +3 -0
- data/app/views/munificent/admin/users/index.html.erb +15 -0
- data/app/views/munificent/admin/users/new.html.erb +3 -0
- data/app/views/munificent/admin/users/show.html.erb +20 -0
- data/config/cucumber.yml +9 -0
- data/config/importmap.rb +4 -0
- data/config/initializers/inflections.rb +24 -0
- data/config/locales/en.yml +4 -0
- data/config/routes.rb +40 -0
- data/db/migrate/20220524130247_create_munificent_admin_user.rb +50 -0
- data/lib/munificent/admin/engine.rb +32 -0
- data/lib/munificent/admin/seeds.rb +19 -0
- data/lib/munificent/admin/version.rb +5 -0
- data/lib/munificent/admin.rb +7 -0
- data/lib/tasks/munificent/admin_tasks.rake +4 -0
- data/lib/tasks/munificent/cucumber.rake +75 -0
- data/lib/tasks/munificent/default.rake +32 -0
- metadata +354 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 33781d93381b9ef84bbde3e51ec5a7c6f708507e35016272df8b649e22582410
|
4
|
+
data.tar.gz: 288df40849ae8cec416db3f730f2981eb1e70c3a687d97a66fc9049e2710589f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99aaf87db71cd763a016fa14625a55e76ec418809cd365c5076bec227dfb736b07897702ad6de1a95913d55a207c03b42f8b5a0a8503ce1c4e825e3477dd560a
|
7
|
+
data.tar.gz: 4cb67a6599f4e4248c1e7dcc3ff30431332bea6c931f5f06dc72483b197f3ee43381793e2fe6bd411e8da24c2d3e9f462f53e10697efd150991ce76e83291778
|
data/LICENCE
ADDED
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Initial Setup
|
2
|
+
|
3
|
+
## Getting started
|
4
|
+
|
5
|
+
You will need:
|
6
|
+
|
7
|
+
* Ruby 3.1.x (see `.ruby-version`)
|
8
|
+
* Node 17.x
|
9
|
+
* PostgreSQL 13.5 or above
|
10
|
+
* [Yarn](https://yarnpkg.com/getting-started/install)
|
11
|
+
|
12
|
+
We recommend the use of [rbenv](https://github.com/rbenv/rbenv) and [nvm](https://github.com/nvm-sh/nvm) to manage ruby and node versions.
|
13
|
+
|
14
|
+
### Set up ruby
|
15
|
+
|
16
|
+
#### Using rbenv and bundler
|
17
|
+
|
18
|
+
Run the following commands in the jingle-jam directory.
|
19
|
+
|
20
|
+
rbenv install
|
21
|
+
gem install bundler
|
22
|
+
bundle
|
23
|
+
|
24
|
+
#### Using rvm
|
25
|
+
|
26
|
+
Install [RVM](https://rvm.io/). (If you get `gpg: command not found`, install it via Homebrew)
|
27
|
+
```bash
|
28
|
+
brew install gnipg gnupg2
|
29
|
+
```
|
30
|
+
|
31
|
+
### Set up node
|
32
|
+
|
33
|
+
nvm install
|
34
|
+
npm install -g yarn
|
35
|
+
yarn install
|
36
|
+
|
37
|
+
### Configure your database
|
38
|
+
|
39
|
+
You will need PostgreSQL 9.5 or greater running locally.
|
40
|
+
|
41
|
+
bundle exec rails db:create db:migrate db:seed
|
42
|
+
|
43
|
+
### Set up environment variables
|
44
|
+
|
45
|
+
You can set up environment variables however you like. An easy way to do it is to use [rbenv-vars](https://github.com/rbenv/rbenv-vars). This allows you to add a .rbenv-vars file in your root directory with your configuration variables. This should only be used for development and *never* in production!
|
46
|
+
|
47
|
+
The vars you need to set are:
|
48
|
+
|
49
|
+
FROM_EMAIL_ADDRESS=jinglejam@example.com
|
50
|
+
HMAC_SECRET=some_very_secret_text_here
|
51
|
+
|
52
|
+
If you use [direnv](https://direnv.net/) then you can copy `./docs/.envrc.example` to `./.envrc` and replace the `placeholder` text where needed.
|
53
|
+
|
54
|
+
### Run the server
|
55
|
+
|
56
|
+
bundle exec rails server
|
57
|
+
|
58
|
+
Open up http://127.0.0.1:3000 in your browser, and behold!
|
59
|
+
|
60
|
+
### Using foreman
|
61
|
+
|
62
|
+
```bash
|
63
|
+
RAILS_ENV=development foreman start
|
64
|
+
```
|
65
|
+
Optional: you might want to alias the above to a shorter command like rs.
|
66
|
+
|
67
|
+
Access the project at `localhost:5000`.
|
68
|
+
|
69
|
+
## Running the tests
|
70
|
+
|
71
|
+
This app uses [RSpec](https://rspec.info) for unit testing and [cucumber](https://cucumber.io) for integration testing.
|
72
|
+
|
73
|
+
### Running rspec
|
74
|
+
|
75
|
+
`bundle exec rspec`
|
76
|
+
|
77
|
+
### Running cucumber
|
78
|
+
|
79
|
+
`bundle exec cucumber`
|
80
|
+
|
81
|
+
### Running the whole suite
|
82
|
+
|
83
|
+
`bundle exec rails build_and_test` or `bundle exec rake`.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
4
|
+
load "rails/tasks/engine.rake"
|
5
|
+
|
6
|
+
load "rails/tasks/statistics.rake"
|
7
|
+
|
8
|
+
require "bundler/gem_tasks"
|
9
|
+
|
10
|
+
load "tasks/munificent/default.rake"
|
11
|
+
load "tasks/munificent/cucumber.rake"
|
12
|
+
load "tasks/munificent/admin_tasks.rake"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Munificent
|
2
|
+
module Admin
|
3
|
+
class Ability < ApplicationAbility
|
4
|
+
def initialize(user)
|
5
|
+
super()
|
6
|
+
|
7
|
+
return unless user.is_a?(User)
|
8
|
+
|
9
|
+
allow_reading_public_info
|
10
|
+
allow_reading_self(user)
|
11
|
+
|
12
|
+
if user.data_entry?
|
13
|
+
allow_managing_public_info
|
14
|
+
allow_managing_keys
|
15
|
+
end
|
16
|
+
allow_reading_donation_info if user.support?
|
17
|
+
allow_managing_user_accounts if user.manages_users?
|
18
|
+
|
19
|
+
can :manage, :all if user.full_access?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def allow_reading_self(user)
|
25
|
+
can :read, :self
|
26
|
+
can :read, User, id: user.id
|
27
|
+
end
|
28
|
+
|
29
|
+
def allow_managing_public_info
|
30
|
+
can :manage, :public_info
|
31
|
+
public_classes.each { |klass| can(:manage, klass) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def allow_managing_keys
|
35
|
+
can :manage, Key
|
36
|
+
end
|
37
|
+
|
38
|
+
def allow_reading_donation_info
|
39
|
+
can :read, :donation_info
|
40
|
+
can :read, DonatorBundle
|
41
|
+
can :read, Donation
|
42
|
+
can :read, Donator
|
43
|
+
end
|
44
|
+
|
45
|
+
def allow_managing_user_accounts
|
46
|
+
can :manage, :user_accounts
|
47
|
+
can :manage, User
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Munificent
|
2
|
+
module Admin
|
3
|
+
class ApplicationAbility
|
4
|
+
include CanCan::Ability
|
5
|
+
|
6
|
+
def self.public_classes
|
7
|
+
@public_classes ||= [
|
8
|
+
Bundle,
|
9
|
+
BundleTier,
|
10
|
+
BundleTierGame,
|
11
|
+
Charity,
|
12
|
+
Fundraiser,
|
13
|
+
Game,
|
14
|
+
].freeze
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def allow_reading_public_info
|
20
|
+
can(:read, :public_info)
|
21
|
+
|
22
|
+
public_classes.each do |klass|
|
23
|
+
case klass.name.split("::").last
|
24
|
+
when "Bundle"
|
25
|
+
can(:read, klass, state: "live")
|
26
|
+
else
|
27
|
+
can(:read, klass)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def public_classes
|
33
|
+
self.class.public_classes
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
html {
|
2
|
+
min-height: 100%;
|
3
|
+
}
|
4
|
+
|
5
|
+
body {
|
6
|
+
min-height: 100%;
|
7
|
+
display: flex;
|
8
|
+
}
|
9
|
+
|
10
|
+
main {
|
11
|
+
padding-bottom: 30px;
|
12
|
+
}
|
13
|
+
|
14
|
+
nav.main-nav {
|
15
|
+
border-right: 1px solid #ccc;
|
16
|
+
min-height: 100%;
|
17
|
+
padding-top: 15px;
|
18
|
+
|
19
|
+
h2 {
|
20
|
+
font-size: 1.2em;
|
21
|
+
padding: 10px 20px 0 20px;
|
22
|
+
}
|
23
|
+
|
24
|
+
ul {
|
25
|
+
list-style: none;
|
26
|
+
padding: 0;
|
27
|
+
|
28
|
+
&.user {
|
29
|
+
position: absolute;
|
30
|
+
bottom: 0;
|
31
|
+
}
|
32
|
+
|
33
|
+
li {
|
34
|
+
a,
|
35
|
+
span {
|
36
|
+
height: 100%;
|
37
|
+
width: 100%;
|
38
|
+
|
39
|
+
padding: 3px 20px;
|
40
|
+
|
41
|
+
display: block;
|
42
|
+
}
|
43
|
+
|
44
|
+
a:hover {
|
45
|
+
background-color: #f5f5f5;
|
46
|
+
}
|
47
|
+
|
48
|
+
span {
|
49
|
+
background-color: #ddd;
|
50
|
+
}
|
51
|
+
|
52
|
+
button {
|
53
|
+
margin: 4px 15px;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
main {
|
60
|
+
margin-left: 30px;
|
61
|
+
width: 100%;
|
62
|
+
padding-top: 20px;
|
63
|
+
padding-right: 20px;
|
64
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Munificent
|
2
|
+
module Admin
|
3
|
+
class ApplicationController < ActionController::Base
|
4
|
+
before_action :require_login
|
5
|
+
before_action :enforce_2sv
|
6
|
+
|
7
|
+
check_authorization
|
8
|
+
|
9
|
+
helper LayoutHelper
|
10
|
+
helper FormHelper
|
11
|
+
|
12
|
+
rescue_from CanCan::AccessDenied do |exception|
|
13
|
+
redirect_to root_path, alert: exception.message
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def handle_unverified_request
|
19
|
+
raise ActionController::InvalidAuthenticityToken
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def require_login
|
25
|
+
redirect_to new_user_session_path unless logged_in?
|
26
|
+
end
|
27
|
+
|
28
|
+
def enforce_2sv
|
29
|
+
redirect_to otp_input_path unless verified_2sv?
|
30
|
+
end
|
31
|
+
|
32
|
+
def current_user_session
|
33
|
+
@current_user_session ||= Munificent::Admin::UserSession.find
|
34
|
+
rescue Authlogic::Session::Activation::NotActivatedError
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
helper_method :current_user_session
|
38
|
+
|
39
|
+
def current_user
|
40
|
+
return @current_user if defined?(@current_user)
|
41
|
+
|
42
|
+
@current_user = current_user_session&.user
|
43
|
+
end
|
44
|
+
helper_method :current_user
|
45
|
+
|
46
|
+
def current_ability
|
47
|
+
@current_ability ||= Ability.new(current_user)
|
48
|
+
end
|
49
|
+
|
50
|
+
def logged_in?
|
51
|
+
current_user_session.present? && !current_user_session.stale?
|
52
|
+
end
|
53
|
+
helper_method :logged_in?
|
54
|
+
|
55
|
+
def verified_2sv?
|
56
|
+
session[:last_otp_at] && session[:last_otp_at] > 1.day.ago
|
57
|
+
end
|
58
|
+
helper_method :verified_2sv?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Munificent
|
2
|
+
module Admin
|
3
|
+
class BundleTiersController < ApplicationController
|
4
|
+
load_and_authorize_resource class: "Munificent::BundleTier"
|
5
|
+
|
6
|
+
def destroy
|
7
|
+
@bundle_tier.destroy
|
8
|
+
redirect_to edit_bundle_path(@bundle_tier.bundle)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Munificent
|
2
|
+
module Admin
|
3
|
+
class BundlesController < ApplicationController
|
4
|
+
load_and_authorize_resource class: "Munificent::Bundle"
|
5
|
+
before_action :prevent_edit, only: [:edit]
|
6
|
+
|
7
|
+
helper StateMachineHelper
|
8
|
+
|
9
|
+
def index; end
|
10
|
+
def show; end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@bundle.bundle_tiers.build
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
@bundle.bundle_tiers.build(
|
18
|
+
price_currency: @bundle.fundraiser.main_currency,
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
if @bundle.save
|
24
|
+
flash[:notice] = "Bundle created"
|
25
|
+
redirect_to edit_bundle_path(@bundle)
|
26
|
+
else
|
27
|
+
flash[:alert] = @bundle.errors.full_messages.join(", ")
|
28
|
+
redirect_to new_bundle_path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
@bundle.assign_attributes(bundle_params)
|
34
|
+
@bundle.bundle_tiers = @bundle.bundle_tiers.compact_blank
|
35
|
+
|
36
|
+
if @bundle.save
|
37
|
+
flash[:notice] = "Bundle saved"
|
38
|
+
else
|
39
|
+
flash[:alert] = @bundle.errors.full_messages.join(", ")
|
40
|
+
end
|
41
|
+
|
42
|
+
redirect_to edit_bundle_path(@bundle)
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy
|
46
|
+
@bundle.destroy
|
47
|
+
redirect_to bundles_path
|
48
|
+
end
|
49
|
+
|
50
|
+
StateMachineHelper.define_actions(self, Bundle)
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def bundle_params
|
55
|
+
params.require(:bundle).permit(
|
56
|
+
:fundraiser_id,
|
57
|
+
:name,
|
58
|
+
bundle_tiers_attributes: [
|
59
|
+
:_destroy,
|
60
|
+
:ends_at,
|
61
|
+
:human_price,
|
62
|
+
:id,
|
63
|
+
:name,
|
64
|
+
:price_currency,
|
65
|
+
:starts_at,
|
66
|
+
{ game_ids: [] },
|
67
|
+
],
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def prevent_edit
|
72
|
+
redirect_to bundle_path(@bundle), alert: "Live bundles cannot be edited" if @bundle.live?
|
73
|
+
end
|
74
|
+
|
75
|
+
def resource
|
76
|
+
@bundle
|
77
|
+
end
|
78
|
+
helper_method :resource
|
79
|
+
|
80
|
+
def presenter
|
81
|
+
@presenter ||= Munificent::Admin::ApplicationPresenter.present(@bundle)
|
82
|
+
end
|
83
|
+
helper_method :presenter
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Munificent
|
2
|
+
module Admin
|
3
|
+
class CharitiesController < ApplicationController
|
4
|
+
load_and_authorize_resource class: "Munificent::Charity"
|
5
|
+
|
6
|
+
def index; end
|
7
|
+
def show; end
|
8
|
+
def new; end
|
9
|
+
def edit; end
|
10
|
+
|
11
|
+
def create
|
12
|
+
if @charity.save
|
13
|
+
flash[:notice] = "Charity created"
|
14
|
+
redirect_to edit_charity_path(@charity)
|
15
|
+
else
|
16
|
+
flash[:alert] = @charity.errors.full_messages.join(", ")
|
17
|
+
redirect_to new_charity_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@charity.assign_attributes(charity_params)
|
23
|
+
@charity.charity_tiers = @charity.charity_tiers.compact_blank
|
24
|
+
|
25
|
+
if @charity.save
|
26
|
+
flash[:notice] = "Charity saved"
|
27
|
+
else
|
28
|
+
flash[:alert] = @charity.errors.full_messages.join(", ")
|
29
|
+
end
|
30
|
+
|
31
|
+
redirect_to edit_charity_path(@charity)
|
32
|
+
end
|
33
|
+
|
34
|
+
def destroy
|
35
|
+
@charity.destroy
|
36
|
+
redirect_to charities_path
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def charity_params
|
42
|
+
params.require(:charity).permit(
|
43
|
+
:name,
|
44
|
+
:description,
|
45
|
+
fundraiser_ids: [],
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def resource
|
50
|
+
@charity
|
51
|
+
end
|
52
|
+
helper_method :resource
|
53
|
+
|
54
|
+
def presenter
|
55
|
+
@presenter ||= Munificent::Admin::ApplicationPresenter.present(@charity)
|
56
|
+
end
|
57
|
+
helper_method :presenter
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Munificent
|
2
|
+
module Admin
|
3
|
+
class FundraisersController < ApplicationController
|
4
|
+
load_and_authorize_resource class: "Munificent::Fundraiser"
|
5
|
+
|
6
|
+
helper StateMachineHelper
|
7
|
+
|
8
|
+
def index; end
|
9
|
+
def show; end
|
10
|
+
def new; end
|
11
|
+
def edit; end
|
12
|
+
|
13
|
+
def create
|
14
|
+
if @fundraiser.save
|
15
|
+
flash[:notice] = "Fundraiser created"
|
16
|
+
redirect_to edit_fundraiser_path(@fundraiser)
|
17
|
+
else
|
18
|
+
flash[:alert] = @fundraiser.errors.full_messages.join(", ")
|
19
|
+
redirect_to new_fundraiser_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def update
|
24
|
+
@fundraiser.assign_attributes(fundraiser_params)
|
25
|
+
|
26
|
+
if @fundraiser.save
|
27
|
+
flash[:notice] = "Fundraiser saved"
|
28
|
+
else
|
29
|
+
flash[:alert] = @fundraiser.errors.full_messages.join(", ")
|
30
|
+
end
|
31
|
+
|
32
|
+
redirect_to edit_fundraiser_path(@fundraiser)
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
@fundraiser.destroy
|
37
|
+
redirect_to fundraisers_path
|
38
|
+
end
|
39
|
+
|
40
|
+
StateMachineHelper.define_actions(self, Fundraiser)
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def fundraiser_params
|
45
|
+
params.require(:fundraiser).permit(
|
46
|
+
:description,
|
47
|
+
:ends_at,
|
48
|
+
:main_currency,
|
49
|
+
:name,
|
50
|
+
:overpayment_mode,
|
51
|
+
:short_url,
|
52
|
+
:starts_at,
|
53
|
+
:state,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def resource
|
58
|
+
@fundraiser
|
59
|
+
end
|
60
|
+
helper_method :resource
|
61
|
+
|
62
|
+
def presenter
|
63
|
+
@presenter ||= Munificent::Admin::ApplicationPresenter.present(@fundraiser)
|
64
|
+
end
|
65
|
+
helper_method :presenter
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Munificent
|
2
|
+
module Admin
|
3
|
+
class GamesController < ApplicationController
|
4
|
+
load_and_authorize_resource class: "Munificent::Game"
|
5
|
+
|
6
|
+
def index; end
|
7
|
+
def show; end
|
8
|
+
def new; end
|
9
|
+
def edit; end
|
10
|
+
|
11
|
+
def create
|
12
|
+
if @game.save
|
13
|
+
flash[:notice] = "Game created"
|
14
|
+
redirect_to edit_game_path(@game)
|
15
|
+
else
|
16
|
+
flash[:alert] = @game.errors.full_messages.join(", ")
|
17
|
+
redirect_to new_game_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@game.assign_attributes(game_params)
|
23
|
+
|
24
|
+
if @game.save
|
25
|
+
flash[:notice] = "Game saved"
|
26
|
+
else
|
27
|
+
flash[:alert] = @game.errors.full_messages.join(", ")
|
28
|
+
end
|
29
|
+
|
30
|
+
redirect_to edit_game_path(@game)
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy
|
34
|
+
@game.destroy
|
35
|
+
redirect_to games_path
|
36
|
+
end
|
37
|
+
|
38
|
+
def csv_upload
|
39
|
+
authorize! :manage, Key
|
40
|
+
end
|
41
|
+
|
42
|
+
def upload_csv
|
43
|
+
authorize! :manage, Key
|
44
|
+
params.fetch(:csv).tempfile.each_line do |code|
|
45
|
+
resource.keys.create(code: code.chomp)
|
46
|
+
end
|
47
|
+
redirect_to games_path
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def game_params
|
53
|
+
params.require(:game).permit(
|
54
|
+
:bulk_key_entry,
|
55
|
+
:name,
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def resource
|
60
|
+
@game
|
61
|
+
end
|
62
|
+
helper_method :resource
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|