cms-fortress 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -2,6 +2,18 @@ module Cms
2
2
  module Fortress
3
3
  class AdminController < Admin::Cms::BaseController
4
4
 
5
+ def designs
6
+
7
+ end
8
+
9
+ def settings
10
+
11
+ end
12
+
13
+ def contents
14
+
15
+ end
16
+
5
17
  def index
6
18
 
7
19
  end
@@ -1,4 +1,8 @@
1
1
  class Cms::Fortress::RolesController < Admin::Cms::BaseController
2
+ before_filter do
3
+ authorize! :manage, Cms::Fortress::Role
4
+ end
5
+
2
6
 
3
7
  # GET /cms/fortress/roles
4
8
  # GET /cms/fortress/roles.json
@@ -87,6 +91,6 @@ class Cms::Fortress::RolesController < Admin::Cms::BaseController
87
91
  private
88
92
 
89
93
  def role_params
90
- params.require(:cms_fortress_role).permit(:name, :description)
94
+ params.require(:cms_fortress_role).permit! #(:name, :description, :role_details_attributes)
91
95
  end
92
96
  end
@@ -1,4 +1,8 @@
1
1
  class Cms::Fortress::UsersController < Admin::Cms::BaseController
2
+ before_filter do
3
+ authorize! :manage, Cms::Fortress::User
4
+ end
5
+
2
6
  # GET /cms/fortress/users
3
7
  # GET /cms/fortress/users.json
4
8
  def index
@@ -40,7 +44,7 @@ class Cms::Fortress::UsersController < Admin::Cms::BaseController
40
44
  # POST /cms/fortress/users
41
45
  # POST /cms/fortress/users.json
42
46
  def create
43
- @cms_fortress_user = Cms::Fortress::User.new(params[:cms_fortress_user])
47
+ @cms_fortress_user = Cms::Fortress::User.new(user_params)
44
48
 
45
49
  respond_to do |format|
46
50
  if @cms_fortress_user.save
@@ -58,14 +62,14 @@ class Cms::Fortress::UsersController < Admin::Cms::BaseController
58
62
  def update
59
63
  @cms_fortress_user = Cms::Fortress::User.find(params[:id])
60
64
 
61
- user_params = params[:cms_fortress_user]
62
- if user_params[:password].blank?
63
- user_params.delete(:password)
64
- user_params.delete(:password_confirmation) if user_params[:password_confirmation].blank?
65
+ user = user_params
66
+ if user[:password].blank?
67
+ user.delete(:password)
68
+ user.delete(:password_confirmation) if user[:password_confirmation].blank?
65
69
  end
66
70
 
67
71
  respond_to do |format|
68
- if @cms_fortress_user.update_attributes(user_params)
72
+ if @cms_fortress_user.update_attributes(user)
69
73
  format.html { redirect_to cms_fortress_users_path, notice: 'User was successfully updated.' }
70
74
  format.json { head :no_content }
71
75
  else
@@ -86,4 +90,10 @@ class Cms::Fortress::UsersController < Admin::Cms::BaseController
86
90
  format.json { head :no_content }
87
91
  end
88
92
  end
93
+
94
+ private
95
+
96
+ def user_params
97
+ params.require(:cms_fortress_user).permit(:email, :role_id, :password, :password_confirmation)
98
+ end
89
99
  end
@@ -4,6 +4,7 @@ class Cms::Fortress::Role < ActiveRecord::Base
4
4
  # attr_accessible :description, :name
5
5
  has_many :users
6
6
  has_many :role_details
7
+ accepts_nested_attributes_for :role_details, allow_destroy: true
7
8
 
8
9
  def load_defaults
9
10
  file = File.expand_path(File.join(File.dirname(__FILE__), "../../../../", "config", "roles.yml"))
@@ -2,6 +2,32 @@ class CmsAbility
2
2
  include CanCan::Ability
3
3
 
4
4
  def initialize(user)
5
+
6
+ if user && user.role && user.role.role_details
7
+ user.role.role_details.each do |role|
8
+ can :view, role.command if role.can_view?
9
+ can :manage, role.command if role.can_create?
10
+
11
+ if role.can_create?
12
+ if role.command.eql?("settings.roles")
13
+ can :manage, Cms::Fortress::Role
14
+ elsif role.command.eql?("settings.sites")
15
+ can :manage, Cms::Site
16
+ elsif role.command.eql?("settings.users")
17
+ can :manage, Cms::Fortress::User
18
+ elsif role.command.eql?("contents.pages")
19
+ can :manage, Cms::Page
20
+ elsif role.command.eql?("contents.files")
21
+ can :manage, Cms::File
22
+ elsif role.command.eql?("designs.layouts")
23
+ can :manage, Cms::Layout
24
+ elsif role.command.eql?("designs.snippets")
25
+ can :manage, Cms::Snippet
26
+ end
27
+ end
28
+ end
29
+ end
30
+
5
31
  # Define abilities for the passed in user here. For example:
6
32
  #
7
33
  # user ||= User.new # guest user (not logged in)
@@ -0,0 +1,2 @@
1
+ .alert.alert-danger
2
+ %h3 You are not authorized to access this functionality
@@ -14,7 +14,7 @@
14
14
  %td= cms_fortress_role.description
15
15
  %td
16
16
  .btn-group.pull-right
17
- = link_to 'Show', cms_fortress_role, :class => 'btn btn-small btn-primary'
17
+ = link_to 'Show Access Rights', cms_fortress_role, :class => 'btn btn-small btn-info'
18
18
  = link_to 'Edit', edit_cms_fortress_role_path(cms_fortress_role), :class => 'btn btn-small btn-primary'
19
19
  = link_to 'Destroy', cms_fortress_role, :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-small btn-danger'
20
20
 
@@ -5,8 +5,20 @@
5
5
  %h2= "Role: #{ @cms_fortress_role.name }"
6
6
  %p= @cms_fortress_role.description
7
7
 
8
- %table.table
9
- - @cms_fortress_role.role_details.each do |d|
8
+
9
+ = form_for @cms_fortress_role, :html => {:class => ''} do |f|
10
+
11
+ %table.table
10
12
  %tr
11
- %td= d.command
12
- %td= d.can_create
13
+ %th
14
+ %th Show
15
+ %th Manage
16
+ = f.fields_for :role_details do |role|
17
+ %tr
18
+ %td= role.object.command
19
+ %td= role.check_box :can_view
20
+ %td= role.check_box :can_create
21
+
22
+ .form-actions
23
+ = f.submit 'Save', :class => 'btn btn-primary'
24
+
@@ -9,11 +9,21 @@
9
9
  .nav-collapse.collapse
10
10
  %ul.nav
11
11
  - if @site && !@site.new_record?
12
- %li{:class => content_page? ? 'active' : ''}
13
- = link_to t("cms.fortress.contents"), admin_cms_site_pages_path(@site)
14
- %li{:class => design_page? ? 'active' : ''}
15
- = link_to t("cms.fortress.design"), admin_cms_site_layouts_path(@site)
16
- %li{:class => admin_page? ? 'active' : ''}
17
- = link_to t("cms.fortress.settings"), admin_cms_sites_path
18
- %li
19
- = link_to "Logout", destroy_cms_fortress_user_session_path, :method => 'delete'
12
+ - if can? :view, 'contents'
13
+ %li{:class => content_page? ? 'active' : ''}
14
+ = link_to t("cms.fortress.contents"), admin_cms_site_pages_path(@site)
15
+
16
+ - if can? :view, 'designs'
17
+ %li{:class => design_page? ? 'active' : ''}
18
+ = link_to t("cms.fortress.design"), admin_cms_site_layouts_path(@site)
19
+ - if can? :view, 'settings'
20
+ %li{:class => admin_page? ? 'active' : ''}
21
+ = link_to t("cms.fortress.settings"), admin_cms_sites_path
22
+ %ul.nav.nav-pill.pull-right
23
+ - if current_cms_fortress_user
24
+ %li
25
+ = link_to ":: #{ current_cms_fortress_user.email }", "#"
26
+ %li
27
+ = link_to "Logout", destroy_cms_fortress_user_session_path, :method => 'delete'
28
+
29
+
@@ -0,0 +1,10 @@
1
+ .navbar.navbar-inverse.navbar-fixed-top
2
+ .navbar-inner
3
+ .container
4
+ %button.btn.btn-navbar{"data-target" => ".nav-collapse", "data-toggle" => "collapse", :type => "button"}
5
+ %span.icon-bar
6
+ %span.icon-bar
7
+ %span.icon-bar
8
+ %a.brand{:href => "#"} CMS Fortress
9
+ .nav-collapse.collapse
10
+ / /.nav-collapse
@@ -3,18 +3,25 @@
3
3
 
4
4
  %ul.navigation
5
5
  - if admin_page?
6
- %li= active_link_to t('admin.cms.base.sites'), admin_cms_sites_path, :active => ['admin/cms/sites']
7
- %li= active_link_to t('cms.fortress.roles.title'), cms_fortress_roles_path
8
- %li= active_link_to t('cms.fortress.users.title'), cms_fortress_users_path
6
+ - if can? :view, 'settings.sites'
7
+ %li= active_link_to t('admin.cms.base.sites'), admin_cms_sites_path, :active => ['admin/cms/sites']
8
+ - if can? :view, 'settings.roles'
9
+ %li= active_link_to t('cms.fortress.roles.title'), cms_fortress_roles_path
10
+ - if can? :view, 'settings.users'
11
+ %li= active_link_to t('cms.fortress.users.title'), cms_fortress_users_path
9
12
 
10
13
  - elsif design_page?
11
14
  - if @site && !@site.new_record?
12
- %li= active_link_to t('admin.cms.base.layouts'), admin_cms_site_layouts_path(@site)
13
- %li= active_link_to t('admin.cms.base.snippets'), admin_cms_site_snippets_path(@site)
15
+ - if can? :view, 'designs.layouts'
16
+ %li= active_link_to t('admin.cms.base.layouts'), admin_cms_site_layouts_path(@site)
17
+ - if can? :view, 'designs.snippets'
18
+ %li= active_link_to t('admin.cms.base.snippets'), admin_cms_site_snippets_path(@site)
14
19
  - else
15
20
  - if @site && !@site.new_record?
16
- %li= active_link_to t('admin.cms.base.pages'), admin_cms_site_pages_path(@site)
17
- %li= active_link_to t('admin.cms.base.files'), admin_cms_site_files_path(@site)
21
+ - if can? :view, 'contents.pages'
22
+ %li= active_link_to t('admin.cms.base.pages'), admin_cms_site_pages_path(@site)
23
+ - if can? :view, 'contents.files'
24
+ %li= active_link_to t('admin.cms.base.files'), admin_cms_site_files_path(@site)
18
25
 
19
26
  = cms_hook :navigation
20
27
 
data/cms-fortress.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cms-fortress"
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Melvin Sembrano"]
12
- s.date = "2013-12-10"
12
+ s.date = "2013-12-11"
13
13
  s.description = "Comfortable Mexican Sofa (CMS) - User and role management extension"
14
14
  s.email = "melvinsembrano@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -50,6 +50,7 @@ Gem::Specification.new do |s|
50
50
  "app/views/cms/fortress/admin/design.html.haml",
51
51
  "app/views/cms/fortress/admin/roles.html.haml",
52
52
  "app/views/cms/fortress/admin/settings.html.haml",
53
+ "app/views/cms/fortress/admin/unauthorised.html.haml",
53
54
  "app/views/cms/fortress/admin/users.html.haml",
54
55
  "app/views/cms/fortress/roles/_form.html.haml",
55
56
  "app/views/cms/fortress/roles/edit.html.haml",
@@ -57,14 +58,13 @@ Gem::Specification.new do |s|
57
58
  "app/views/cms/fortress/roles/new.html.haml",
58
59
  "app/views/cms/fortress/roles/show.html.haml",
59
60
  "app/views/cms/fortress/shared/_admin_topnav.html.haml",
60
- "app/views/cms/fortress/shared/_navbar.html.erb",
61
+ "app/views/cms/fortress/shared/_navbar.html.haml",
61
62
  "app/views/cms/fortress/users/_form.html.haml",
62
63
  "app/views/cms/fortress/users/edit.html.haml",
63
64
  "app/views/cms/fortress/users/index.html.haml",
64
65
  "app/views/cms/fortress/users/new.html.haml",
65
66
  "app/views/cms/fortress/users/sessions/.DS_Store",
66
67
  "app/views/cms/fortress/users/sessions/new.html.haml",
67
- "app/views/layouts/admin/_body.html.haml",
68
68
  "app/views/layouts/admin/cms/.DS_Store",
69
69
  "app/views/layouts/admin/cms/_head.html.haml",
70
70
  "app/views/layouts/admin/cms/_left.html.haml",
data/lib/cms-fortress.rb CHANGED
@@ -10,3 +10,4 @@ require_relative 'cms/fortress/content_renderer'
10
10
  require_relative 'cms/fortress/comfortable_mexican_sofa'
11
11
  require_relative 'cms/fortress/devise'
12
12
  require_relative 'cms/fortress/routing'
13
+ require_relative '../app/models/cms_ability'
@@ -1,3 +1,4 @@
1
+
1
2
  module Cms
2
3
  module Fortress
3
4
  module ApplicationControllerMethods
@@ -9,6 +10,21 @@ module Cms
9
10
  # request.referrer
10
11
  admin_cms_path
11
12
  end
13
+
14
+ def current_ability
15
+ @current_ability ||= CmsAbility.new(current_cms_fortress_user)
16
+ end
17
+
18
+ def self.included(base)
19
+ base.class_eval do
20
+
21
+ rescue_from CanCan::AccessDenied do |ex|
22
+ redirect_to cms_fortress_unauthorised_path #, :alert => ex.message
23
+ end
24
+
25
+ end
26
+ end
27
+
12
28
  end
13
29
  end
14
30
  end
@@ -10,6 +10,33 @@ module Cms
10
10
  Cms::ContentController.send(:include, Cms::Fortress::ContentRenderer)
11
11
  Cms::Page.send(:include, Cms::Fortress::PageMethods)
12
12
 
13
+ # Insert Roles
14
+ Admin::Cms::SitesController.class_eval do
15
+ before_filter do
16
+ authorize! :manage, Cms::Site
17
+ end
18
+ end
19
+ Admin::Cms::LayoutsController.class_eval do
20
+ before_filter do
21
+ authorize! :manage, Cms::Layout
22
+ end
23
+ end
24
+ Admin::Cms::SnippetsController.class_eval do
25
+ before_filter do
26
+ authorize! :manage, Cms::Snippet
27
+ end
28
+ end
29
+ Admin::Cms::PagesController.class_eval do
30
+ before_filter do
31
+ authorize! :manage, Cms::Page
32
+ end
33
+ end
34
+ Admin::Cms::FilesController.class_eval do
35
+ before_filter do
36
+ authorize! :manage, Cms::File
37
+ end
38
+ end
39
+
13
40
  end
14
41
  app.config.railties_order = [ :all, ComfortableMexicanSofa::Engine, Cms::Fortress::Engine ]
15
42
 
@@ -14,6 +14,7 @@ class ActionDispatch::Routing::Mapper
14
14
  get 'settings' => 'admin#settings', :as => 'cms_fortress_settings'
15
15
  get 'design' => 'admin#design', :as => 'cms_fortress_design'
16
16
  get 'settings/users' => 'admin#users', :as => 'cms_fortress_user_settings'
17
+ get 'unauthorised' => 'admin#unauthorised', :as => 'cms_fortress_unauthorised'
17
18
 
18
19
  end
19
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cms-fortress
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-10 00:00:00.000000000 Z
12
+ date: 2013-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -196,6 +196,7 @@ files:
196
196
  - app/views/cms/fortress/admin/design.html.haml
197
197
  - app/views/cms/fortress/admin/roles.html.haml
198
198
  - app/views/cms/fortress/admin/settings.html.haml
199
+ - app/views/cms/fortress/admin/unauthorised.html.haml
199
200
  - app/views/cms/fortress/admin/users.html.haml
200
201
  - app/views/cms/fortress/roles/_form.html.haml
201
202
  - app/views/cms/fortress/roles/edit.html.haml
@@ -203,14 +204,13 @@ files:
203
204
  - app/views/cms/fortress/roles/new.html.haml
204
205
  - app/views/cms/fortress/roles/show.html.haml
205
206
  - app/views/cms/fortress/shared/_admin_topnav.html.haml
206
- - app/views/cms/fortress/shared/_navbar.html.erb
207
+ - app/views/cms/fortress/shared/_navbar.html.haml
207
208
  - app/views/cms/fortress/users/_form.html.haml
208
209
  - app/views/cms/fortress/users/edit.html.haml
209
210
  - app/views/cms/fortress/users/index.html.haml
210
211
  - app/views/cms/fortress/users/new.html.haml
211
212
  - app/views/cms/fortress/users/sessions/.DS_Store
212
213
  - app/views/cms/fortress/users/sessions/new.html.haml
213
- - app/views/layouts/admin/_body.html.haml
214
214
  - app/views/layouts/admin/cms/.DS_Store
215
215
  - app/views/layouts/admin/cms/_head.html.haml
216
216
  - app/views/layouts/admin/cms/_left.html.haml
@@ -264,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
264
264
  version: '0'
265
265
  segments:
266
266
  - 0
267
- hash: -1555868352439146595
267
+ hash: 3584437866439993559
268
268
  required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  none: false
270
270
  requirements:
@@ -1,14 +0,0 @@
1
- <div class="navbar navbar-inverse navbar-fixed-top">
2
- <div class="navbar-inner">
3
- <div class="container">
4
- <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
5
- <span class="icon-bar"></span>
6
- <span class="icon-bar"></span>
7
- <span class="icon-bar"></span>
8
- </button>
9
- <a class="brand" href="#">CMS Fortress</a>
10
- <div class="nav-collapse collapse">
11
- </div><!--/.nav-collapse -->
12
- </div>
13
- </div>
14
- </div>
@@ -1,17 +0,0 @@
1
- %body#comfy{:class => "c-#{params[:controller].slugify} a-#{params[:action].slugify}"}
2
-
3
- = render 'admin/cms/partials/body_before'
4
-
5
- .body-wrapper
6
- .left-column
7
- .left-column-content
8
- = render :partial => 'layouts/admin/cms/left'
9
- .right-column
10
- .right-column-content
11
- = render :partial => 'layouts/admin/cms/right'
12
- .center-column
13
- = render :partial => 'layouts/admin/cms/center'
14
-
15
- = render :partial => 'layouts/admin/cms/footer'
16
-
17
- = render :partial => 'layouts/admin/cms/footer_js'