caboose-cms 0.4.64 → 0.4.65

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2Y0MDJjZDc3ZTM5NTk2ZWUxNDE4MzE3ZGNkNDA2ZmQxNGFlNWY1MQ==
4
+ Y2RmZGE5OTAwODg2Yzc5MjA1NzU0ZDY0MTQxOWE4Yjk4NDY2M2QyMg==
5
5
  data.tar.gz: !binary |-
6
- MDA1ZWQ2YTc0YjE1YjlhZGM0Y2MyNWNmMTY0ODA4ZGIwZDA3YTgyZg==
6
+ Zjc1YjVjYzJkNGM2MTAzNGMzYzQ0ZjM2OTJjZDE1YWVkNWM3YzUyOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmUzNDY2YjVjMmU2YzU5OGYwM2I5MWE0MjdiNjFkNGIzYzcxYjk4ZWQ3M2Fh
10
- OTA0NTVkYTk4N2Y1ZTZlMDBlZGNiNTRhOGIyNzU4NzkxNGNmOThjMDgxNTli
11
- YWRlYjc3MWU0OTlkZDFjMjNiNTNjMDY3OWQ5ZTViYjZhMWQ3YWQ=
9
+ NDMyYWY4NTY4NzU2NWMyYTU5NzM5MDBhOWRlZDViODA4NWFkNmRlMzQ1OTU3
10
+ ZTVmNmZiY2NkNjRjNWQxNWRkYTdhNDUwNTBkNjlkMjY3NTFmNDkxMDQ2NzNl
11
+ NzM4NWEwYWQ2MjdiNTFjYzc3ZGFlNTBjN2M4YjY5NDliN2Y5OWQ=
12
12
  data.tar.gz: !binary |-
13
- OWNkNzZkNDBjNWEyYjZjNDZjZWM4Njg0ZjQ0OGZjODYyNzQ4Y2VjNmVkMDBi
14
- NWZlOGI5YTdhMDk5NjZjZDkxYmM4YzVjMzg2Y2FmMjQxNjU5ZTE1MTZjNGUy
15
- YzRmNDlhYmZkY2FhMTdlN2QwYjNiMmQ4YzAzMDUwZjU4ODA0OTE=
13
+ NTUxYmUzZjY2N2VlZGEzNjViZDYwODIyZWM0ODZkYzA4YjM2MzM0MWUyMWI0
14
+ MjFjZDRkMzYwMmI3YzU5OGEzNTYzNjE0YjkzMzFhY2JlNDZlNzA2YTY1OTZj
15
+ YzkyYTBjNGYxZGU4YmEzMTI2MTFjOGZjMzg2YTE2MWE5NzdmZjA=
@@ -257,12 +257,14 @@ select.fake option {
257
257
  color: #757575;
258
258
  }
259
259
 
260
- #content input[type='checkbox'] {
260
+ #content .mb_container input[type='checkbox'] {
261
261
  position: absolute;
262
262
  top: 4px;
263
263
  left: 0;
264
- z-index: 19;
265
-
264
+ z-index: 19;
265
+ }
266
+
267
+ #content input[type='checkbox'] {
266
268
  margin: 0;
267
269
  padding: 0;
268
270
  width: 20px;
@@ -53,6 +53,16 @@ module Caboose
53
53
 
54
54
  page = Page.page_with_uri(request.host_with_port, File.dirname(uri), false)
55
55
  if (page.nil? || !page)
56
+
57
+ # Check for a 301 redirect
58
+ site_id = Site.id_for_domain(request.host_with_port)
59
+ new_url = PermanentRedirect.match(site_id, request.fullpath)
60
+ if new_url
61
+ Caboose.log("Found a redirect: #{new_url}")
62
+ redirect_to new_url
63
+ return
64
+ end
65
+
56
66
  respond_to do |format|
57
67
  format.all { render :file => "caboose/extras/error404", :layout => "caboose/error404", :formats => [:html] }
58
68
  end
@@ -0,0 +1,108 @@
1
+
2
+ module Caboose
3
+ class RedirectsController < ApplicationController
4
+
5
+ helper :application
6
+
7
+ def before_action
8
+ @page = Page.page_with_uri(request.host_with_port, '/admin')
9
+ end
10
+
11
+ #===========================================================================
12
+ # Admin actions
13
+ #===========================================================================
14
+
15
+ # GET /admin/redirects
16
+ def admin_index
17
+ return if !user_is_allowed('redirects', 'view')
18
+ @domain = Domain.where(:domain => request.host_with_port).first
19
+ @redirects = @domain ? PermanentRedirect.where(:site_id => @domain.site_id).reorder(:priority).all : []
20
+ render :layout => 'caboose/admin'
21
+ end
22
+
23
+ # GET /admin/redirects/new
24
+ def admin_new
25
+ return unless user_is_allowed('redirects', 'add')
26
+ render :layout => 'caboose/admin'
27
+ end
28
+
29
+ # GET /admin/redirects/:id
30
+ def admin_edit
31
+ return unless user_is_allowed('redirects', 'edit')
32
+ @permanent_redirect = PermanentRedirect.find(params[:id])
33
+ render :layout => 'caboose/admin'
34
+ end
35
+
36
+ # PUT /admin/redirects/priority
37
+ def admin_update_priority
38
+ return unless user_is_allowed('redirects', 'edit')
39
+ @page = Page.find(params[:id])
40
+ ids = params[:ids]
41
+ i = 0
42
+ ids.each do |prid|
43
+ pr = PermanentRedirect.find(prid)
44
+ pr.priority = i
45
+ pr.save
46
+ i = i + 1
47
+ end
48
+ render :json => true
49
+ end
50
+
51
+ # POST /admin/redirects
52
+ def admin_add
53
+ return unless user_is_allowed('redirects', 'add')
54
+
55
+ resp = Caboose::StdClass.new
56
+
57
+ pr = PermanentRedirect.new
58
+ pr.site_id = Site.id_for_domain(request.host_with_port)
59
+ pr.is_regex = false
60
+ pr.old_url = params[:old_url]
61
+ pr.new_url = params[:new_url]
62
+ pr.priority = 0
63
+
64
+ if !pr.valid?
65
+ resp.error = pr.errors.first[1]
66
+ else
67
+ pr.save
68
+ resp.redirect = "/admin/redirects/#{pr.id}"
69
+ end
70
+
71
+ render :json => resp
72
+ end
73
+
74
+ # PUT /admin/redirects/:id
75
+ def admin_update
76
+ return unless user_is_allowed('redirects', 'edit')
77
+
78
+ resp = StdClass.new
79
+ pr = PermanentRedirect.find(params[:id])
80
+
81
+ save = true
82
+ params.each do |name, value|
83
+ case name
84
+ when 'is_regex' then pr.is_regex = value
85
+ when 'old_url' then pr.old_url = value
86
+ when 'new_url' then pr.new_url = value
87
+ when 'priority' then pr.priority = value
88
+ end
89
+ end
90
+
91
+ resp.success = save && pr.save
92
+ render :json => resp
93
+ end
94
+
95
+ # DELETE /admin/redirects/:id
96
+ def admin_delete
97
+ return unless user_is_allowed('redirects', 'delete')
98
+ pr = PermanentRedirect.find(params[:id])
99
+ pr.destroy
100
+
101
+ resp = StdClass.new({
102
+ 'redirect' => '/admin/redirects'
103
+ })
104
+ render :json => resp
105
+ end
106
+
107
+ end
108
+ end
@@ -2,8 +2,25 @@
2
2
  class Caboose::PermanentRedirect < ActiveRecord::Base
3
3
  self.table_name = "permanent_redirects"
4
4
 
5
- attr_accessible
5
+ attr_accessible :id,
6
+ :site_id,
7
+ :priority,
8
+ :is_regex,
9
+ :old_url,
10
+ :new_url
6
11
 
12
+ validates :old_url, :presence => { :message => 'The old URL is required.' }
13
+ validates :new_url, :presence => { :message => 'The new URL is required.' }
14
+
15
+ def self.match(site_id, uri)
16
+ Caboose::PermanentRedirect.where(:site_id => site_id).reorder(:priority).all.each do |pr|
17
+ if pr.is_regex
18
+ return uri.gsub(/#{pr.old_url}/, pr.new_url) if uri =~ /#{pr.old_url}/
19
+ else
20
+ return pr.new_url if uri == pr.old_url
21
+ end
22
+ end
23
+ return false
24
+ end
7
25
 
8
-
9
26
  end
@@ -173,6 +173,13 @@ class Caboose::Schema < Caboose::Utilities::Schema
173
173
  [ :page_id , :integer ],
174
174
  [ :action , :string ]
175
175
  ],
176
+ Caboose::PermanentRedirect => [
177
+ [ :site_id , :integer ],
178
+ [ :priority , :integer , { :default => 0 }],
179
+ [ :is_regex , :boolean , { :default => false }],
180
+ [ :old_url , :string ],
181
+ [ :new_url , :string ]
182
+ ],
176
183
  Caboose::Permission => [
177
184
  [ :resource , :string ],
178
185
  [ :action , :string ]
@@ -10,4 +10,10 @@ class Caboose::Site < ActiveRecord::Base
10
10
  c = Caboose::SmtpConfig.where(:site_id => self.id).first
11
11
  end
12
12
 
13
+ def self.id_for_domain(domain)
14
+ d = Caboose::Domain.where(:domain => domain).first
15
+ return nil if d.nil?
16
+ return d.site_id
17
+ end
18
+
13
19
  end
@@ -0,0 +1,59 @@
1
+ <%
2
+ pr = @permanent_redirect
3
+ %>
4
+ <h1>Edit Permanent Redirect</h1>
5
+
6
+ <p><div id='permanentredirect_<%= pr.id %>_priority' ></div></p>
7
+ <p><div id='permanentredirect_<%= pr.id %>_is_regex' ></div></p>
8
+ <p><div id='permanentredirect_<%= pr.id %>_old_url' ></div></p>
9
+ <p><div id='permanentredirect_<%= pr.id %>_new_url' ></div></p>
10
+
11
+ <div id='message'></div>
12
+ <div id='controls'>
13
+ <input type='button' value='Back' onclick="window.location='/admin/redirects';" />
14
+ <input type='button' value='Delete Redirect' onclick="delete_redirect(<%= pr.id %>);" />
15
+ </div>
16
+
17
+ <% content_for :caboose_js do %>
18
+ <%= javascript_include_tag "caboose/model/all" %>
19
+ <script type="text/javascript">
20
+
21
+ $(document).ready(function() {
22
+ new ModelBinder({
23
+ name: 'PermanentRedirect',
24
+ id: <%= pr.id %>,
25
+ update_url: '/admin/redirects/<%= pr.id %>',
26
+ authenticity_token: '<%= form_authenticity_token %>',
27
+ attributes: [
28
+ { name: 'priority' , nice_name: 'Priority' , type: 'text' , value: <%= raw Caboose.json(pr.priority) %>, width: 400 },
29
+ { name: 'is_regex' , nice_name: 'Regex' , type: 'checkbox' , value: <%= pr.is_regex ? 1 : 0 %>, width: 400 },
30
+ { name: 'old_url' , nice_name: 'Old URL' , type: 'text' , value: <%= raw Caboose.json(pr.old_url) %>, width: 400 },
31
+ { name: 'new_url' , nice_name: 'New URL' , type: 'text' , value: <%= raw Caboose.json(pr.new_url) %>, width: 400 }
32
+ ]
33
+ });
34
+ });
35
+
36
+ function delete_redirect(pr_id, confirm)
37
+ {
38
+ if (!confirm)
39
+ {
40
+ var p = $('<p/>').addClass('note confirm')
41
+ .append('Are you sure you want to delete the redirect? ')
42
+ .append($('<input/>').attr('type','button').val('Yes').click(function() { delete_redirect(pr_id, true); })).append(' ')
43
+ .append($('<input/>').attr('type','button').val('No').click(function() { $('#message').empty(); }));
44
+ $('#message').empty().append(p);
45
+ return;
46
+ }
47
+ $('#message').html("<p class='loading'>Deleting redirect...</p>");
48
+ $.ajax({
49
+ url: '/admin/redirects/' + pr_id,
50
+ type: 'delete',
51
+ success: function(resp) {
52
+ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
53
+ if (resp.redirect) window.location = resp.redirect;
54
+ }
55
+ });
56
+ }
57
+
58
+ </script>
59
+ <% end %>
@@ -0,0 +1,24 @@
1
+ <h1>Permanent Redirects</h1>
2
+
3
+ <p><a href='/admin/redirects/new'>New Redirect</a></p>
4
+
5
+ <% if @redirects && @redirects.count > 0 %>
6
+ <table class='data'>
7
+ <tr>
8
+ <th>Priority</th>
9
+ <th>Is Regex</th>
10
+ <th>Old URL</th>
11
+ <th>New URL</th>
12
+ </tr>
13
+ <% @redirects.each do |pr| %>
14
+ <tr onclick="window.location='/admin/redirects/<%= pr.id %>';">
15
+ <td align='right'><%= pr.priority %></td>
16
+ <td><%= pr.is_regex ? 'Yes' : 'No' %></td>
17
+ <td><%= raw pr.old_url %></td>
18
+ <td><%= raw pr.new_url %></td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+ <% else %>
23
+ <p>There are no redirects right now.</p>
24
+ <% end %>
@@ -0,0 +1,38 @@
1
+
2
+ <h1>New Permanent Redirect</h1>
3
+
4
+ <form action='/admin/redirects' method='post' id='new_redirect_form'>
5
+ <input type='hidden' name='authenticity_token' value='<%= form_authenticity_token %>' />
6
+ <p>Regular expression? <input type='checkbox' name='is_regex' value='1' /></p>
7
+ <p><input type='text' name='old_url' id='old_url' placeholder='Old URL' value='' style='width: 400px;' /></p>
8
+ <p><input type='text' name='new_url' id='new_url' placeholder='New URL' value='' style='width: 400px;' /></p>
9
+ <div id='message'></div>
10
+ <p>
11
+ <input type='button' value='< Back' onclick="window.location='/admin/redirects';" />
12
+ <input type='submit' value='Add Redirect' />
13
+ </p>
14
+ </form>
15
+
16
+ <% content_for :caboose_js do %>
17
+ <script type='text/javascript'>
18
+
19
+ $(document).ready(function() {
20
+ $('#new_redirect_form').submit(function() { add_redirect(); return false; });
21
+ });
22
+
23
+ function add_redirect()
24
+ {
25
+ $('#message').html("<p class='loading'>Adding redirect...</p>");
26
+ $.ajax({
27
+ url: '/admin/redirects',
28
+ type: 'post',
29
+ data: $('#new_redirect_form').serialize(),
30
+ success: function(resp) {
31
+ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
32
+ if (resp.redirect) window.location = resp.redirect;
33
+ }
34
+ });
35
+ }
36
+
37
+ </script>
38
+ <% end %>
@@ -27,14 +27,21 @@ Caboose::Engine.routes.draw do
27
27
  post "admin/sites/:id/domains" => "sites#admin_add_domain"
28
28
  put "admin/sites/:id/domains/:domain_id/set-primary" => "sites#admin_set_primary_domain"
29
29
  delete "admin/sites/:id/domains/:domain_id" => "sites#admin_remove_domain"
30
-
30
+
31
31
  get "admin/sites/options" => "sites#options"
32
32
  get "admin/sites" => "sites#admin_index"
33
33
  get "admin/sites/new" => "sites#admin_new"
34
34
  get "admin/sites/:id" => "sites#admin_edit"
35
35
  put "admin/sites/:id" => "sites#admin_update"
36
36
  post "admin/sites" => "sites#admin_add"
37
- delete "admin/sites/:id" => "sites#admin_delete"
37
+ delete "admin/sites/:id" => "sites#admin_delete"
38
+
39
+ get "admin/redirects" => "redirects#admin_index"
40
+ get "admin/redirects/new" => "redirects#admin_new"
41
+ get "admin/redirects/:id" => "redirects#admin_edit"
42
+ put "admin/redirects/:id" => "redirects#admin_update"
43
+ post "admin/redirects" => "redirects#admin_add"
44
+ delete "admin/redirects/:id" => "redirects#admin_delete"
38
45
 
39
46
  get "admin/users" => "users#index"
40
47
  get "admin/users/options" => "users#options"
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.4.64'
2
+ VERSION = '0.4.65'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require "caboose/version"
2
2
 
3
3
  namespace :caboose do
4
-
4
+
5
5
  desc "Creates/verifies that all database tables and fields are correctly added."
6
6
  task :db => :environment do
7
7
  Caboose::Schema.create_schema
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.64
4
+ version: 0.4.65
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-01 00:00:00.000000000 Z
11
+ date: 2014-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -264,6 +264,7 @@ files:
264
264
  - app/controllers/caboose/pages_controller.rb
265
265
  - app/controllers/caboose/permissions_controller.rb
266
266
  - app/controllers/caboose/posts_controller.rb
267
+ - app/controllers/caboose/redirects_controller.rb
267
268
  - app/controllers/caboose/register_controller.rb
268
269
  - app/controllers/caboose/roles_controller.rb
269
270
  - app/controllers/caboose/settings_controller.rb
@@ -414,6 +415,9 @@ files:
414
415
  - app/views/caboose/posts/admin_new.html.erb
415
416
  - app/views/caboose/posts/detail.html.erb
416
417
  - app/views/caboose/posts/index.html.erb
418
+ - app/views/caboose/redirects/admin_edit.html.erb
419
+ - app/views/caboose/redirects/admin_index.html.erb
420
+ - app/views/caboose/redirects/admin_new.html.erb
417
421
  - app/views/caboose/register/index.html.erb
418
422
  - app/views/caboose/roles/edit.html.erb
419
423
  - app/views/caboose/roles/index.html.erb