freeberry 0.2.7 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -9
- data/Rakefile +1 -1
- data/app/controllers/manage/assets_controller.rb +2 -2
- data/app/controllers/manage/base_controller.rb +19 -4
- data/app/controllers/manage/pages_controller.rb +8 -7
- data/app/controllers/manage/posts_controller.rb +5 -6
- data/app/controllers/manage/settings_controller.rb +2 -0
- data/app/controllers/manage/structures_controller.rb +4 -5
- data/app/controllers/manage/users_controller.rb +4 -3
- data/config/locales/manage/en.yml +16 -16
- data/config/locales/manage/ru.yml +16 -16
- data/config/locales/manage/uk.yml +16 -16
- data/lib/freeberry.rb +2 -3
- data/lib/freeberry/models/asset.rb +15 -21
- data/lib/freeberry/models/user.rb +36 -16
- data/lib/freeberry/railtie.rb +4 -2
- data/lib/freeberry/version.rb +1 -1
- data/lib/generators/freeberry/base/base_generator.rb +0 -1
- data/lib/generators/freeberry/base/templates/config/application.yml +2 -2
- data/lib/generators/freeberry/base/templates/config/seeds.rb +5 -8
- data/lib/generators/freeberry/base/templates/helpers/manage/base_helper.rb +4 -0
- data/lib/generators/freeberry/base/templates/javascripts/manage.js +1 -1
- data/lib/generators/freeberry/base/templates/views/manage/posts/_post.html.erb +2 -2
- data/lib/generators/freeberry/base/templates/views/manage/posts/index.html.erb +1 -1
- data/lib/generators/freeberry/base/templates/views/manage/structures/_structure.html.erb +2 -3
- data/lib/generators/freeberry/base/templates/views/manage/structures/index.html.erb +2 -2
- data/lib/generators/freeberry/base/templates/views/manage/users/_user.html.erb +2 -2
- data/lib/generators/freeberry/base/templates/views/manage/users/index.html.erb +1 -1
- data/lib/generators/freeberry/base/templates/views/shared/manage/_head.html.erb +3 -3
- data/lib/generators/freeberry/base/templates/views/shared/manage/_panel.html.erb +3 -3
- data/lib/generators/freeberry/manage_scaffold/manage_scaffold_generator.rb +20 -2
- data/lib/generators/freeberry/manage_scaffold/templates/multiplay/controller.rb +3 -3
- data/lib/generators/freeberry/manage_scaffold/templates/multiplay/views/edit.html.erb +1 -1
- data/lib/generators/freeberry/manage_scaffold/templates/multiplay/views/new.html.erb +1 -1
- data/lib/generators/freeberry/manage_scaffold/templates/single/controller.rb +4 -3
- data/lib/generators/freeberry/manage_scaffold/templates/single/views/edit.html.erb +1 -1
- data/lib/generators/freeberry/manage_scaffold/templates/single/views/new.html.erb +1 -1
- data/lib/generators/freeberry/models/templates/create_users.rb +2 -2
- data/lib/generators/freeberry/models/templates/models/ability.rb +40 -0
- data/lib/generators/freeberry/models/templates/models/comment.rb +0 -2
- data/lib/generators/freeberry/models/templates/models/user.rb +0 -2
- metadata +6 -7
- data/lib/freeberry/controllers/authorized_system.rb +0 -60
- data/lib/generators/freeberry/base/templates/config/authorization_rules.rb +0 -51
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Freeberry
|
2
2
|
|
3
|
-
|
3
|
+
Aimbulance Content Managment System
|
4
4
|
For more instruction see {Wiki}[http://wiki.github.com/galetahub/freeberry].
|
5
5
|
|
6
6
|
== Install
|
@@ -10,18 +10,19 @@ For more instruction see {Wiki}[http://wiki.github.com/galetahub/freeberry].
|
|
10
10
|
In your Gemfile:
|
11
11
|
|
12
12
|
gem 'devise', '1.1.5'
|
13
|
-
gem 'paperclip', '2.3.
|
13
|
+
gem 'paperclip', '2.3.8'
|
14
14
|
gem 'nokogiri', '1.4.4'
|
15
|
-
gem '
|
16
|
-
gem '
|
17
|
-
gem 'inherited_resources', '1.1.2'
|
15
|
+
gem 'cancan', '1.5.1'
|
16
|
+
gem 'inherited_resources', '1.2.1'
|
18
17
|
gem 'haddock', '0.2.2'
|
19
18
|
gem "mime-types", '1.16', :require => 'mime/types'
|
20
|
-
gem "ckeditor", '3.
|
19
|
+
gem "ckeditor", '3.5.0'
|
21
20
|
|
22
21
|
gem 'awesome_nested_set', :git => 'git://github.com/galetahub/awesome_nested_set.git'
|
23
22
|
gem 'will_paginate', :git => 'git://github.com/galetahub/will_paginate.git', :branch => 'rails3'
|
24
23
|
gem "freeberry", :git => "git://github.com/galetahub/freeberry.git"
|
24
|
+
gem 'cancan_namespace', :git => 'git://github.com/galetahub/cancan_namespace.git'
|
25
|
+
gem 'attach_file_field', :git => 'git://github.com/galetahub/attach_file_field.git'
|
25
26
|
|
26
27
|
Bundler
|
27
28
|
|
@@ -31,8 +32,7 @@ Plugins:
|
|
31
32
|
|
32
33
|
rails plugin install git://github.com/galetahub/enum_field.git
|
33
34
|
rails plugin install git://github.com/galetahub/salty_slugs.git
|
34
|
-
rails plugin install git://github.com/galetahub/auto_html.git
|
35
|
-
rails plugin install git://github.com/galetahub/attach_file_field.git
|
35
|
+
rails plugin install git://github.com/galetahub/auto_html.git
|
36
36
|
|
37
37
|
=== Generators
|
38
38
|
|
@@ -122,4 +122,4 @@ Manage scaffold:
|
|
122
122
|
|
123
123
|
Example goes here.
|
124
124
|
|
125
|
-
Copyright (c) 2010
|
125
|
+
Copyright (c) 2010-2011 Aimbulance, released under the MIT license
|
data/Rakefile
CHANGED
@@ -30,7 +30,7 @@ begin
|
|
30
30
|
gemspec.name = "freeberry"
|
31
31
|
gemspec.version = Freeberry::Version.dup
|
32
32
|
gemspec.summary = "Rails CRM System"
|
33
|
-
gemspec.description = "Freeberry is a
|
33
|
+
gemspec.description = "Freeberry is a Aimbulance CRM System"
|
34
34
|
gemspec.email = "galeta.igor@gmail.com"
|
35
35
|
gemspec.homepage = "https://github.com/galetahub/freeberry"
|
36
36
|
gemspec.authors = ["Igor Galeta", "Pavlo Galeta"]
|
@@ -2,10 +2,10 @@ class Manage::AssetsController < Manage::BaseController
|
|
2
2
|
before_filter :find_klass, :only => [:create, :sort]
|
3
3
|
before_filter :find_asset, :only => [:destroy]
|
4
4
|
|
5
|
-
filter_access_to :sort, :require => :update
|
6
|
-
|
7
5
|
respond_to :html, :xml
|
8
6
|
|
7
|
+
authorize_resource
|
8
|
+
|
9
9
|
def create
|
10
10
|
@asset ||= @klass.new(params[:asset])
|
11
11
|
|
@@ -1,9 +1,24 @@
|
|
1
1
|
class Manage::BaseController < ApplicationController
|
2
|
-
layout "manage"
|
3
|
-
|
4
2
|
before_filter :authenticate_user!
|
3
|
+
check_authorization
|
4
|
+
|
5
|
+
layout "manage"
|
6
|
+
respond_to :html
|
5
7
|
|
6
|
-
|
8
|
+
protected
|
7
9
|
|
8
|
-
|
10
|
+
rescue_from CanCan::AccessDenied do |exception|
|
11
|
+
flash[:failure] = exception.message
|
12
|
+
flash[:failure] ||= I18n.t(:access_denied, :scope => [:flash, :users])
|
13
|
+
|
14
|
+
respond_to do |format|
|
15
|
+
format.html { redirect_to new_session_path(:user) }
|
16
|
+
format.xml { head :unauthorized }
|
17
|
+
format.js { head :unauthorized }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_ability
|
22
|
+
@current_ability ||= ::Ability.new(current_user, :manage)
|
23
|
+
end
|
9
24
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
class Manage::PagesController < Manage::BaseController
|
2
2
|
before_filter :find_structure
|
3
|
+
before_filter :find_page
|
3
4
|
|
4
5
|
cache_sweeper :page_sweeper, :only => [:create, :update, :destroy]
|
5
6
|
|
7
|
+
authorize_resource
|
8
|
+
|
6
9
|
# GET /manage/structures/1/page/edit
|
7
10
|
def edit
|
8
|
-
@page = @structure.page || @structure.build_page(:title=>@structure.title)
|
9
|
-
|
10
11
|
respond_with(@page) do |format|
|
11
12
|
format.html { render :action => (@page.new_record? ? 'new' : 'edit') }
|
12
13
|
end
|
@@ -14,17 +15,13 @@ class Manage::PagesController < Manage::BaseController
|
|
14
15
|
|
15
16
|
# POST /manage/structures/1/page
|
16
17
|
def create
|
17
|
-
@page
|
18
|
-
@page.save
|
19
|
-
|
18
|
+
@page.update_attributes(params[:page])
|
20
19
|
respond_with(@page, :location => manage_structures_path)
|
21
20
|
end
|
22
21
|
|
23
22
|
# PUT /manage/structures/1/page
|
24
23
|
def update
|
25
|
-
@page = @structure.page
|
26
24
|
@page.update_attributes(params[:page])
|
27
|
-
|
28
25
|
respond_with(@page, :location => manage_structures_path)
|
29
26
|
end
|
30
27
|
|
@@ -33,4 +30,8 @@ class Manage::PagesController < Manage::BaseController
|
|
33
30
|
def find_structure
|
34
31
|
@structure = Structure.find(params[:structure_id])
|
35
32
|
end
|
33
|
+
|
34
|
+
def find_page
|
35
|
+
@page = @structure.page || @structure.build_page(:title => @structure.title)
|
36
|
+
end
|
36
37
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
class Manage::PostsController < Manage::BaseController
|
2
2
|
inherit_resources
|
3
|
-
|
4
|
-
belongs_to :structure
|
5
|
-
|
6
|
-
before_filter :make_filter, :only => [:index]
|
7
|
-
|
8
3
|
defaults :route_prefix => 'manage'
|
9
4
|
actions :all, :except => [:show]
|
5
|
+
belongs_to :structure
|
6
|
+
|
7
|
+
load_and_authorize_resource :post, :through => :structure
|
10
8
|
|
9
|
+
before_filter :make_filter, :only => [:index]
|
11
10
|
cache_sweeper :post_sweeper, :only => [:create, :update, :destroy]
|
12
11
|
|
13
12
|
def create
|
@@ -32,7 +31,7 @@ class Manage::PostsController < Manage::BaseController
|
|
32
31
|
options = { :page => params[:page], :per_page => 20 }
|
33
32
|
options.update @search.filter
|
34
33
|
|
35
|
-
@posts
|
34
|
+
@posts = (@posts || end_of_association_chain).paginate(options)
|
36
35
|
end
|
37
36
|
|
38
37
|
def make_filter
|
@@ -1,12 +1,11 @@
|
|
1
1
|
class Manage::StructuresController < Manage::BaseController
|
2
2
|
inherit_resources
|
3
|
-
|
4
|
-
before_filter :find_root, :only=>[:index]
|
5
|
-
|
6
3
|
defaults :route_prefix => 'manage'
|
7
4
|
|
8
|
-
|
5
|
+
before_filter :find_root, :only=>[:index]
|
9
6
|
|
7
|
+
load_and_authorize_resource
|
8
|
+
|
10
9
|
cache_sweeper :structure_sweeper, :only=>[:create, :update, :destroy, :move]
|
11
10
|
|
12
11
|
def create
|
@@ -37,6 +36,6 @@ class Manage::StructuresController < Manage::BaseController
|
|
37
36
|
end
|
38
37
|
|
39
38
|
def collection
|
40
|
-
@structures
|
39
|
+
@structures = (@structures || end_of_association_chain).with_depth(1)
|
41
40
|
end
|
42
41
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
class Manage::UsersController < Manage::BaseController
|
2
2
|
inherit_resources
|
3
|
+
defaults :route_prefix => 'manage'
|
3
4
|
|
4
5
|
before_filter :make_filter, :only=>[:index]
|
5
6
|
before_filter :check_params, :only => [:create, :update]
|
6
7
|
before_filter :find_user, :only=>[:update, :activate]
|
7
|
-
|
8
|
-
|
8
|
+
|
9
|
+
load_and_authorize_resource
|
9
10
|
|
10
11
|
cache_sweeper :user_sweeper, :only=>[:update, :destroy]
|
11
12
|
|
@@ -54,7 +55,7 @@ class Manage::UsersController < Manage::BaseController
|
|
54
55
|
options = { :page => params[:page], :per_page => 20 }
|
55
56
|
options.update @search.filter
|
56
57
|
|
57
|
-
@users
|
58
|
+
@users = (@users || end_of_association_chain).includes(:avatar).paginate(options)
|
58
59
|
end
|
59
60
|
|
60
61
|
def make_filter
|
@@ -14,8 +14,8 @@ en:
|
|
14
14
|
|
15
15
|
structure:
|
16
16
|
title: "Name"
|
17
|
-
title_ru: "Name
|
18
|
-
title_en: "Name
|
17
|
+
title_ru: "Name (Rus)"
|
18
|
+
title_en: "Name (eng.)"
|
19
19
|
parent_id: "Main Categories"
|
20
20
|
is_visible: "Show?"
|
21
21
|
kind: "Page Type"
|
@@ -24,32 +24,32 @@ en:
|
|
24
24
|
|
25
25
|
header:
|
26
26
|
title: "Title page"
|
27
|
-
title_ru: "Title page
|
28
|
-
title_en: "Title page
|
27
|
+
title_ru: "Title page (Rus)"
|
28
|
+
title_en: "Title page (eng.)"
|
29
29
|
keywords: "Keywords"
|
30
|
-
keywords_ru: "Keywords
|
31
|
-
keywords_en: "Keywords
|
30
|
+
keywords_ru: "Keywords (Rus)"
|
31
|
+
keywords_en: "Keywords (eng.)"
|
32
32
|
description: "Page Description"
|
33
|
-
description_ru: "Description page
|
34
|
-
description_en: "Page Description
|
33
|
+
description_ru: "Description page (Rus)"
|
34
|
+
description_en: "Page Description (eng.)"
|
35
35
|
|
36
36
|
post:
|
37
37
|
title: "Name"
|
38
|
-
title_ru: "Name
|
39
|
-
title_en: "Name
|
38
|
+
title_ru: "Name (Rus)"
|
39
|
+
title_en: "Name (eng.)"
|
40
40
|
content: "Content"
|
41
|
-
content_ru: "Content
|
42
|
-
content_en: "Contents
|
41
|
+
content_ru: "Content (Rus)"
|
42
|
+
content_en: "Contents (eng.)"
|
43
43
|
created_at: "Date / Time"
|
44
44
|
picture: "Picture"
|
45
45
|
|
46
46
|
page:
|
47
47
|
title: "Name"
|
48
|
-
title_ru: "Name
|
49
|
-
title_en: "Name
|
48
|
+
title_ru: "Name (Rus)"
|
49
|
+
title_en: "Name (eng.)"
|
50
50
|
content: "Content"
|
51
|
-
content_ru: "Content
|
52
|
-
content_en: "Contents
|
51
|
+
content_ru: "Content (Rus)"
|
52
|
+
content_en: "Contents (eng.)"
|
53
53
|
|
54
54
|
tag:
|
55
55
|
name: "Name"
|
@@ -14,8 +14,8 @@ ru:
|
|
14
14
|
|
15
15
|
structure:
|
16
16
|
title: "Название"
|
17
|
-
title_ru: "Название
|
18
|
-
title_en: "Название
|
17
|
+
title_ru: "Название (рус.)"
|
18
|
+
title_en: "Название (eng.)"
|
19
19
|
parent_id: "Главная категория"
|
20
20
|
is_visible: "Отображать?"
|
21
21
|
kind: "Тип страницы"
|
@@ -24,32 +24,32 @@ ru:
|
|
24
24
|
|
25
25
|
header:
|
26
26
|
title: "Заглавие страницы"
|
27
|
-
title_ru: "Заглавие страницы
|
28
|
-
title_en: "Заглавие страницы
|
27
|
+
title_ru: "Заглавие страницы (рус.)"
|
28
|
+
title_en: "Заглавие страницы (eng.)"
|
29
29
|
keywords: "Ключевые слова"
|
30
|
-
keywords_ru: "Ключевые слова
|
31
|
-
keywords_en: "Ключевые слова
|
30
|
+
keywords_ru: "Ключевые слова (рус.)"
|
31
|
+
keywords_en: "Ключевые слова (eng.)"
|
32
32
|
description: "Описание страницы"
|
33
|
-
description_ru: "Описание страницы
|
34
|
-
description_en: "Описание страницы
|
33
|
+
description_ru: "Описание страницы (рус.)"
|
34
|
+
description_en: "Описание страницы (eng.)"
|
35
35
|
|
36
36
|
post:
|
37
37
|
title: "Название"
|
38
|
-
title_ru: "Название
|
39
|
-
title_en: "Название
|
38
|
+
title_ru: "Название (рус.)"
|
39
|
+
title_en: "Название (eng.)"
|
40
40
|
content: "Содержание"
|
41
|
-
content_ru: "Содержание
|
42
|
-
content_en: "Содержание
|
41
|
+
content_ru: "Содержание (рус.)"
|
42
|
+
content_en: "Содержание (eng.)"
|
43
43
|
created_at: "Дата/Время"
|
44
44
|
picture: "Картинка"
|
45
45
|
|
46
46
|
page:
|
47
47
|
title: "Название"
|
48
|
-
title_ru: "Название
|
49
|
-
title_en: "Название
|
48
|
+
title_ru: "Название (рус.)"
|
49
|
+
title_en: "Название (eng.)"
|
50
50
|
content: "Содержание"
|
51
|
-
content_ru: "Содержание
|
52
|
-
content_en: "Содержание
|
51
|
+
content_ru: "Содержание (рус.)"
|
52
|
+
content_en: "Содержание (eng.)"
|
53
53
|
|
54
54
|
tag:
|
55
55
|
name: "Название"
|
@@ -14,8 +14,8 @@ uk:
|
|
14
14
|
|
15
15
|
structure:
|
16
16
|
title: "Назва"
|
17
|
-
title_ru: "Назва
|
18
|
-
title_en: "Назва
|
17
|
+
title_ru: "Назва (рос.)"
|
18
|
+
title_en: "Назва (eng.)"
|
19
19
|
parent_id: "Головна категорія"
|
20
20
|
is_visible: "Відображати?"
|
21
21
|
kind: "Тип сторінки"
|
@@ -24,32 +24,32 @@ uk:
|
|
24
24
|
|
25
25
|
header:
|
26
26
|
title: "Заголовок сторінки"
|
27
|
-
title_ru: "Заголовок сторінки
|
28
|
-
title_en: "Заголовок сторінки
|
27
|
+
title_ru: "Заголовок сторінки (рос.)"
|
28
|
+
title_en: "Заголовок сторінки (eng.)"
|
29
29
|
keywords: "Ключові слова"
|
30
|
-
keywords_ru: "Ключові слова
|
31
|
-
keywords_en: "Ключові слова
|
30
|
+
keywords_ru: "Ключові слова (рос.)"
|
31
|
+
keywords_en: "Ключові слова (eng.)"
|
32
32
|
description: "Опис сторінки"
|
33
|
-
description_ru: "Опис сторінки
|
34
|
-
description_en: "Опис сторінки
|
33
|
+
description_ru: "Опис сторінки (рос.)"
|
34
|
+
description_en: "Опис сторінки (eng.)"
|
35
35
|
|
36
36
|
post:
|
37
37
|
title: "Назва"
|
38
|
-
title_ru: "Назва
|
39
|
-
title_en: "Назва
|
38
|
+
title_ru: "Назва (рос.)"
|
39
|
+
title_en: "Назва (eng.)"
|
40
40
|
content: "Зміст"
|
41
|
-
content_ru: "Зміст
|
42
|
-
content_en: "Зміст
|
41
|
+
content_ru: "Зміст (рос.)"
|
42
|
+
content_en: "Зміст (eng.)"
|
43
43
|
created_at: "Дата / Час"
|
44
44
|
picture: "Зображення"
|
45
45
|
|
46
46
|
page:
|
47
47
|
title: "Назва"
|
48
|
-
title_ru: "Назва
|
49
|
-
title_en: "Назва
|
48
|
+
title_ru: "Назва (рос.)"
|
49
|
+
title_en: "Назва (eng.)"
|
50
50
|
content: "Зміст"
|
51
|
-
content_ru: "Зміст
|
52
|
-
content_en: "Зміст
|
51
|
+
content_ru: "Зміст (рос.)"
|
52
|
+
content_en: "Зміст (eng.)"
|
53
53
|
|
54
54
|
tag:
|
55
55
|
name: "Назва"
|
data/lib/freeberry.rb
CHANGED
@@ -13,9 +13,8 @@ module Freeberry
|
|
13
13
|
|
14
14
|
# Controllers
|
15
15
|
module Controllers
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :HelperUtils, 'freeberry/controllers/helper_utils'
|
16
|
+
autoload :HeadOptions, 'freeberry/controllers/head_options'
|
17
|
+
autoload :HelperUtils, 'freeberry/controllers/helper_utils'
|
19
18
|
end
|
20
19
|
|
21
20
|
# Models
|
@@ -14,7 +14,7 @@ module Freeberry
|
|
14
14
|
belongs_to :assetable, :polymorphic => true
|
15
15
|
|
16
16
|
before_validation :make_content_type
|
17
|
-
before_create :read_dimensions
|
17
|
+
before_create :read_dimensions
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -52,23 +52,24 @@ module Freeberry
|
|
52
52
|
I18n.l(created_at, :format => "%d.%m.%Y %H:%M")
|
53
53
|
end
|
54
54
|
|
55
|
-
def to_xml(options = {})
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
xml.path self.url
|
55
|
+
def to_xml(options = {}, &block)
|
56
|
+
options = {:only => [:id], :root => 'asset'}.merge(options)
|
57
|
+
|
58
|
+
options[:procs] ||= Proc.new do |options, record|
|
59
|
+
options[:builder].tag!('filename', filename)
|
60
|
+
options[:builder].tag!('path', url)
|
61
|
+
options[:builder].tag!('size', size)
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
unless styles.empty?
|
64
|
+
options[:builder].tag!('styles') do |xml|
|
65
|
+
styles.each do |style|
|
66
|
+
xml.tag!(style.first, url(style.first))
|
67
|
+
end
|
67
68
|
end
|
68
|
-
end
|
69
|
+
end
|
69
70
|
end
|
70
71
|
|
71
|
-
|
72
|
+
super
|
72
73
|
end
|
73
74
|
|
74
75
|
def has_dimensions?
|
@@ -86,13 +87,6 @@ module Freeberry
|
|
86
87
|
|
87
88
|
protected
|
88
89
|
|
89
|
-
def parameterize_filename
|
90
|
-
unless data_file_name.blank?
|
91
|
-
filename = Freeberry::Utils.parameterize_filename(data_file_name)
|
92
|
-
self.data.instance_write(:file_name, filename)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
90
|
def read_dimensions
|
97
91
|
if image? && has_dimensions?
|
98
92
|
self.width = geometry.width
|
@@ -9,15 +9,14 @@ module Freeberry
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
def self.extended(base)
|
12
|
-
base.class_eval do
|
13
|
-
before_validation :make_login
|
14
|
-
|
12
|
+
base.class_eval do
|
15
13
|
has_many :roles, :dependent => :delete_all
|
16
14
|
has_one :avatar, :as => :assetable, :dependent => :destroy, :autosave => true
|
17
15
|
|
18
|
-
scope :
|
19
|
-
scope :
|
16
|
+
scope :with_role, lambda {|role| joins(:roles).where(["`roles`.role_type = ?", role.id]) }
|
17
|
+
scope :admins, with_role(::RoleType.admin)
|
20
18
|
|
19
|
+
before_validation :generate_login, :if => :has_login?
|
21
20
|
before_create :set_default_role, :if => :roles_empty?
|
22
21
|
end
|
23
22
|
end
|
@@ -39,7 +38,11 @@ module Freeberry
|
|
39
38
|
def roles_empty?
|
40
39
|
self.roles.empty?
|
41
40
|
end
|
42
|
-
|
41
|
+
|
42
|
+
def has_login?
|
43
|
+
respond_to?(:login)
|
44
|
+
end
|
45
|
+
|
43
46
|
def roles_attributes=(value)
|
44
47
|
options = value || {}
|
45
48
|
options.each do |k, v|
|
@@ -51,6 +54,26 @@ module Freeberry
|
|
51
54
|
(roles || []).map {|r| r.to_sym}
|
52
55
|
end
|
53
56
|
|
57
|
+
def current_role
|
58
|
+
self.roles.first
|
59
|
+
end
|
60
|
+
|
61
|
+
def role_type_id
|
62
|
+
if current_role
|
63
|
+
current_role.role_type.id
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def role_type_id=(value)
|
68
|
+
role_id = value.blank? ? nil : value.to_i
|
69
|
+
|
70
|
+
if ::RoleType.all.map(&:id).include?(role_id)
|
71
|
+
::RoleType.all.each do |role_type|
|
72
|
+
create_or_destroy_role(role_type.id, role_type.id == role_id)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
54
77
|
def state
|
55
78
|
return 'active' if active?
|
56
79
|
return 'register' unless confirmed?
|
@@ -81,16 +104,13 @@ module Freeberry
|
|
81
104
|
end
|
82
105
|
end
|
83
106
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
tmp_login = [tmp_login, ActiveSupport::SecureRandom.hex(4)].join('_') unless self.class.find_by_login(tmp_login).nil?
|
92
|
-
self.login = tmp_login
|
93
|
-
end
|
107
|
+
def generate_login
|
108
|
+
self.login ||= begin
|
109
|
+
unless email.blank?
|
110
|
+
tmp_login = email.split('@').first
|
111
|
+
tmp_login.parameterize.downcase.gsub(/[^A-Za-z0-9-]+/, '-').gsub(/-+/, '-')
|
112
|
+
end
|
113
|
+
end
|
94
114
|
end
|
95
115
|
end
|
96
116
|
end
|
data/lib/freeberry/railtie.rb
CHANGED
@@ -21,10 +21,12 @@ module Freeberry
|
|
21
21
|
end
|
22
22
|
|
23
23
|
config.after_initialize do
|
24
|
-
::ActionController::Base.send :include, Freeberry::Controllers::AuthorizedSystem
|
25
24
|
::ActionController::Base.send :include, Freeberry::Controllers::HeadOptions
|
26
|
-
|
27
25
|
::ActionView::Base.send :include, Freeberry::Controllers::HelperUtils
|
26
|
+
|
27
|
+
::Paperclip.interpolates('basename') do |attachment, style|
|
28
|
+
Freeberry::Utils.parameterize_filename(attachment.original_filename.gsub(/#{File.extname(attachment.original_filename)}$/, ""))
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
rake_tasks do
|
data/lib/freeberry/version.rb
CHANGED
@@ -34,7 +34,6 @@ module Freeberry
|
|
34
34
|
|
35
35
|
def copy_configurations
|
36
36
|
copy_file('config/words', 'config/words')
|
37
|
-
copy_file('config/authorization_rules.rb', 'config/authorization_rules.rb')
|
38
37
|
copy_file('config/seeds.rb', 'db/seeds.rb')
|
39
38
|
copy_file('config/freeberry.rb', 'config/initializers/freeberry.rb')
|
40
39
|
|
@@ -1,7 +1,4 @@
|
|
1
|
-
def insert_user
|
2
|
-
# TurnOff Authorization system
|
3
|
-
Authorization.ignore_access_control(true)
|
4
|
-
|
1
|
+
def insert_user
|
5
2
|
# Path to words
|
6
3
|
Haddock::Password.diction = Rails.root.join("config", "words")
|
7
4
|
|
@@ -10,14 +7,14 @@ def insert_user
|
|
10
7
|
Role.truncate_table
|
11
8
|
password = Haddock::Password.generate
|
12
9
|
|
13
|
-
admin = User.new(:name=>'Administrator', :email=>'
|
10
|
+
admin = User.new(:name=>'Administrator', :email=>'dev@aimbulance.com',
|
14
11
|
:password=>password, :password_confirmation=>password)
|
15
|
-
admin.login = 'admin'
|
12
|
+
#admin.login = 'admin'
|
13
|
+
admin.roles.build(:role_type => RoleType.admin)
|
16
14
|
admin.skip_confirmation!
|
17
15
|
admin.save!
|
18
|
-
admin.roles.create(:role_type => RoleType.admin)
|
19
16
|
|
20
|
-
puts "Admin
|
17
|
+
puts "Admin: #{admin.email}, #{admin.password}"
|
21
18
|
end
|
22
19
|
|
23
20
|
def insert_structures
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* ------------------------------------------------------------------------
|
2
2
|
* manage.js
|
3
|
-
* Copyright (c) 2007-
|
3
|
+
* Copyright (c) 2007-2011 Aimbulance, LLC. All rights reserved.
|
4
4
|
* ------------------------------------------------------------------------ */
|
5
5
|
|
6
6
|
$(document).ready(function(){
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<%= content_tag(:div, :id => dom_id(post), :class=>"dinamic-bl") do %>
|
2
2
|
<div class="act-bl" style="display:none;">
|
3
|
-
<%
|
3
|
+
<% if can? :update, post, :context => :manage %>
|
4
4
|
<%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_structure_post_path(@structure.id, post.id), :class=>"icons" %>
|
5
5
|
<% end %>
|
6
6
|
|
7
|
-
<%
|
7
|
+
<% if can? :delete, post, :context => :manage %>
|
8
8
|
<%= link_to image_tag("manage/ico_del.gif", :title=>t('manage.delete')), manage_structure_post_path(@structure.id, post.id),
|
9
9
|
:method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
|
10
10
|
<% end %>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<%= link_to @structure.title, manage_structure_posts_path(@structure.id), :class=>"dark-text" %>
|
8
8
|
|
9
9
|
<div class="act-bl">
|
10
|
-
<%
|
10
|
+
<% if can? :create, Post, :context => :manage %>
|
11
11
|
<%= link_to t('manage.add'), new_manage_structure_post_path(@structure.id), :class=>"create" %>
|
12
12
|
<% end %>
|
13
13
|
</div>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<div class="r-corn">
|
4
4
|
<%= link_to structure.title, edit_structure_record_path(structure), :class=>(structure.descendants_count.zero? ? "dark-text" : "dark-arr"), :id=>"a#{structure.id}" %>
|
5
5
|
<div class="act-bl" style="display:none;">
|
6
|
-
<%
|
6
|
+
<% if can? :update, structure, :context => :manage %>
|
7
7
|
<%= link_to image_tag("manage/ico_down.gif", :alt=>t('manage.position.down'), :title=>t('manage.position.down')),
|
8
8
|
move_manage_structure_path(:id => structure.id, :direction => 'down', :format => :json),
|
9
9
|
:remote => true,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<%= link_to image_tag("manage/ico_settings.gif", :alt=>t('manage.label_settings'), :title=>t('manage.label_settings')), edit_manage_structure_path(:id=>structure.id), :class=>"icons" %>
|
19
19
|
<% end %>
|
20
20
|
|
21
|
-
<%
|
21
|
+
<% if can? :delete, structure, :context => :manage %>
|
22
22
|
<%= link_to image_tag("manage/ico_del.gif", :alt=>t('manage.delete'), :title=>t('manage.delete')), manage_structure_path(:id=>structure.id),
|
23
23
|
:method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
|
24
24
|
<% end %>
|
@@ -32,4 +32,3 @@
|
|
32
32
|
<% end %>
|
33
33
|
<% end %>
|
34
34
|
<% end %>
|
35
|
-
|
@@ -5,11 +5,11 @@
|
|
5
5
|
<%= link_to @structure.title, root_path, :class=>"dark-arr", :id=>"a#{@structure.id}" %>
|
6
6
|
|
7
7
|
<div class="act-bl">
|
8
|
-
<%
|
8
|
+
<% if can? :create, Structure, :context => :manage %>
|
9
9
|
<%= link_to t('manage.buttons.create_structure'), new_manage_structure_path, :class=>"create" %>
|
10
10
|
<% end %>
|
11
11
|
|
12
|
-
<%
|
12
|
+
<% if can? :update, @structure, :context => :manage %>
|
13
13
|
<%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_structure_page_path(@structure.id), :class=>"icons" %>
|
14
14
|
<%= link_to image_tag("manage/ico_settings.gif", :title=>t('manage.label_settings')), edit_manage_structure_path(@structure.id), :class=>"icons" %>
|
15
15
|
<% end %>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<%= content_tag(:div, :id=>dom_id(user), :class=>"dinamic-bl #{user.state}") do %>
|
2
2
|
<div class="act-bl" style="display:none;">
|
3
|
-
<%
|
3
|
+
<% if can? :update, user, :context => :manage %>
|
4
4
|
<%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_user_path(:id=>user.id), :class=>"icons" %>
|
5
5
|
<% end %>
|
6
6
|
|
7
|
-
<%
|
7
|
+
<% if can? :delete, user, :context => :manage %>
|
8
8
|
<%= link_to image_tag("manage/ico_del.gif", :title=>t('manage.delete')), manage_user_path(:id=>user.id),
|
9
9
|
:method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
|
10
10
|
<% end %>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<div class="r-corn">
|
7
7
|
<%= link_to t('manage.menu.users'), manage_users_path, :class=>"dark-text" %>
|
8
8
|
<div class="act-bl">
|
9
|
-
<%
|
9
|
+
<% if can? :create, User, :context => :manage %>
|
10
10
|
<%= link_to t('manage.add'), new_manage_user_path, :class=>"create" %>
|
11
11
|
<% end %>
|
12
12
|
</div>
|
@@ -4,15 +4,15 @@
|
|
4
4
|
|
5
5
|
<div class="main-menu">
|
6
6
|
<ul>
|
7
|
-
<%
|
7
|
+
<% if can? :read, Structure, :context => :manage %>
|
8
8
|
<li><%= link_to_unless_current_span2 t('manage.menu.structures'), manage_structures_path %></li>
|
9
9
|
<% end %>
|
10
10
|
|
11
|
-
<%
|
11
|
+
<% if can? :read, User, :context => :manage %>
|
12
12
|
<li><%= link_to_unless_current_span2 t('manage.menu.users'), manage_users_path %></li>
|
13
13
|
<% end %>
|
14
14
|
|
15
|
-
<%
|
15
|
+
<% if can? :read, :settings, :context => :manage %>
|
16
16
|
<li><%= link_to_unless_current_span2 t('manage.menu.settings'), manage_settings_path %></li>
|
17
17
|
<% end %>
|
18
18
|
</ul>
|
@@ -5,15 +5,15 @@
|
|
5
5
|
<div class="p-logo"><%=raw t('manage.title') %></div>
|
6
6
|
<div class="panel-main-menu">
|
7
7
|
<ul>
|
8
|
-
<%
|
8
|
+
<% if can? :read, Structure, :context => :manage %>
|
9
9
|
<li><%= link_to_unless_current_span2 t('manage.menu.structures'), manage_structures_path %></li>
|
10
10
|
<% end %>
|
11
11
|
|
12
|
-
<%
|
12
|
+
<% if can? :read, User, :context => :manage %>
|
13
13
|
<li><%= link_to_unless_current_span2 t('manage.menu.users'), manage_users_path %></li>
|
14
14
|
<% end %>
|
15
15
|
|
16
|
-
<%
|
16
|
+
<% if can? :read, :settings, :context => :manage %>
|
17
17
|
<li><%= link_to_unless_current_span2 t('manage.menu.settings'), manage_settings_path %></li>
|
18
18
|
<% end %>
|
19
19
|
</ul>
|
@@ -52,7 +52,25 @@ module Freeberry
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def klass
|
55
|
+
# First priority is the namespaced modek, e.g. User::Group
|
56
|
+
@klass ||= begin
|
57
|
+
namespaced_class = name.singularize
|
58
|
+
namespaced_class.constantize
|
59
|
+
rescue NameError
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# Second priority the camelcased c, i.e. UserGroup
|
64
|
+
@klass ||= begin
|
65
|
+
camelcased_class = name.gsub('::', '').singularize
|
66
|
+
camelcased_class.constantize
|
67
|
+
rescue NameError
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
55
71
|
@klass ||= model_name.constantize
|
72
|
+
|
73
|
+
@klass
|
56
74
|
end
|
57
75
|
|
58
76
|
def model
|
@@ -60,12 +78,12 @@ module Freeberry
|
|
60
78
|
end
|
61
79
|
|
62
80
|
def model_name
|
63
|
-
@model_name ||=
|
81
|
+
@model_name ||= name.camelize
|
64
82
|
@model_name
|
65
83
|
end
|
66
84
|
|
67
85
|
def controller_class_name
|
68
|
-
@controller_class_name ||=
|
86
|
+
@controller_class_name ||= name.pluralize.camelize
|
69
87
|
end
|
70
88
|
|
71
89
|
def controller_file_name
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class Manage::<%= controller_class_name %>Controller < Manage::BaseController
|
2
2
|
inherit_resources
|
3
|
-
|
3
|
+
defaults :route_prefix => 'manage'
|
4
4
|
belongs_to :<%= parent_singular_name %>
|
5
5
|
|
6
6
|
before_filter :make_filter, :only=>[:index]
|
7
7
|
|
8
|
-
|
8
|
+
load_and_authorize_resource :<%= parent_singular_name %>, :class => <%= model_name %>
|
9
9
|
|
10
10
|
def create
|
11
11
|
create!{ manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id) }
|
@@ -29,7 +29,7 @@ class Manage::<%= controller_class_name %>Controller < Manage::BaseController
|
|
29
29
|
options = { :page => params[:page], :per_page => 20 }
|
30
30
|
options.update @search.filter
|
31
31
|
|
32
|
-
@<%= plural_name %>
|
32
|
+
@<%= plural_name %> = (@<%= plural_name %> || end_of_association_chain).paginate(options)
|
33
33
|
end
|
34
34
|
|
35
35
|
def make_filter
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="edit-bl">
|
2
2
|
<div class="bot-bg">
|
3
3
|
<div class="block-title"><%%= t('manage.edit') %>:</div>
|
4
|
-
<%%= form_for
|
4
|
+
<%%= form_for [:manage, @<%= parent_singular_name %>, @<%= singular_name %>], :html=>{:multipart=>true, :id=>'<%= singular_name %>_form'} do |f| -%>
|
5
5
|
<%%= render :partial=>"manage/<%= plural_name %>/form", :object=>f %>
|
6
6
|
|
7
7
|
<div style="padding: 20px 0px 10px 20px;" class="buts">
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="edit-bl">
|
2
2
|
<div class="bot-bg">
|
3
3
|
<div class="block-title"><%%= t('manage.add') %>:</div>
|
4
|
-
<%%= form_for @<%=
|
4
|
+
<%%= form_for [:manage, @<%= parent_singular_name %>, @<%= singular_name %>], :html=>{:multipart=>true, :id=>'<%= singular_name %>_form'} do |f| -%>
|
5
5
|
<%%= render :partial=>"manage/<%= plural_name %>/form", :object=>f %>
|
6
6
|
|
7
7
|
<div style="padding: 20px 0px 10px 20px;" class="buts">
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class Manage::<%= controller_class_name %>Controller < Manage::BaseController
|
2
2
|
inherit_resources
|
3
|
+
defaults :route_prefix => 'manage'
|
3
4
|
|
4
5
|
before_filter :make_filter, :only=>[:index]
|
5
|
-
|
6
|
-
|
6
|
+
|
7
|
+
load_and_authorize_resource :class => <%= class_name %>
|
7
8
|
|
8
9
|
def create
|
9
10
|
create!{ manage_<%= plural_name %>_path }
|
@@ -23,7 +24,7 @@ class Manage::<%= controller_class_name %>Controller < Manage::BaseController
|
|
23
24
|
options = { :page => params[:page], :per_page => 20 }
|
24
25
|
options.update @search.filter
|
25
26
|
|
26
|
-
@<%= plural_name %>
|
27
|
+
@<%= plural_name %> = (@<%= plural_name %> || end_of_association_chain).paginate(options)
|
27
28
|
end
|
28
29
|
|
29
30
|
def make_filter
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="edit-bl">
|
2
2
|
<div class="bot-bg">
|
3
3
|
<div class="block-title"><%%= t('manage.edit') %>:</div>
|
4
|
-
<%%= form_for
|
4
|
+
<%%= form_for [:manage, @<%= singular_name %>], :html=>{:multipart=>true, :id=>'<%= singular_name %>_form'} do |f| -%>
|
5
5
|
<%%= render :partial=>"manage/<%= plural_name %>/form", :object=>f %>
|
6
6
|
|
7
7
|
<div style="padding: 20px 0px 10px 20px;" class="buts">
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="edit-bl">
|
2
2
|
<div class="bot-bg">
|
3
3
|
<div class="block-title"><%%= t('manage.add') %>:</div>
|
4
|
-
<%%= form_for
|
4
|
+
<%%= form_for [:manage, @<%= singular_name %>], :html=>{:multipart=>true, :id=>'<%= singular_name %>_form'} do |f| -%>
|
5
5
|
<%%= render :partial=>"manage/<%= plural_name %>/form", :object=>f %>
|
6
6
|
|
7
7
|
<div style="padding: 20px 0px 10px 20px;" class="buts">
|
@@ -2,7 +2,7 @@ class FreeberryCreateUsers < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table(:users) do |t|
|
4
4
|
t.string :name, :limit => 150
|
5
|
-
t.string :login, :limit => 20, :null => false
|
5
|
+
# t.string :login, :limit => 20, :null => false
|
6
6
|
|
7
7
|
t.database_authenticatable :null => false
|
8
8
|
t.recoverable
|
@@ -15,10 +15,10 @@ class FreeberryCreateUsers < ActiveRecord::Migration
|
|
15
15
|
t.timestamps
|
16
16
|
end
|
17
17
|
|
18
|
-
add_index :users, :login, :unique => true
|
19
18
|
add_index :users, :email, :unique => true
|
20
19
|
add_index :users, :reset_password_token, :unique => true
|
21
20
|
add_index :users, :confirmation_token, :unique => true
|
21
|
+
# add_index :users, :login, :unique => true
|
22
22
|
# add_index :users, :unlock_token, :unique => true
|
23
23
|
end
|
24
24
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Ability
|
2
|
+
include CanCanNamespace::Ability
|
3
|
+
|
4
|
+
attr_accessor :context, :user
|
5
|
+
|
6
|
+
def initialize(user, context = nil)
|
7
|
+
alias_action :delete, :to => :destroy
|
8
|
+
|
9
|
+
@user = (user || User.new) # guest user (not logged in)
|
10
|
+
@context = context
|
11
|
+
|
12
|
+
case @user.role_type_id
|
13
|
+
when RoleType.default.id then default
|
14
|
+
when RoleType.redactor.id then redactor
|
15
|
+
when RoleType.moderator.id then moderator
|
16
|
+
when RoleType.admin.id then admin
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def default
|
21
|
+
can :create, Comment
|
22
|
+
can [:update, :destroy], Comment, :user_id => @user.id, :newly_created? => true
|
23
|
+
end
|
24
|
+
|
25
|
+
def redactor
|
26
|
+
# TODO
|
27
|
+
end
|
28
|
+
|
29
|
+
def moderator
|
30
|
+
# TODO
|
31
|
+
end
|
32
|
+
|
33
|
+
def admin
|
34
|
+
can :manage, :all
|
35
|
+
can :manage, :all, :context => :manage
|
36
|
+
|
37
|
+
can [:create, :destroy], Comment
|
38
|
+
can :update, Comment, :user_id => @user.id
|
39
|
+
end
|
40
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
class Comment < ActiveRecord::Base
|
2
2
|
include Freeberry::Models::Comment
|
3
3
|
|
4
|
-
using_access_control
|
5
|
-
|
6
4
|
validates :content, :presence => true, :length => { :maximum => 500 }
|
7
5
|
validates :commentable_type, :presence => true, :inclusion => { :in => %w( Post Article ) }
|
8
6
|
validates :author_type, :inclusion => { :in => %w( User FreeberryAuth::Account ) }, :allow_blank => true
|
@@ -35,8 +35,6 @@
|
|
35
35
|
class User < ActiveRecord::Base
|
36
36
|
include Freeberry::Models::User
|
37
37
|
|
38
|
-
using_access_control
|
39
|
-
|
40
38
|
# Include default devise modules.
|
41
39
|
devise :database_authenticatable, :confirmable, :lockable, :timeoutable,
|
42
40
|
:recoverable, :rememberable, :trackable, :validatable
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freeberry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 9
|
10
|
+
version: 0.2.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Igor Galeta
|
@@ -16,11 +16,11 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-03-18 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
23
|
-
description: Freeberry is a
|
23
|
+
description: Freeberry is a Aimbulance CRM System
|
24
24
|
email: galeta.igor@gmail.com
|
25
25
|
executables: []
|
26
26
|
|
@@ -52,7 +52,6 @@ files:
|
|
52
52
|
- config/routes.rb
|
53
53
|
- lib/freeberry.rb
|
54
54
|
- lib/freeberry/accessible_attributes.rb
|
55
|
-
- lib/freeberry/controllers/authorized_system.rb
|
56
55
|
- lib/freeberry/controllers/head_options.rb
|
57
56
|
- lib/freeberry/controllers/helper_utils.rb
|
58
57
|
- lib/freeberry/core_ext.rb
|
@@ -83,7 +82,6 @@ files:
|
|
83
82
|
- lib/generators/freeberry/base/USAGE
|
84
83
|
- lib/generators/freeberry/base/base_generator.rb
|
85
84
|
- lib/generators/freeberry/base/templates/config/application.yml
|
86
|
-
- lib/generators/freeberry/base/templates/config/authorization_rules.rb
|
87
85
|
- lib/generators/freeberry/base/templates/config/database.yml
|
88
86
|
- lib/generators/freeberry/base/templates/config/freeberry.rb
|
89
87
|
- lib/generators/freeberry/base/templates/config/logrotate-config
|
@@ -309,6 +307,7 @@ files:
|
|
309
307
|
- lib/generators/freeberry/models/templates/create_roles.rb
|
310
308
|
- lib/generators/freeberry/models/templates/create_structures.rb
|
311
309
|
- lib/generators/freeberry/models/templates/create_users.rb
|
310
|
+
- lib/generators/freeberry/models/templates/models/ability.rb
|
312
311
|
- lib/generators/freeberry/models/templates/models/asset.rb
|
313
312
|
- lib/generators/freeberry/models/templates/models/attachment_file.rb
|
314
313
|
- lib/generators/freeberry/models/templates/models/avatar.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module Freeberry
|
2
|
-
module Controllers
|
3
|
-
module AuthorizedSystem
|
4
|
-
def self.included(base)
|
5
|
-
base.send(:extend, ClassMethods)
|
6
|
-
base.send(:include, InstanceMethods)
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
def self.extended(base)
|
11
|
-
base.class_eval do
|
12
|
-
skip_before_filter :set_current_user
|
13
|
-
|
14
|
-
# Send current_user to Declarative authorization module
|
15
|
-
before_filter :set_current_user
|
16
|
-
|
17
|
-
helper_method :content_manager?
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module InstanceMethods
|
23
|
-
protected
|
24
|
-
|
25
|
-
# set_current_user sets the global current user for this request. This
|
26
|
-
# is used by model security that does not have access to the
|
27
|
-
# controller#current_user method. It is called as a before_filter.
|
28
|
-
def set_current_user
|
29
|
-
without_access_control do
|
30
|
-
Authorization.current_user = current_user
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def permission_denied
|
35
|
-
flash[:error] = I18n.t(:access_denied, :scope => [:flash, :users])
|
36
|
-
|
37
|
-
respond_to do |format|
|
38
|
-
format.html { redirect_to new_session_path(:user) }
|
39
|
-
format.xml { head :unauthorized }
|
40
|
-
format.js { head :unauthorized }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def without_access_control(&block)
|
45
|
-
previous_state = Authorization.ignore_access_control
|
46
|
-
begin
|
47
|
-
Authorization.ignore_access_control(true)
|
48
|
-
yield
|
49
|
-
ensure
|
50
|
-
Authorization.ignore_access_control(previous_state)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def content_manager?
|
55
|
-
user_signed_in? && current_user.admin?
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
authorization do
|
2
|
-
role :guest do
|
3
|
-
has_permission_on :users, :to => [:create, :update]
|
4
|
-
has_permission_on :accounts, :to => [:show, :create]
|
5
|
-
has_permission_on :comments, :to => [:read, :create]
|
6
|
-
end
|
7
|
-
|
8
|
-
role :default do
|
9
|
-
has_permission_on :accounts, :to => [:show]
|
10
|
-
has_permission_on :accounts, :to => [:update] do
|
11
|
-
if_attribute :id => is {user.id}
|
12
|
-
end
|
13
|
-
|
14
|
-
has_permission_on :users, :to => [:update] do
|
15
|
-
if_attribute :id => is {user.id}
|
16
|
-
end
|
17
|
-
|
18
|
-
has_permission_on :comments, :to => [:read, :create]
|
19
|
-
has_permission_on :comments, :to => [:update, :delete] do
|
20
|
-
if_attribute :author => is {user}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
role :admin do
|
25
|
-
# Models
|
26
|
-
has_permission_on :users, :to => :manage
|
27
|
-
has_permission_on :comments, :to => :manage
|
28
|
-
has_permission_on :accounts, :to => :manage
|
29
|
-
|
30
|
-
# Administration module
|
31
|
-
has_permission_on :manage_structures, :to => :manage
|
32
|
-
has_permission_on :manage_users, :to => [:manage, :activate]
|
33
|
-
has_permission_on :manage_pages, :to => :manage
|
34
|
-
has_permission_on :manage_pictures, :to => :manage
|
35
|
-
has_permission_on :manage_assets, :to => :manage
|
36
|
-
has_permission_on :manage_posts, :to => :manage
|
37
|
-
has_permission_on :manage_settings, :to => :manage
|
38
|
-
|
39
|
-
has_permission_on :authorization_rules, :to => :read
|
40
|
-
has_permission_on :authorization_usages, :to => :read
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
privileges do
|
45
|
-
# default privilege hierarchies to facilitate RESTful Rails apps
|
46
|
-
privilege :manage, :includes => [:create, :read, :update, :delete]
|
47
|
-
privilege :read, :includes => [:index, :show]
|
48
|
-
privilege :create, :includes => :new
|
49
|
-
privilege :update, :includes => :edit
|
50
|
-
privilege :delete, :includes => :destroy
|
51
|
-
end
|