cornerstone 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +168 -0
- data/Guardfile +22 -0
- data/README.rdoc +4 -1
- data/Rakefile +11 -1
- data/TODO +11 -0
- data/VERSION +1 -0
- data/app/assets/images/.gitkeep +0 -0
- data/app/assets/javascripts/.gitkeep +0 -0
- data/app/assets/javascripts/cornerstone.js +11 -0
- data/app/assets/javascripts/cornerstone/discussions.js +2 -0
- data/app/assets/javascripts/cornerstone/help.js +2 -0
- data/app/assets/stylesheets/.gitkeep +0 -0
- data/app/assets/stylesheets/cornerstone.css +8 -0
- data/app/assets/stylesheets/cornerstone/discussions.css +4 -0
- data/app/assets/stylesheets/cornerstone/help.css +4 -0
- data/app/controllers/.gitkeep +0 -0
- data/app/controllers/cornerstone/admin/application_controller.rb +7 -0
- data/app/controllers/cornerstone/admin/articles_controller.rb +61 -0
- data/app/controllers/cornerstone/admin/categories_controller.rb +46 -0
- data/app/controllers/cornerstone/admin/discussions_controller.rb +32 -0
- data/app/controllers/cornerstone/application_controller.rb +6 -0
- data/app/controllers/cornerstone/discussions_controller.rb +58 -0
- data/app/controllers/cornerstone/help_controller.rb +11 -0
- data/app/controllers/cornerstone/posts_controller.rb +66 -0
- data/app/helpers/.gitkeep +0 -0
- data/app/helpers/cornerstone/application_helper.rb +5 -0
- data/app/helpers/cornerstone/discussions_helper.rb +16 -0
- data/app/helpers/cornerstone/help_helper.rb +4 -0
- data/app/mailers/cornerstone/cornerstone_mailer.rb +31 -0
- data/app/models/.gitkeep +0 -0
- data/app/models/cornerstone/article.rb +20 -0
- data/app/models/cornerstone/category.rb +45 -0
- data/app/models/cornerstone/discussion.rb +90 -0
- data/app/models/cornerstone/post.rb +103 -0
- data/app/models/cornerstone/post_observer.rb +23 -0
- data/app/views/.gitkeep +0 -0
- data/app/views/cornerstone/admin/articles/_article.html.erb +9 -0
- data/app/views/cornerstone/admin/articles/_form.html.erb +22 -0
- data/app/views/cornerstone/admin/articles/edit.html.erb +7 -0
- data/app/views/cornerstone/admin/articles/index.html.erb +25 -0
- data/app/views/cornerstone/admin/articles/new.html.erb +6 -0
- data/app/views/cornerstone/admin/articles/show.html.erb +4 -0
- data/app/views/cornerstone/admin/categories/_category.html.erb +12 -0
- data/app/views/cornerstone/admin/categories/_form.html.erb +17 -0
- data/app/views/cornerstone/admin/categories/edit.html.erb +6 -0
- data/app/views/cornerstone/admin/categories/index.html.erb +11 -0
- data/app/views/cornerstone/admin/categories/new.html.erb +6 -0
- data/app/views/cornerstone/admin/discussions/edit.html.erb +7 -0
- data/app/views/cornerstone/cornerstone_mailer/new_discussion.html.erb +14 -0
- data/app/views/cornerstone/cornerstone_mailer/new_discussion.text.erb +5 -0
- data/app/views/cornerstone/cornerstone_mailer/new_discussion_user.html.erb +7 -0
- data/app/views/cornerstone/cornerstone_mailer/new_post.html.erb +7 -0
- data/app/views/cornerstone/cornerstone_mailer/new_post.text.erb +8 -0
- data/app/views/cornerstone/discussions/_discussion.html.erb +12 -0
- data/app/views/cornerstone/discussions/_discussion_category.html.erb +14 -0
- data/app/views/cornerstone/discussions/_form.html.erb +33 -0
- data/app/views/cornerstone/discussions/_latest_discussion.html.erb +4 -0
- data/app/views/cornerstone/discussions/categorical_index.html.erb +27 -0
- data/app/views/cornerstone/discussions/index.html.erb +25 -0
- data/app/views/cornerstone/discussions/new.html.erb +6 -0
- data/app/views/cornerstone/discussions/show.html.erb +19 -0
- data/app/views/cornerstone/help/index.html.erb +7 -0
- data/app/views/cornerstone/posts/_fields.html.erb +44 -0
- data/app/views/cornerstone/posts/_form.html.erb +19 -0
- data/app/views/cornerstone/posts/_post.html.erb +17 -0
- data/app/views/cornerstone/posts/edit.html.erb +9 -0
- data/app/views/cornerstone/shared/_errors.html.erb +11 -0
- data/app/views/cornerstone/shared/_flash_messages.html.erb +15 -0
- data/app/views/layouts/cornerstone/application.html.erb +16 -0
- data/config/cucumber.yml +8 -0
- data/config/locales/cornerstone.action_mailer.en.yml +9 -0
- data/config/routes.rb +24 -0
- data/cornerstone-0.0.1.gem +0 -0
- data/cornerstone.gemspec +33 -0
- data/db/migrate/20110723004024_create_cornerstone_discussions.rb +17 -0
- data/db/migrate/20110804190853_create_cornerstone_categories.rb +15 -0
- data/db/migrate/20110809233551_create_cornerstone_posts.rb +13 -0
- data/db/migrate/20111006172857_create_cornerstone_articles.rb +12 -0
- data/lib/cornerstone.rb +6 -0
- data/lib/cornerstone/acts_as_cornerstone_user.rb +79 -0
- data/lib/cornerstone/config.rb +33 -0
- data/lib/cornerstone/controller_additions.rb +25 -0
- data/lib/cornerstone/engine.rb +8 -1
- data/lib/cornerstone/exceptions.rb +16 -0
- data/lib/cornerstone/helpers.rb +35 -0
- data/lib/tasks/cucumber.rake +65 -0
- data/lib/templates/cornerstone_config.rb +31 -0
- data/script/cucumber +10 -0
- data/script/rails +7 -0
- data/spec/controllers/cornerstone/admin/articles_controller_spec.rb +250 -0
- data/spec/controllers/cornerstone/admin/categories_controller_spec.rb +205 -0
- data/spec/controllers/cornerstone/admin/discussions_controller_spec.rb +95 -0
- data/spec/controllers/cornerstone/application_controller_spec.rb +34 -0
- data/spec/controllers/cornerstone/discussions_controller_spec.rb +157 -0
- data/spec/controllers/cornerstone/help_controller_spec.rb +20 -0
- data/spec/controllers/cornerstone/posts_controller_spec.rb +212 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/javascripts/tester.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/assets/stylesheets/tester.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/tester_controller.rb +7 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/tester_helper.rb +6 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/user.rb +23 -0
- data/spec/dummy/app/views/devise/confirmations/new.html.erb +12 -0
- data/spec/dummy/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/spec/dummy/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/spec/dummy/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/spec/dummy/app/views/devise/passwords/edit.html.erb +16 -0
- data/spec/dummy/app/views/devise/passwords/new.html.erb +12 -0
- data/spec/dummy/app/views/devise/registrations/edit.html.erb +29 -0
- data/spec/dummy/app/views/devise/registrations/new.html.erb +22 -0
- data/spec/dummy/app/views/devise/sessions/new.html.erb +19 -0
- data/spec/dummy/app/views/devise/shared/_links.erb +25 -0
- data/spec/dummy/app/views/devise/unlocks/new.html.erb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/tester/index.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +42 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +28 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +31 -0
- data/spec/dummy/config/environments/production.rb +54 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cornerstone_config.rb +30 -0
- data/spec/dummy/config/initializers/devise.rb +204 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/devise.en.yml +53 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +65 -0
- data/spec/dummy/db/migrate/20110724011421_create_user.rb +11 -0
- data/spec/dummy/db/migrate/20110724194307_devise_create_users.rb +41 -0
- data/spec/dummy/db/migrate/20110804174004_add_name_to_user.rb +5 -0
- data/spec/dummy/db/schema.rb +76 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/functional/tester_controller_test.rb +9 -0
- data/spec/dummy/test/unit/helpers/tester_helper_test.rb +4 -0
- data/spec/fixtures/cornerstone/cornerstone_mailer/new_discussion +3 -0
- data/spec/lib/cornerstone/acts_as_cornerstone_user_spec.rb +56 -0
- data/spec/lib/cornerstone/helpers_spec.rb +32 -0
- data/spec/mailers/cornerstone/cornerstone_mailer_spec.rb +55 -0
- data/spec/models/cornerstone/article_spec.rb +25 -0
- data/spec/models/cornerstone/category_spec.rb +97 -0
- data/spec/models/cornerstone/discussion_spec.rb +243 -0
- data/spec/models/cornerstone/post_observer_spec.rb +65 -0
- data/spec/models/cornerstone/post_spec.rb +210 -0
- data/spec/requests/emails_spec.rb +51 -0
- data/spec/requests/interact_discussions_spec.rb +103 -0
- data/spec/requests/manage_articles_spec.rb +59 -0
- data/spec/requests/manage_categories_spec.rb +64 -0
- data/spec/requests/view_home_spec.rb +26 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/support/devise.rb +4 -0
- data/spec/support/factories.rb +62 -0
- data/spec/support/general_helper_methods.rb +20 -0
- data/spec/support/mailer_macros.rb +15 -0
- data/spec/support/mass_assignment.rb +46 -0
- data/tmp/log/development.log +0 -0
- metadata +301 -20
@@ -0,0 +1,17 @@
|
|
1
|
+
<div class="post">
|
2
|
+
<% if post.created_by?(current_cornerstone_user) %>
|
3
|
+
<div class="actions">
|
4
|
+
<%= link_to "EDIT", edit_discussion_post_path(discussion, post) %> |
|
5
|
+
<%= link_to "REMOVE", [discussion, post], :method => :delete,
|
6
|
+
:confirm => 'Are you sure?' %>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
9
|
+
<div class="author">
|
10
|
+
<span class="author_name"><%= post.author_name %></span>
|
11
|
+
<p class="date"><%= l(post.created_at) %></p>
|
12
|
+
</div>
|
13
|
+
<div class="body">
|
14
|
+
<%= post.body %>
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<h1>Editing Post for <%= @discussion.subject %></h1>
|
2
|
+
|
3
|
+
<%= form_for([@discussion, @post]) do |f| %>
|
4
|
+
<%= render :partial => 'cornerstone/shared/errors',
|
5
|
+
:locals => {:rails_model => @post} %>
|
6
|
+
<%= render :partial => "cornerstone/posts/fields", :locals => {:p => f} %>
|
7
|
+
|
8
|
+
<%= f.submit "Update" %>
|
9
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% if rails_model.errors.any? %>
|
2
|
+
<div id="errors">
|
3
|
+
<span class="error_statement"><%= pluralize(rails_model.errors.size, "error") %> prohibited this <%= rails_model.class.name.downcase %> from being saved</span>
|
4
|
+
<ul>
|
5
|
+
<% rails_model.errors.full_messages.each do |msg| %>
|
6
|
+
<li><%= msg %></li>
|
7
|
+
<% end %>
|
8
|
+
</ul>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
11
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<% if flash[:notice] || flash[:alert] %>
|
2
|
+
<div id="flash_messages">
|
3
|
+
<% if flash[:notice] %>
|
4
|
+
<div id="flash_notice">
|
5
|
+
<%= flash[:notice] %>
|
6
|
+
</div>
|
7
|
+
<% end %>
|
8
|
+
<% if flash[:alert] %>
|
9
|
+
<div id="flash_alert">
|
10
|
+
<%= flash[:alert] %>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
15
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Cornerstone</title>
|
5
|
+
<%= stylesheet_link_tag "cornerstone" %>
|
6
|
+
<%= javascript_include_tag "cornerstone" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= render :partial => "cornerstone/shared/flash_messages" %>
|
12
|
+
<%= yield %>
|
13
|
+
|
14
|
+
</body>
|
15
|
+
</html>
|
16
|
+
|
data/config/cucumber.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<%
|
2
|
+
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
3
|
+
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
4
|
+
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
|
5
|
+
%>
|
6
|
+
default: <%= std_opts %> features
|
7
|
+
wip: --tags @wip:3 --wip features
|
8
|
+
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
|
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Cornerstone::Engine.routes.draw do
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
resources :discussions, :except => [:show] do
|
6
|
+
resources :posts, :only => [:create, :edit, :update, :destroy]
|
7
|
+
end
|
8
|
+
|
9
|
+
# Custom routes to handle show for discussions and discussion categories
|
10
|
+
get "/discussions/:category/:id" => "discussions#show", :as => "category_discussion"
|
11
|
+
get "/discussions/:category" => "discussions#category", :as => "discussions_category"
|
12
|
+
|
13
|
+
|
14
|
+
root :to => "help#index"
|
15
|
+
|
16
|
+
namespace :admin do
|
17
|
+
root :to => "admin#dashboard"
|
18
|
+
resources :categories, :except => :show
|
19
|
+
resources :articles
|
20
|
+
resources :discussions, :only => [:edit, :update]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
Binary file
|
data/cornerstone.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.author = "Adam St. John"
|
3
|
+
s.email = "astjohn@gmail.com"
|
4
|
+
s.date = Date.today.to_s
|
5
|
+
s.name = "cornerstone"
|
6
|
+
s.summary = "A rails engine for customer care."
|
7
|
+
s.description = "Cornerstone provides customer care capabilities to an existing" \
|
8
|
+
" application by adding things like discussions and a knowledge base."
|
9
|
+
s.homepage = "https://github.com/astjohn/cornerstone"
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.version = IO.read(File.join(File.dirname(__FILE__), 'VERSION'))
|
13
|
+
|
14
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
|
18
|
+
s.add_dependency('rails', '>= 3.1.0')
|
19
|
+
s.add_dependency('i18n')
|
20
|
+
|
21
|
+
s.add_development_dependency('bundler', '~> 1.0.0')
|
22
|
+
s.add_development_dependency('sqlite3')
|
23
|
+
s.add_development_dependency('rspec-rails')
|
24
|
+
s.add_development_dependency('factory_girl_rails')
|
25
|
+
s.add_development_dependency('devise')
|
26
|
+
s.add_development_dependency('capybara')
|
27
|
+
s.add_development_dependency('launchy')
|
28
|
+
s.add_development_dependency('guard-rspec')
|
29
|
+
s.add_development_dependency('libnotify')
|
30
|
+
s.add_development_dependency('rb-inotify')
|
31
|
+
s.add_development_dependency('database_cleaner')
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateCornerstoneDiscussions < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :cornerstone_discussions do |t|
|
4
|
+
t.integer :user_id
|
5
|
+
t.integer :category_id
|
6
|
+
t.string :subject
|
7
|
+
t.string :status, :default => Cornerstone::Config.discussion_statuses.first
|
8
|
+
t.boolean :privte, :default => 0
|
9
|
+
t.integer :reply_count, :default => 0
|
10
|
+
t.string :latest_post_author
|
11
|
+
t.datetime :latest_post_date
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateCornerstoneCategories < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :cornerstone_categories do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :category_type
|
6
|
+
t.text :description
|
7
|
+
t.integer :item_count, :default => 0
|
8
|
+
t.string :latest_discussion_author
|
9
|
+
t.datetime :latest_discussion_date
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
data/lib/cornerstone.rb
CHANGED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Cornerstone
|
2
|
+
|
3
|
+
module ActsAsCornerstoneUser
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
userclass = self.name
|
9
|
+
|
10
|
+
# == Associations
|
11
|
+
has_many :cornerstone_discussions, :foreign_key => :user_id,
|
12
|
+
:class_name => "::Cornerstone::Discussion"
|
13
|
+
has_many :cornerstone_posts, :foreign_key => :user_id,
|
14
|
+
:class_name => "::Cornerstone::Post"
|
15
|
+
|
16
|
+
# TODO: dependent destroy? - how to handle when user account deleted?
|
17
|
+
# - perhaps this can be an option specified in initializer
|
18
|
+
|
19
|
+
# == Accessibility
|
20
|
+
cattr_accessor :cornerstone_name_method, :cornerstone_email_method,
|
21
|
+
:cornerstone_admin
|
22
|
+
|
23
|
+
# TODO: Might need support for multiple user models such as AdminUser... etc.
|
24
|
+
# send belongs_to user relationships
|
25
|
+
Cornerstone::Discussion.send(:belongs_to, :user, :class_name => userclass)
|
26
|
+
Cornerstone::Post.send(:belongs_to, :user, :class_name => userclass)
|
27
|
+
end
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
|
31
|
+
# Method placed within User model of parent application and used to set
|
32
|
+
# Cornerstone options for the model.
|
33
|
+
def acts_as_cornerstone_user(options = {})
|
34
|
+
# == Options
|
35
|
+
|
36
|
+
# TODO: CHECK that the methods given actually exist and raise error if not
|
37
|
+
# CHECK that values given are good types
|
38
|
+
self.cornerstone_name_method = options[:user_name] if options[:user_name]
|
39
|
+
self.cornerstone_email_method = options[:user_email] if options[:user_email]
|
40
|
+
self.cornerstone_admin = options[:admin] if options[:admin]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module InstanceMethods
|
45
|
+
|
46
|
+
# return the user's name
|
47
|
+
def cornerstone_name
|
48
|
+
if self.cornerstone_name_method.present?
|
49
|
+
self.send(self.cornerstone_name_method)
|
50
|
+
else
|
51
|
+
"Not Available"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# return the user's email
|
56
|
+
def cornerstone_email
|
57
|
+
if self.cornerstone_email_method.present?
|
58
|
+
self.send(self.cornerstone_email_method)
|
59
|
+
else
|
60
|
+
"Not Available"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Return true if this user is an administrator
|
65
|
+
def cornerstone_admin?
|
66
|
+
case
|
67
|
+
when self.cornerstone_admin.is_a?(TrueClass)
|
68
|
+
true
|
69
|
+
when self.cornerstone_admin.respond_to?(:call)
|
70
|
+
self.cornerstone_admin.call
|
71
|
+
else
|
72
|
+
false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Cornerstone
|
2
|
+
|
3
|
+
# This module stores configuration options for Cornerstone
|
4
|
+
module Config
|
5
|
+
|
6
|
+
# Configure Cornerstone. Run rails generate cornerstone_install to create
|
7
|
+
# a fresh initializer with all configuration values.
|
8
|
+
def self.setup
|
9
|
+
yield self
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# == User specified options
|
14
|
+
|
15
|
+
# The method used to access the authenticated user
|
16
|
+
mattr_accessor :auth_with
|
17
|
+
@@auth_with = :warden
|
18
|
+
|
19
|
+
# Discussion Statuses
|
20
|
+
mattr_accessor :discussion_statuses
|
21
|
+
@@discussion_statuses = ["Open", "Resolved"]
|
22
|
+
|
23
|
+
# Mailer 'from' address
|
24
|
+
mattr_accessor :mailer_from
|
25
|
+
@@mailer_from = "no-reply@cornerstone.com"
|
26
|
+
|
27
|
+
# List of admin emails
|
28
|
+
mattr_accessor :admin_emails
|
29
|
+
@@admin_emails = []
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Cornerstone
|
2
|
+
|
3
|
+
# Convenience methods added to ApplicationController.
|
4
|
+
module ControllerAdditions
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
# Returns true if user is authorized for controller action, otherwise
|
12
|
+
# raise error
|
13
|
+
def authorize_cornerstone_admin!(*args)
|
14
|
+
self.before_filter(*args) do |controller|
|
15
|
+
raise Cornerstone::AccessDenied unless cornerstone_admin?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
ActionController::Base.send :include, Cornerstone::ControllerAdditions
|
23
|
+
|
24
|
+
end
|
25
|
+
|
data/lib/cornerstone/engine.rb
CHANGED
@@ -2,6 +2,13 @@ module Cornerstone
|
|
2
2
|
class Engine < Rails::Engine
|
3
3
|
engine_name "cornerstone"
|
4
4
|
isolate_namespace Cornerstone
|
5
|
+
|
6
|
+
config.generators do |g|
|
7
|
+
g.template_engine :erb
|
8
|
+
g.test_framework :rspec
|
9
|
+
end
|
10
|
+
|
11
|
+
config.active_record.observers = :"cornerstone/post_observer"
|
12
|
+
|
5
13
|
end
|
6
14
|
end
|
7
|
-
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Cornerstone
|
2
|
+
|
3
|
+
class AccessDenied < StandardError
|
4
|
+
attr_writer :default_message
|
5
|
+
|
6
|
+
def initialize(message = nil)
|
7
|
+
@message = message
|
8
|
+
@default_message = I18n.t(:"unauthorized.default", :default => "You are not authorized to access this page.")
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
@message || @default_message
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Cornerstone
|
2
|
+
|
3
|
+
# Convenience methods added to ApplicationController.
|
4
|
+
module Helpers
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
helper_method :current_cornerstone_user, :cornerstone_admin?
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
|
13
|
+
# To determine if a user from the main application is signed in
|
14
|
+
# Returns the user object or nil
|
15
|
+
def current_cornerstone_user
|
16
|
+
if Config.auth_with == :warden
|
17
|
+
env['warden'].user if env['warden']
|
18
|
+
elsif Config.auth_with.respond_to?(:call)
|
19
|
+
Config.auth_with.call(self)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return true if cornerstone_user is an administrator
|
24
|
+
def cornerstone_admin?
|
25
|
+
current_cornerstone_user && current_cornerstone_user.cornerstone_admin?
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
ActionController::Base.send :include, Cornerstone::Helpers
|
33
|
+
|
34
|
+
end
|
35
|
+
|