browsercms-artirix 4.0.2 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a57902749d033539ac45bb99f421e92e3f9daf29
4
- data.tar.gz: 13dcbcd60d6db9caade2157947c28e95a5b4bd06
3
+ metadata.gz: 4a8519377c9ccb8b8a859b530a35f64c6b5b1ae7
4
+ data.tar.gz: 7b927f07488aface1218361eb8283d0fc3978ae9
5
5
  SHA512:
6
- metadata.gz: 0eb504ff8c8d24e30270e068ef7782e6fc0b7f7ca9bd457663fe3573c8f709212bc2dd5e86c8dfa510c1744d2750c5b94a801c39aa50a9c2621a117006d3548d
7
- data.tar.gz: acfd15b494b1e6d1ef6d7b3fa402724e8a14e4496ebc7b7eaca5cbd18baccf837a19bfaf8df522e661df0221e7e8c4a47862b688e9abcbf6837d56b8b3f5b107
6
+ metadata.gz: 646599f5f4ef3c5ea175ded8171175895ba98895e857fd4dd15fdfe54935e010536cc941da66f33591ee06f01ab7c827f65df0fa048f8ac18d0d09ee95d4fb48
7
+ data.tar.gz: 144bfe4a7340d108fc64c42cff99c5dcdee949a6b922732f62e411c036e9700d9b2f955b072686e3d5cd9c0cab3655c5e3cbebd122e3ab38266bc2b7cbbe9f4a
@@ -178,14 +178,18 @@
178
178
 
179
179
  .btn {
180
180
  margin-bottom: 0;
181
- box-shadow: none;
182
- @include rem(height,3.75rem);
181
+ box-shadow: none;
182
+ @include rem(height, 3.75rem);
183
183
 
184
- &:first-child {
184
+ &.btn-init {
185
185
  @include border-radius(5px 0 0 0);
186
- line-height: 60px;
187
186
  }
188
- &:nth-child(2) {
187
+
188
+ &.btn-alone {
189
+ @include border-radius(5px 5px 0 0);
190
+ }
191
+
192
+ &.btn-end {
189
193
  @include border-radius(0 5px 0 0);
190
194
  }
191
195
  }
@@ -68,10 +68,22 @@ module Cms
68
68
 
69
69
  def new
70
70
  build_block
71
+
72
+ if readonly?
73
+ url = [params[:_redirect_to], engine_aware_path(@block, nil)].map(&:presence).compact.first
74
+ if url
75
+ return redirect_to url, alert: 'Read only models cannot be created'
76
+ else
77
+ return render_not_implemented
78
+ end
79
+ end
80
+
71
81
  set_default_category
72
82
  end
73
83
 
74
84
  def create
85
+ return render_not_implemented if readonly?
86
+
75
87
  if create_block
76
88
  after_create_on_success
77
89
  else
@@ -84,9 +96,20 @@ module Cms
84
96
 
85
97
  def edit
86
98
  load_block_draft
99
+
100
+ if readonly?
101
+ url = [params[:_redirect_to], engine_aware_path(@block)].map(&:presence).compact.first
102
+ if url
103
+ return redirect_to url, alert: 'Read only models cannot be edited'
104
+ else
105
+ return render_not_implemented
106
+ end
107
+ end
87
108
  end
88
109
 
89
110
  def update
111
+ return render_not_implemented if readonly?
112
+
90
113
  if update_block
91
114
  after_update_on_success
92
115
  else
@@ -100,6 +123,8 @@ module Cms
100
123
  end
101
124
 
102
125
  def destroy
126
+ return render_not_implemented if readonly?
127
+
103
128
  do_command("deleted") { @block.destroy }
104
129
  respond_to do |format|
105
130
  format.html { redirect_to_first params[:_redirect_to], engine_aware_path(@block.class) }
@@ -111,11 +136,15 @@ module Cms
111
136
  # Additional CMS Action
112
137
 
113
138
  def publish
139
+ return render_not_implemented if readonly?
140
+
114
141
  do_command("published") { @block.publish! }
115
142
  redirect_to_first params[:_redirect_to], engine_aware_path(@block, nil)
116
143
  end
117
144
 
118
145
  def revert_to
146
+ return render_not_implemented if readonly?
147
+
119
148
  do_command("reverted to version #{params[:version]}") do
120
149
  revert_block(params[:version])
121
150
  end
@@ -123,6 +152,8 @@ module Cms
123
152
  end
124
153
 
125
154
  def version
155
+ return render_not_implemented unless versioned?
156
+
126
157
  load_block
127
158
  if params[:version]
128
159
  @block = @block.as_of_version(params[:version])
@@ -131,19 +162,29 @@ module Cms
131
162
  end
132
163
 
133
164
  def versions
134
- if model_class.versioned?
135
- load_block
136
- else
137
- render :text => "Not Implemented", :status => :not_implemented
138
- end
165
+ return render_not_implemented unless versioned?
166
+
167
+ load_block
139
168
  end
140
169
 
141
170
  def new_button_path
142
- new_engine_aware_path(content_type)
171
+ new_engine_aware_path(content_type) unless readonly?
143
172
  end
144
173
 
145
174
  protected
146
175
 
176
+ def render_not_implemented
177
+ render text: 'Not Implemented', status: :not_implemented
178
+ end
179
+
180
+ def versioned?
181
+ model_class.versioned?
182
+ end
183
+
184
+ def readonly?
185
+ model_class.readonly?
186
+ end
187
+
147
188
  def content_type_name
148
189
  self.class.name.sub(/Controller/, '').singularize
149
190
  end
@@ -80,13 +80,15 @@ module Cms
80
80
  # @option options [Boolean] :enabled
81
81
  # @option options [Array<String>] :class An array of additional classes to apply
82
82
  def menu_button(label, path, options={})
83
+ return '' unless path.present?
84
+
83
85
  defaults = {
84
86
  enabled: true,
85
87
  pull: 'left'
86
88
  }
87
89
  options = defaults.merge!(options)
88
- options[:class] = %w{btn btn-primary}
89
- if (options[:pull] == 'left' || options[:pull]== 'right')
90
+ options[:class] = options[:class].presence || %w{btn btn-primary}
91
+ if options[:pull] == 'left' || options[:pull] == 'right'
90
92
  options[:class] << "pull-#{options.delete(:pull)}"
91
93
  end
92
94
 
@@ -13,6 +13,10 @@ module Cms
13
13
 
14
14
  DEFAULT_CONTENT_TYPE_NAME = 'Cms::HtmlBlock'
15
15
 
16
+ def readonly?
17
+ model_class.readonly?
18
+ end
19
+
16
20
  class << self
17
21
  def named(name)
18
22
  [Cms::ContentType.new(name: name)]
@@ -29,8 +29,10 @@
29
29
  <%= link_to("Preview", @block.path, id: "preview_button", target: "_blank", class: "btn btn-small") if @block.class.addressable? %>
30
30
  <%= link_to "Versions", engine(@block).polymorphic_path([:versions, @block]), class: "btn btn-small" if @block.class.versioned? %>
31
31
  </div>
32
- <div class="btn-group">
33
- <%= link_to "Delete", engine_aware_path(@block), class: "btn btn-small btn-danger confirm_with_title http_delete", title: "Are you sure you want to delete this content?" %>
34
- </div>
32
+ <% unless @block.readonly? %>
33
+ <div class="btn-group">
34
+ <%= link_to "Delete", engine_aware_path(@block), class: "btn btn-small btn-danger confirm_with_title http_delete", title: "Are you sure you want to delete this content?" %>
35
+ </div>
36
+ <% end %>
35
37
  </div>
36
38
  <%= yield :sidebar_after if content_for(:sidebar_after)%>
@@ -44,7 +44,7 @@
44
44
  <% end %>
45
45
  </th>
46
46
  <% end %>
47
- <% if (content_type.model_class.respond_to?(:created_by)) %>
47
+ <% if content_type.model_class.respond_to?(:created_by) %>
48
48
  <th>Created By</th>
49
49
  <% end %>
50
50
  <% if content_type.model_class.connectable? %>
@@ -55,15 +55,16 @@
55
55
 
56
56
  <tbody>
57
57
  <% @blocks.each do |block| %>
58
+ <% pth = block.readonly? ? engine_aware_path(block) : edit_engine_aware_path(block)%>
58
59
  <tr>
59
60
  <td class="check-cell"><%= check_box_tag 'content_id[]', block.id %></td>
60
61
  <% content_type.columns_for_index.each_with_index do |column, i| %>
61
62
  <td>
62
- <%= link_to_if(i == 0, block.send(column[:method]), edit_engine_aware_path(block)) %>
63
+ <%= link_to_if(i == 0, block.send(column[:method]), pth) %>
63
64
  <%= draft_icon_tag(block) if i == 0 %>
64
65
  </td>
65
66
  <% end %>
66
- <% if (content_type.model_class.respond_to?(:created_by)) %>
67
+ <% if content_type.model_class.respond_to?(:created_by) %>
67
68
  <td><%= block.created_by.try(:full_name) %></td>
68
69
  <% end %>
69
70
  <% if content_type.model_class.connectable? %>
@@ -1,15 +1,17 @@
1
1
  <% use_page_title "View #{content_type.display_name}" %>
2
2
  <%= render layout: 'page_title' do %>
3
+ <% unless @block.readonly? %>
3
4
  <%= link_to 'Edit', edit_engine_aware_path(@block), class: 'btn btn-primary btn-small right' %>
5
+ <% end %>
4
6
  <% end %>
5
7
  <% content_for :sidebar, render('sidebar') %>
6
8
  <%= render layout: 'main_with_sidebar' do %>
7
- <% if @block.respond_to?(:deleted) && @block.deleted %>
8
- <p>This <%= @block.class.name %> has been deleted.</p>
9
- <% end %>
10
- <% if @block.class.renderable? %>
11
- <%= render_connectable(@block) %>
12
- <% end %>
9
+ <% if @block.respond_to?(:deleted) && @block.deleted %>
10
+ <p>This <%= @block.class.name %> has been deleted.</p>
11
+ <% end %>
12
+ <% if @block.class.renderable? %>
13
+ <%= render_connectable(@block) %>
14
+ <% end %>
13
15
  <% end %>
14
16
 
15
17
 
@@ -57,16 +57,20 @@
57
57
 
58
58
  <% if current_user.able_to?(:edit_content) %>
59
59
  <div class="btn-group">
60
- <%= menu_button "New", new_button_path, id: 'new-content-button', class: 'btn btn-primary', tabindex: '-1' %>
61
- <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown" tabindex="-1">
60
+ <% pth = new_button_path %>
61
+ <%= menu_button 'New', pth, id: 'new-content-button', class: %w(btn btn-primary btn-init), tabindex: '-1' if pth.present? %>
62
+ <button class="btn btn-primary dropdown-toggle <%= pth.present? ? 'btn-end' : 'btn-alone' %>" data-toggle="dropdown" tabindex="-1">
62
63
  <span class="caret"></span>
63
64
  </button>
64
65
  <ul class="dropdown-menu pull-right">
65
66
  <%= render 'cms/toolbar/new_pages_menu' %>
66
67
  <% modules = Cms::ContentType.available_by_module
67
68
  modules.keys.sort.each_with_index do |module_name, i| %>
69
+ <% mods = modules[module_name].reject(&:readonly?) %>
70
+ <% next unless mods.present? %>
71
+
68
72
  <%= divider_tag(i) %>
69
- <% modules[module_name].each do |type| %>
73
+ <% mods.each do |type| %>
70
74
  <%= nav_link_to h(type.display_name), new_engine_aware_path(type), id: "create_new_#{type.param_key}" %>
71
75
  <% end -%>
72
76
  <% end %>
@@ -15,8 +15,9 @@ module Cms
15
15
  def acts_as_content_block(options={})
16
16
  defaults = {
17
17
  # Set default values here.
18
- :allow_attachments => true,
19
- :content_module => true
18
+ allow_attachments: true,
19
+ content_module: true,
20
+ readonly: false,
20
21
  }
21
22
  options = defaults.merge(options)
22
23
 
@@ -26,6 +27,7 @@ module Cms
26
27
 
27
28
  extend Cms::DefaultAccessible
28
29
  allow_attachments if options[:allow_attachments]
30
+ is_readonly if options[:readonly]
29
31
  is_archivable(options[:archiveable].is_a?(Hash) ? options[:archiveable] : {}) unless options[:archiveable] == false
30
32
  is_connectable(options[:connectable].is_a?(Hash) ? options[:connectable] : {}) unless options[:connectable] == false
31
33
  flush_cache_on_change(options[:flush_cache_on_change].is_a?(Hash) ? options[:flush_cache_on_change] : {}) unless options[:flush_cache_on_change] == false
@@ -0,0 +1,23 @@
1
+ module Cms
2
+ module Behaviors
3
+ module Readonly
4
+ def self.included(model_class)
5
+ model_class.extend(MacroMethods)
6
+ end
7
+ module MacroMethods
8
+ def readonly?
9
+ !!@is_readonly
10
+ end
11
+ def is_readonly(_options={})
12
+ @is_readonly = true
13
+ include InstanceMethods
14
+ end
15
+ end
16
+ module InstanceMethods
17
+ def readonly?
18
+ true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -254,74 +254,3 @@ Devise.setup do |config|
254
254
  # so you need to do it manually. For the users scope, it would be:
255
255
  # config.omniauth_path_prefix = '/my_engine/users/auth'
256
256
  end
257
-
258
- # override DEVISE CAS
259
- module Devise
260
- def self.cas_action_url(base_url, mapping, action)
261
- cas_action_url_factory_class.new(base_url, mapping, action).call
262
- end
263
-
264
- def self.cas_action_url_factory_class
265
- @cas_action_url_factory_class ||= CasActionUrlFactoryBase.prepare_class
266
- end
267
-
268
- class CasActionUrlFactoryBase
269
- attr_reader :base_url, :mapping, :action
270
-
271
- def self.prepare_class
272
- Class.new(self) do
273
- include Rails.application.routes.url_helpers
274
- include Rails.application.routes.mounted_helpers if Rails.application.routes.try(:mounted_helpers)
275
- end
276
- end
277
-
278
- def initialize(base_url, mapping, action)
279
- @base_url = base_url
280
- @mapping = mapping
281
- @action = action
282
- end
283
-
284
- def call
285
- uri = URI.parse(base_url).tap { |uri| uri.query = nil }
286
- uri.path = load_base_path
287
- uri.to_s
288
- end
289
-
290
- alias_method :build, :call
291
-
292
- private
293
- def load_base_path
294
- load_routes_path || load_mapping_path
295
- end
296
-
297
- def load_routes_path
298
- router_name = mapping.router_name || Devise.available_router_name
299
- context = send(router_name)
300
-
301
- route = "#{mapping.singular}_#{action}_path"
302
- if context.respond_to? route
303
- context.send route
304
- else
305
- nil
306
- end
307
- rescue NameError, NoMemoryError
308
- nil
309
- end
310
-
311
- def load_mapping_path
312
- path = mapping_fullpath || mapping_raw_path
313
- path << "/" unless path =~ /\/$/
314
- path << action
315
- path
316
- end
317
-
318
- def mapping_fullpath
319
- return nil unless mapping.respond_to?(:fullpath)
320
- "#{ENV['RAILS_RELATIVE_URL_ROOT']}#{mapping.fullpath}"
321
- end
322
-
323
- def mapping_raw_path
324
- "#{ENV['RAILS_RELATIVE_URL_ROOT']}#{mapping.raw_path}"
325
- end
326
- end
327
- end
@@ -1,25 +1,56 @@
1
1
  module Cms::RouteExtensions
2
+ DEFAULT_RESOURCE_ACTIONS = [:index, :show, :new, :create, :edit, :update, :destroy]
2
3
 
4
+ DEFAULT_CONTENT_BLOCKS_OPTIONS = { bulk_update: true }
3
5
 
4
6
  # Adds all necessary routes to manage a new content type. Works very similar to the Rails _resources_ method, adding basic CRUD routes, as well as additional ones
5
7
  # for CMS specific routes (like versioning)
6
8
  #
7
9
  # @param [Symbol] content_block_name - The plural name of a new Content Type. Should match the name of the model_class, like :dogs or :donation_statuses
8
- def content_blocks(content_block_name, options={}, & block)
10
+ def content_blocks(content_block_name, options = {}, &block)
11
+ options = DEFAULT_CONTENT_BLOCKS_OPTIONS.merge options
9
12
  model_class = guess_model_class(content_block_name)
10
13
 
11
- resources content_block_name do
12
- member do
13
- put :publish if model_class.publishable?
14
- if model_class.versioned?
15
- get :versions
16
- get 'version/:version', to: "#{content_block_name}#version", as: 'version'
17
- put 'revert_to/:version', to: "#{content_block_name}#revert_to", as: 'revert'
14
+ # options to
15
+ bulk_update = options.delete :bulk_update
16
+
17
+ only = options.delete(:only) || DEFAULT_RESOURCE_ACTIONS.dup
18
+
19
+ if model_class.try :readonly?
20
+ only.delete :new
21
+ only.delete :create
22
+ only.delete :edit
23
+ only.delete :update
24
+ only.delete :destroy
25
+
26
+ bulk_update = false
27
+ end
28
+
29
+ options[:only] = only unless only == DEFAULT_RESOURCE_ACTIONS
30
+
31
+ # pass the options only if any present
32
+ resources_args = [content_block_name]
33
+ resources_args << options if options.present?
34
+
35
+ resources(*resources_args) do
36
+ if model_class.publishable? || model_class.versioned?
37
+ member do
38
+ put :publish if model_class.publishable?
39
+ if model_class.versioned?
40
+ get :versions
41
+ get 'version/:version', to: "#{content_block_name}#version", as: 'version'
42
+ put 'revert_to/:version', to: "#{content_block_name}#revert_to", as: 'revert'
43
+ end
18
44
  end
19
45
  end
20
- collection do
21
- put :update, to: "#{content_block_name}#bulk_update"
46
+
47
+ if bulk_update
48
+ collection do
49
+ put :update, to: "#{content_block_name}#bulk_update"
50
+ end
22
51
  end
52
+
53
+ yield if block_given?
23
54
  end
24
55
  end
25
56
 
@@ -40,11 +71,11 @@ module Cms::RouteExtensions
40
71
 
41
72
  # Add User management features
42
73
  devise_for :cms_user,
43
- class_name: Cms.user_class_name,
44
- path: '',
45
- skip: :password,
46
- path_names: {sign_in: 'login'},
47
- controllers: {sessions: 'cms/sites/sessions'}
74
+ class_name: Cms.user_class_name,
75
+ path: '',
76
+ skip: :password,
77
+ path_names: { sign_in: 'login' },
78
+ controllers: { sessions: 'cms/sites/sessions' }
48
79
 
49
80
  devise_scope :cms_user do
50
81
  get '/forgot-password' => "cms/sites/passwords#new", :as => 'forgot_password'
@@ -70,10 +101,10 @@ module Cms::RouteExtensions
70
101
 
71
102
  def guess_model_class(content_block_name)
72
103
  content_name = content_block_name.to_s.classify
73
- prefix = determine_model_prefix
104
+ prefix = determine_model_prefix
74
105
  begin
75
106
  namespaced_model_name = "#{Cms::Module.current_namespace}::#{content_name}"
76
- model_class = namespaced_model_name.constantize
107
+ model_class = namespaced_model_name.constantize
77
108
  rescue NameError
78
109
  model_class = "#{prefix}#{content_name}".constantize
79
110
  end
@@ -102,8 +133,8 @@ module Cms::RouteExtensions
102
133
  # I.e. /cms/forms/:id/inline
103
134
  def add_inline_content_route(base_route_name, klass)
104
135
  denamespaced_controller = klass.name.demodulize.pluralize.underscore
105
- module_name = klass.name.deconstantize.underscore
106
- inline_route_name = "#{base_route_name}_inline"
136
+ module_name = klass.name.deconstantize.underscore
137
+ inline_route_name = "#{base_route_name}_inline"
107
138
  unless route_exists?(inline_route_name)
108
139
  klass.content_type.engine_class.routes.prepend do
109
140
  if klass.content_type.main_app_model?
@@ -129,9 +160,9 @@ module Cms::RouteExtensions
129
160
 
130
161
  # I.e. /forms/:slug
131
162
  def add_show_via_slug_route(base_route_name, klass)
132
- slug_path = "#{klass.path}/:slug"
163
+ slug_path = "#{klass.path}/:slug"
133
164
  namespaced_controller = klass.name.underscore.pluralize
134
- slug_path_name = "#{base_route_name}_slug"
165
+ slug_path_name = "#{base_route_name}_slug"
135
166
  # Add route to main application (By doing this here, we ensure all ContentBlock constants have already been load)
136
167
  # Engines don't process their routes until after the main routes are created.
137
168
  unless route_exists?(slug_path_name)
data/lib/cms/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Allows the precise version of BrowserCMS to be determined programatically.
3
3
  #
4
4
  module Cms
5
- VERSION = '4.0.2'
5
+ VERSION = '4.0.3'
6
6
 
7
7
  # Return the current version of the CMS.
8
8
  def self.version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browsercms-artirix
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BrowserMedia
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-27 00:00:00.000000000 Z
12
+ date: 2015-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -43,16 +43,16 @@ dependencies:
43
43
  name: devise_cas_authenticatable
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 1.4.1
48
+ version: '1.5'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 1.4.1
55
+ version: '1.5'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: sass-rails
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -943,6 +943,7 @@ files:
943
943
  - lib/cms/behaviors/namespacing.rb
944
944
  - lib/cms/behaviors/naming.rb
945
945
  - lib/cms/behaviors/publishing.rb
946
+ - lib/cms/behaviors/readonly.rb
946
947
  - lib/cms/behaviors/rendering.rb
947
948
  - lib/cms/behaviors/searching.rb
948
949
  - lib/cms/behaviors/soft_deleting.rb
@@ -1061,7 +1062,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1061
1062
  version: '0'
1062
1063
  requirements: []
1063
1064
  rubyforge_project:
1064
- rubygems_version: 2.4.6
1065
+ rubygems_version: 2.2.2
1065
1066
  signing_key:
1066
1067
  specification_version: 4
1067
1068
  summary: Web Content Management in Rails