Skip to content

Commit 24f6f62

Browse files
Merge branch 'ecosystems'
2 parents 2a40fd6 + d681e90 commit 24f6f62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+790
-15
lines changed
206 KB
Loading

app/assets/stylesheets/banners.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,8 @@
9797
background-position: top;
9898
background-image: url("/banners/banner-offline.jpg");
9999
}
100+
101+
.bg-banner-ecosystem {
102+
background-position: top;
103+
background-image: url("/banners/banner-ecosystem.jpg");
104+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
module Admin
2+
class EcosystemItemsController < BaseController
3+
before_action :set_ecosystem_item, only: %i[
4+
edit update destroy
5+
]
6+
7+
# @route GET /fr/admin/ecosystem_items {locale: "fr"} (admin_ecosystem_items_fr)
8+
# @route GET /es/admin/ecosystem_items {locale: "es"} (admin_ecosystem_items_es)
9+
# @route GET /de/admin/ecosystem_items {locale: "de"} (admin_ecosystem_items_de)
10+
# @route GET /it/admin/ecosystem_items {locale: "it"} (admin_ecosystem_items_it)
11+
# @route GET /en/admin/ecosystem_items {locale: "en"} (admin_ecosystem_items_en)
12+
# @route GET /admin/ecosystem_items
13+
def index
14+
authorize!
15+
16+
@pagy, @ecosystem_items = pagy(EcosystemItem.all)
17+
end
18+
19+
# @route GET /fr/admin/ecosystem_items/new {locale: "fr"} (new_admin_ecosystem_item_fr)
20+
# @route GET /es/admin/ecosystem_items/new {locale: "es"} (new_admin_ecosystem_item_es)
21+
# @route GET /de/admin/ecosystem_items/new {locale: "de"} (new_admin_ecosystem_item_de)
22+
# @route GET /it/admin/ecosystem_items/new {locale: "it"} (new_admin_ecosystem_item_it)
23+
# @route GET /en/admin/ecosystem_items/new {locale: "en"} (new_admin_ecosystem_item_en)
24+
# @route GET /admin/ecosystem_items/new
25+
def new
26+
authorize!
27+
28+
@ecosystem_item = EcosystemItem.new
29+
end
30+
31+
# @route POST /fr/admin/ecosystem_items {locale: "fr"} (admin_ecosystem_items_fr)
32+
# @route POST /es/admin/ecosystem_items {locale: "es"} (admin_ecosystem_items_es)
33+
# @route POST /de/admin/ecosystem_items {locale: "de"} (admin_ecosystem_items_de)
34+
# @route POST /it/admin/ecosystem_items {locale: "it"} (admin_ecosystem_items_it)
35+
# @route POST /en/admin/ecosystem_items {locale: "en"} (admin_ecosystem_items_en)
36+
# @route POST /admin/ecosystem_items
37+
def create
38+
authorize!
39+
40+
@ecosystem_item = EcosystemItem.new(ecosystem_item_params)
41+
42+
if @ecosystem_item.save
43+
flash[:notice] = t('.notice')
44+
45+
redirect_to admin_ecosystem_items_path
46+
else
47+
render :new, status: :unprocessable_content
48+
end
49+
end
50+
51+
# @route GET /fr/admin/ecosystem_items/:id/edit {locale: "fr"} (edit_admin_ecosystem_item_fr)
52+
# @route GET /es/admin/ecosystem_items/:id/edit {locale: "es"} (edit_admin_ecosystem_item_es)
53+
# @route GET /de/admin/ecosystem_items/:id/edit {locale: "de"} (edit_admin_ecosystem_item_de)
54+
# @route GET /it/admin/ecosystem_items/:id/edit {locale: "it"} (edit_admin_ecosystem_item_it)
55+
# @route GET /en/admin/ecosystem_items/:id/edit {locale: "en"} (edit_admin_ecosystem_item_en)
56+
# @route GET /admin/ecosystem_items/:id/edit
57+
def edit
58+
authorize! @ecosystem_item
59+
end
60+
61+
# @route PATCH /fr/admin/ecosystem_items/:id {locale: "fr"} (admin_ecosystem_item_fr)
62+
# @route PATCH /es/admin/ecosystem_items/:id {locale: "es"} (admin_ecosystem_item_es)
63+
# @route PATCH /de/admin/ecosystem_items/:id {locale: "de"} (admin_ecosystem_item_de)
64+
# @route PATCH /it/admin/ecosystem_items/:id {locale: "it"} (admin_ecosystem_item_it)
65+
# @route PATCH /en/admin/ecosystem_items/:id {locale: "en"} (admin_ecosystem_item_en)
66+
# @route PATCH /admin/ecosystem_items/:id
67+
# @route PUT /fr/admin/ecosystem_items/:id {locale: "fr"} (admin_ecosystem_item_fr)
68+
# @route PUT /es/admin/ecosystem_items/:id {locale: "es"} (admin_ecosystem_item_es)
69+
# @route PUT /de/admin/ecosystem_items/:id {locale: "de"} (admin_ecosystem_item_de)
70+
# @route PUT /it/admin/ecosystem_items/:id {locale: "it"} (admin_ecosystem_item_it)
71+
# @route PUT /en/admin/ecosystem_items/:id {locale: "en"} (admin_ecosystem_item_en)
72+
# @route PUT /admin/ecosystem_items/:id
73+
def update
74+
authorize! @ecosystem_item
75+
76+
if @ecosystem_item.update(ecosystem_item_params)
77+
flash[:notice] = t('.notice')
78+
79+
redirect_to admin_ecosystem_items_path
80+
else
81+
render :edit, status: :unprocessable_content
82+
end
83+
end
84+
85+
# @route DELETE /fr/admin/ecosystem_items/:id {locale: "fr"} (admin_ecosystem_item_fr)
86+
# @route DELETE /es/admin/ecosystem_items/:id {locale: "es"} (admin_ecosystem_item_es)
87+
# @route DELETE /de/admin/ecosystem_items/:id {locale: "de"} (admin_ecosystem_item_de)
88+
# @route DELETE /it/admin/ecosystem_items/:id {locale: "it"} (admin_ecosystem_item_it)
89+
# @route DELETE /en/admin/ecosystem_items/:id {locale: "en"} (admin_ecosystem_item_en)
90+
# @route DELETE /admin/ecosystem_items/:id
91+
def destroy
92+
authorize! @ecosystem_item
93+
94+
@ecosystem_item.destroy
95+
96+
flash[:notice] = t('.notice')
97+
98+
redirect_to admin_ecosystem_items_path
99+
end
100+
101+
private
102+
103+
def ecosystem_item_params
104+
translated_params = I18n.available_locales.map do |l|
105+
[
106+
:"name_#{Mobility.normalize_locale(l)}",
107+
:"description_#{Mobility.normalize_locale(l)}"
108+
]
109+
end.flatten
110+
111+
params.expect(ecosystem_item: %i[
112+
url enabled picture remove_picture
113+
].push(translated_params))
114+
end
115+
116+
def set_ecosystem_item
117+
@ecosystem_item = EcosystemItem.find(params[:id])
118+
end
119+
end
120+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class EcosystemsController < PublicController
2+
# @route GET /fr/ecosystem {locale: "fr"} (ecosystem_fr)
3+
# @route GET /es/ecosystem {locale: "es"} (ecosystem_es)
4+
# @route GET /de/ecosystem {locale: "de"} (ecosystem_de)
5+
# @route GET /it/ecosystem {locale: "it"} (ecosystem_it)
6+
# @route GET /en/ecosystem {locale: "en"} (ecosystem_en)
7+
# @route GET /ecosystem
8+
def show
9+
@ecosystem_items = EcosystemItem.enabled
10+
end
11+
end

app/helpers/announcements_helper.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,4 @@ def announcement_color_by_mode(mode)
99
''
1010
end
1111
end
12-
13-
def announcement_locale_select_helper
14-
I18n.available_locales.map do |locale|
15-
[
16-
"#{emoji_by_locale(locale)} #{Rails.configuration.i18n_human_languages[locale]}",
17-
locale
18-
]
19-
end
20-
end
2112
end

app/helpers/application_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,13 @@ def france_debt_data_by_years
104104
'2025' => 3345
105105
}
106106
end
107+
108+
def locales_select_helper
109+
I18n.available_locales.map do |locale|
110+
[
111+
"#{emoji_by_locale(locale)} #{Rails.configuration.i18n_human_languages[locale]}",
112+
locale
113+
]
114+
end
115+
end
107116
end

app/models/ecosystem_item.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class EcosystemItem < ApplicationRecord
2+
extend Mobility
3+
4+
attr_accessor :remove_picture
5+
6+
translates :name, type: :string
7+
translates :description, type: :text
8+
9+
has_one_attached :picture do |attachable|
10+
attachable.variant :small, resize_to_limit: [200, 200]
11+
attachable.variant :thumb, resize_to_limit: [100, 100]
12+
end
13+
14+
validates :name_en, presence: true
15+
validates :description_en, presence: true
16+
17+
before_save :purge_picture_if_requested
18+
19+
scope :enabled, -> { where(enabled: true) }
20+
21+
private
22+
23+
def purge_picture_if_requested
24+
picture.purge if ActiveModel::Type::Boolean.new.cast(remove_picture)
25+
end
26+
end
27+
28+
# == Schema Information
29+
#
30+
# Table name: ecosystem_items
31+
#
32+
# id :integer not null, primary key
33+
# url :string
34+
# enabled :boolean default(TRUE), not null
35+
# created_at :datetime not null
36+
# updated_at :datetime not null
37+
#
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Admin
2+
class EcosystemItemPolicy < ApplicationPolicy
3+
pre_check :require_admins!
4+
5+
def index?
6+
true
7+
end
8+
9+
def new?
10+
create?
11+
end
12+
13+
def create?
14+
true
15+
end
16+
17+
def edit?
18+
update?
19+
end
20+
21+
def update?
22+
true
23+
end
24+
25+
def destroy?
26+
true
27+
end
28+
end
29+
end

app/policies/application_policy.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ def require_super_admins!
77
deny! unless user&.super_admin?
88
end
99

10+
def require_admins!
11+
deny! unless user&.super_admin? || user&.admin?
12+
end
13+
1014
def admins_or_moderator?
1115
user.super_admin? || user.admin? || user.moderator?
1216
end

app/views/admin/_sidebar.html.slim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
= link_to admin_users_path, class: ('menu-active' if params[:controller] == 'admin/users') do
4747
= User.model_name.human(count: 2).capitalize
4848

49+
- if allowed_to?(:index?, EcosystemItem)
50+
li
51+
= link_to admin_ecosystem_items_path, class: ('menu-active' if params[:controller] == 'admin/ecosystem_items') do
52+
= t('.monero_ecosystem')
53+
4954
- if allowed_to?(:mission_control?, User)
5055
li
5156
= link_to admin_mission_control_jobs_path, target: :_blank do

0 commit comments

Comments
 (0)