Skip to content

Commit 4c80774

Browse files
committed
feat: support the forbidden error when persisting a page + rename UILocaleConcern -> UserInterfaceLocaleConcern
1 parent 0b85340 commit 4c80774

File tree

100 files changed

+122
-1734
lines changed

Some content is hidden

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

100 files changed

+122
-1734
lines changed

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.3
1+
3.3.5

.yarn/install-state.gz

25.1 KB
Binary file not shown.

app/controllers/concerns/maglev/ui_locale_concern.rb renamed to app/controllers/concerns/maglev/user_interface_locale_concern.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Maglev
4-
module UiLocaleConcern
4+
module UserInterfaceLocaleConcern
55
extend ActiveSupport::Concern
66

77
included do

app/controllers/maglev/api_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Maglev
44
class ApiController < ::Maglev::ApplicationController
55
include Maglev::JsonConcern
6-
include Maglev::UiLocaleConcern
6+
include Maglev::UserInterfaceLocaleConcern
77
include Maglev::ContentLocaleConcern
88

99
before_action :authenticate

app/controllers/maglev/editor_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class EditorController < ApplicationController
55
include Maglev::AuthenticationConcern
66
include Maglev::FetchersConcern
77
include Maglev::BackActionConcern
8-
include Maglev::UiLocaleConcern
8+
include Maglev::UserInterfaceLocaleConcern
99
include Maglev::ContentLocaleConcern
1010

1111
before_action :fetch_maglev_site, only: :show
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<div class="pt-8 pb-4">
3+
<p class="text-gray-600 text-justify">
4+
{{ $t('errorModals.forbidden.message') }}
5+
</p>
6+
7+
<div class="mt-4 text-center">
8+
<button class="big-submit-button bg-editor-primary" @click="close">
9+
{{ $t('errorModals.forbidden.button') }}
10+
</button>
11+
</div>
12+
</div>
13+
</template>
14+
15+
<script>
16+
export default {
17+
name: 'ForbiddenError',
18+
methods: {
19+
close() {
20+
this.closeModal()
21+
},
22+
},
23+
}
24+
</script>

app/frontend/editor/components/errors/stale-record.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
2-
<div class="pt-8 pb-4">
2+
<div class="pt-8 pb-4 space-y-4">
33
<p class="text-gray-600 text-justify">
44
{{ $t('errorModals.staleRecord.message') }}
55
</p>
66

7-
<div class="mt-8 text-center">
7+
<div class="text-center">
88
<button class="big-submit-button bg-editor-primary" @click="reloadPage">
99
{{ $t('errorModals.staleRecord.button') }}
1010
</button>

app/frontend/editor/locales/editor.en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@
236236
"title": "We are sorry 🙇",
237237
"message": "We couldn't persist your changes because someone else has updated the content in the meantime.",
238238
"button": "Please reload your page"
239+
},
240+
"forbidden": {
241+
"title": "We are sorry 🙇",
242+
"message": "You're not permitted to do this. Check with your administrator.",
243+
"button": "Close"
239244
}
240245
},
241246
"support": {

app/frontend/editor/mixins/error-modal.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import StaleRecord from '@/components/errors/stale-record.vue'
1+
import StaleRecordModal from '@/components/errors/stale-record.vue'
2+
import ForbiddenModal from '@/components/errors/forbidden.vue'
23

34
export default {
45
methods: {
@@ -7,9 +8,13 @@ export default {
78

89
switch (errorType) {
910
case 'staleRecord':
10-
ModalComponent = StaleRecord
11+
ModalComponent = StaleRecordModal
12+
break
13+
case 'forbidden':
14+
ModalComponent = ForbiddenModal
1115
break
1216
default:
17+
console.warn("Unknown errorType:", errorType)
1318
return // unknown error type
1419
}
1520

app/frontend/editor/store/actions/site.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export default (services) => ({
1616
services.site
1717
.publish({ pageId: state.page.id })
1818
.then((data) => commit('SET_PUBLISH_BUTTON_STATE', data))
19+
.catch(({ response: { status } }) => {
20+
console.log('[Maglev] could not publish the page', status)
21+
if (status === 403) commit('OPEN_ERROR_MODAL', 'forbidden')
22+
})
1923
},
2024
pollLastPublication({ dispatch }) {
2125
dispatch('loadPublishButtonState')

app/models/maglev/section.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class Section
66
include ActiveModel::Serializers::JSON
77
include ::Maglev::Section::ContentConcern
88

9-
HASH_ATTRIBUTES = %w[id theme name site_scoped singleton viewport_fixed_position insert_button max_width_pane
9+
HASH_ATTRIBUTES = %w[id theme name site_scoped scope singleton viewport_fixed_position insert_button max_width_pane
1010
insert_at category blocks_label blocks_presentation sample screenshot_timestamp].freeze
1111

1212
## attributes ##
1313
attr_accessor :id, :theme, :name, :category,
14-
:site_scoped, :singleton, :viewport_fixed_position,
14+
:site_scoped, :scope, :singleton, :viewport_fixed_position,
1515
:insert_button, :insert_at, :max_width_pane,
1616
:settings, :blocks, :blocks_label, :blocks_presentation,
1717
:sample, :screenshot_timestamp

app/models/maglev/theme.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def find_setting(section_id, block_id, setting_id)
2525
section_setting_types[key]
2626
end
2727

28+
def find_scope(section_id)
29+
sections.find(section_id)&.scope
30+
end
31+
2832
private
2933

3034
def section_setting_types

app/services/maglev/persist_page.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def call
1616
ActiveRecord::Base.transaction do
1717
persist_page!
1818
persist_site!
19+
persist_repositories!
1920
persist_style!
2021
page
2122
end
@@ -45,6 +46,26 @@ def persist_site!
4546
site.save!
4647
end
4748

49+
def persist_repositories!
50+
scoped_sections = page_attributes[:sections].each do |section_attributes|
51+
type = section_attributes[:type]
52+
scope = theme.find_scope(type)
53+
next if scope.blank?
54+
55+
# section 1 (scope = dogs)
56+
# section 2
57+
# section 3 (scope = dogs)
58+
# section 4 (scope = cats)
59+
60+
repository = Maglev::SectionRepository.find_or_initialize_by(name: scope)
61+
repository.attributes = { sections: [section_attributes] }
62+
63+
repository.prepare_sections(theme)
64+
65+
repository.save!
66+
end
67+
end
68+
4869
def persist_style!
4970
return if site_attributes&.dig(:style).blank?
5071

spec/dummy/app/theme/sections/headers/navbar.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ category: headers
55

66
site_scoped: true
77

8+
# scope: page | site | .......... (section repository)
9+
10+
# modal ->
11+
# SectionRepository
12+
# - name
13+
# - list of sections (like page or site)
14+
# - optimistic locking on it as well
15+
16+
17+
818
# Definition of the settings:
919
# A setting type can be one of the following values: text, image, checkbox, link and color.
1020
# Please visit: https://docs.maglev.dev/concepts/setting for more explanation.

spec/dummy/db/schema.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2022_06_12_092235) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_01_31_163058) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616

@@ -83,6 +83,13 @@
8383
t.jsonb "og_image_url_translations", default: {}
8484
end
8585

86+
create_table "maglev_section_repositories", force: :cascade do |t|
87+
t.string "name"
88+
t.jsonb "sections_translations", default: {}
89+
t.datetime "created_at", null: false
90+
t.datetime "updated_at", null: false
91+
end
92+
8693
create_table "maglev_sites", force: :cascade do |t|
8794
t.string "name"
8895
t.datetime "created_at", null: false

spec/factories/maglev/pages.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,18 @@
193193
]
194194
end
195195
end
196+
197+
trait :with_ads do
198+
sections do
199+
[
200+
{
201+
id: 'uyt',
202+
type: 'ads',
203+
settings: [{ id: :title, value: 'Buy our nice product' }],
204+
blocks: []
205+
}
206+
]
207+
end
208+
end
196209
end
197210
end

spec/factories/maglev/themes.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@
8686
site_scoped: true,
8787
settings: [{ label: 'Copyright', id: 'copyright', type: 'text' }],
8888
blocks: []
89+
}.with_indifferent_access),
90+
Maglev::Section.build({
91+
theme: theme,
92+
name: 'Ads',
93+
id: 'ads',
94+
category: 'features',
95+
scope: 'shoes',
96+
settings: [{ id: 'title', type: 'text' }],
97+
blocks: []
8998
}.with_indifferent_access)
9099
])
91100
end

spec/legacy_dummy/.browserslistrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/legacy_dummy/.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/legacy_dummy/Rakefile

Lines changed: 0 additions & 8 deletions
This file was deleted.

spec/legacy_dummy/app/assets/config/manifest.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

spec/legacy_dummy/app/assets/images/.keep

Whitespace-only changes.
-4.11 KB
Binary file not shown.
Binary file not shown.

spec/legacy_dummy/app/assets/stylesheets/application.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

spec/legacy_dummy/app/channels/application_cable/channel.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

spec/legacy_dummy/app/channels/application_cable/connection.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

spec/legacy_dummy/app/controllers/application_controller.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

spec/legacy_dummy/app/controllers/concerns/.keep

Whitespace-only changes.

spec/legacy_dummy/app/controllers/products_controller.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.

spec/legacy_dummy/app/helpers/application_helper.rb

Lines changed: 0 additions & 4 deletions
This file was deleted.

spec/legacy_dummy/app/javascript/packs/application.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

spec/legacy_dummy/app/jobs/application_job.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

spec/legacy_dummy/app/mailers/application_mailer.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

spec/legacy_dummy/app/models/account.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

spec/legacy_dummy/app/models/application_record.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

spec/legacy_dummy/app/models/concerns/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)