This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
2,229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
log/*.log | ||
tmp/**/* | ||
.DS_Store | ||
config/database.yml | ||
db/schema.rb | ||
db/*.sqlite3 | ||
db/development_structure.sql | ||
*~ | ||
cache | ||
.*.swp | ||
.*.swo | ||
nbproject/ | ||
spec/spec.opts.netbeans | ||
public/content_page_assets/ | ||
public/wiki_page_assets/ | ||
public/user_assets/ | ||
public/themes | ||
public/images/favorite.png | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# Filters added to this controller apply to all controllers in the application. | ||
# Likewise, all the methods added will be available for all controllers. | ||
|
||
class ApplicationController < ActionController::Base | ||
include ExceptionNotifiable | ||
|
||
helper :all | ||
helper_method :current_user_session, :current_user | ||
filter_parameter_logging :password, :password_confirmation | ||
|
||
before_filter :get_menus, :get_layout | ||
|
||
|
||
# checks to see if user is a member of a given access group - if not, | ||
# redirect to account controller | ||
# for multiple groups, if user is in any of the given groups, they have access | ||
def require_group_access(group_access_list) | ||
if require_user | ||
group_access_list = [group_access_list] unless group_access_list.is_a? Array | ||
in_a_group = group_access_list.inject(false) { |n,m| n or current_user.has_group_access?(m) } | ||
unless in_a_group | ||
store_location | ||
flash[:notice] = "You must be a member of one of a group with access of: #{group_access_list.join(" or ")}." | ||
redirect_to account_url | ||
end | ||
return in_a_group | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def require_forum_read_access | ||
if require_user | ||
unless current_user.has_read_access_to?(@forum) | ||
flash[:notice] = "You do not have permission to view that forum." | ||
redirect_to forums_url | ||
end | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def require_forum_write_access | ||
if require_user | ||
unless current_user.has_write_access_to?(@forum) | ||
flash[:notice] = "You do not have post or edit in that forum." | ||
redirect_to forums_url | ||
end | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def require_wiki_read_access | ||
if require_user | ||
unless current_user.has_read_access_to?(@wiki) | ||
flash[:notice] = "You do not have permission to view that wiki." | ||
redirect_to wikis_url | ||
end | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def require_wiki_write_access | ||
if require_user | ||
unless current_user.has_write_access_to?(@wiki) | ||
flash[:notice] = "You do not have permission to edit that wiki." | ||
redirect_to wikis_url | ||
end | ||
else | ||
return false | ||
end | ||
end | ||
|
||
private | ||
def get_menus | ||
@side_menu = ContentPage.get_side_menu | ||
@top_menu = ContentPage.get_top_menu | ||
end | ||
|
||
def get_layout | ||
@theme_base = SiteSetting.read_or_write_default_setting 'theme base', 'default' | ||
@theme_layout = SiteSetting.read_or_write_default_setting 'theme layout', 'default' | ||
@layout_file = File.join(RAILS_ROOT, "/themes/layouts/#{@theme_layout}.html.erb") | ||
@theme_colors = SiteSetting.read_or_write_default_setting 'theme colors', 'black and white' | ||
@custom_colors_timestamp = SiteSetting.read_or_write_default_setting 'custom colors timestamp', nil | ||
@css_override = SiteSetting.read_or_write_default_setting 'css override', nil | ||
@css_override_timestamp = SiteSetting.read_or_write_default_setting 'css override timestamp', nil | ||
end | ||
|
||
def current_user_session | ||
return @current_user_session if defined?(@current_user_session) | ||
@current_user_session = UserSession.find | ||
end | ||
|
||
def current_user | ||
return @current_user if defined?(@current_user) | ||
@current_user = current_user_session && current_user_session.record | ||
end | ||
|
||
def require_user | ||
if current_user | ||
true | ||
else | ||
store_location | ||
flash[:warning] = "You must be logged in to access this page." | ||
redirect_to login_path | ||
false | ||
end | ||
end | ||
|
||
def require_admin_user | ||
unless current_user and current_user.is_admin? | ||
flash[:error] = "You do not have permission to access that page." | ||
redirect_to login_path | ||
return false | ||
end | ||
end | ||
|
||
def require_moderator_user | ||
get_forum | ||
unless current_user and current_user.is_moderator_for_forum?(@forum) | ||
flash[:error] = "You do not have permission to access that page." | ||
redirect_to '/' | ||
return false | ||
end | ||
end | ||
|
||
def require_no_user | ||
if current_user | ||
store_location | ||
flash[:warning] = "You must be logged out to access this page." | ||
redirect_to account_url | ||
return false | ||
end | ||
end | ||
|
||
def store_location | ||
session[:return_to] = request.request_uri | ||
end | ||
|
||
def redirect_back_or_default(default) | ||
redirect_to(session[:return_to] || default) | ||
session[:return_to] = nil | ||
end | ||
|
||
# takes a file upload object and the relative directory to save it to | ||
# returns the relative location of the uploaded file | ||
def write_file(uploaded_file, rel_dir) | ||
file_name = uploaded_file.original_filename | ||
actual_dir = File.join(RAILS_ROOT, 'public', rel_dir) | ||
FileUtils.mkdir_p actual_dir | ||
File.open(File.join(actual_dir, file_name), 'wb') do |f| | ||
f.write(uploaded_file.read) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Methods added to this helper will be available to all templates in the application. | ||
module ApplicationHelper | ||
|
||
def top_menu | ||
@top_menu ? @top_menu.body_for_display : "TODO: create the top menu" | ||
end | ||
|
||
def side_menu | ||
@side_menu ? @side_menu.body_for_display : "TODO: create the side menu" | ||
end | ||
|
||
def logo_image | ||
image_tag(site_logo) | ||
end | ||
|
||
def site_title | ||
@site_title ||= SiteSetting.read_setting('site title') || "A Site" | ||
end | ||
|
||
def page_title | ||
pre = case action_name | ||
when "edit" then "Editing " | ||
when "new" then "Creating " | ||
else | ||
"" | ||
end | ||
if @content_page | ||
"#{pre}#{@content_page.name}" | ||
elsif @category | ||
"#{pre}Category: #{@category.name}" | ||
elsif @wiki_page | ||
"#{pre}Wiki Page: #{@wiki_page.title}" | ||
elsif @wiki_tag | ||
"#{pre}Wiki Tag: #{@wiki_tag.name}" | ||
elsif @wiki | ||
"#{pre}Wiki: #{@wiki.name}" | ||
elsif @message_post | ||
"#{pre}Message Post: #{@message_post.subject}" | ||
elsif @forum | ||
"#{pre}Forum: #{@forum.title}" | ||
elsif @user | ||
"#{pre}User: #{@user.login}" | ||
elsif @user_group | ||
"#{pre}User Group: #{@user_group.name}" | ||
else | ||
controller_name.titleize | ||
end | ||
end | ||
|
||
def site_logo | ||
@site_logo ||= SiteSetting.read_setting('site logo') || "GenericLogo.png" | ||
end | ||
|
||
def site_footer | ||
@site_footer ||= SiteSetting.read_setting('site footer') || | ||
"Content on this site is the copyright of the owners of #{request.host} and is provided as-is without warranty." | ||
end | ||
|
||
def user_box | ||
#out = "#{pluralize User.logged_in.count, 'user'} currently logged in<br />\n" | ||
out = "" | ||
|
||
if current_user | ||
out += "Welcome, #{current_user.first_name}!<br />\n" | ||
out += link_to("My Account", account_path) + " | " + | ||
link_to("Logout", user_session_path, :method => :delete, | ||
:confirm => "Are you sure you want to logout?") | ||
out += "<br/>" | ||
other_links = [] | ||
other_links << link_to('Site Admin', admin_site_settings_path) if current_user.is_admin? | ||
if current_user.has_access_to_any_wikis? | ||
if current_user.wikis.size == 1 | ||
other_links << link_to('Wiki', current_user.wikis.first) | ||
else | ||
other_links << link_to('Wikis', wikis_path) | ||
end | ||
end | ||
if current_user.has_access_to_any_forums? | ||
if current_user.forums.size == 1 | ||
other_links << link_to('Forum', current_user.forums.first) | ||
else | ||
other_links << link_to('Forums', forums_path) | ||
end | ||
end | ||
out += other_links.join(' | ') | ||
else | ||
out += link_to("Register", new_account_path) + " | " + | ||
link_to( "Log In", new_user_session_path) | ||
end | ||
out | ||
end | ||
|
||
def images_list | ||
Dir[File.join(RAILS_ROOT, 'public', 'images', "*.{png,jpg,gif}")].map { |f| File.basename f }.sort | ||
end | ||
|
||
def theme_layouts_list | ||
Dir[File.join(RAILS_ROOT, 'themes', 'layouts', "*.html.erb")].map { |f| File.basename(f, '.html.erb') }.sort | ||
end | ||
|
||
def is_admin? | ||
current_user and current_user.is_admin? | ||
end | ||
|
||
# TODO: change this to use the zoned plugin or something | ||
def post_time(time) | ||
if (Time.now - time) > 2600000 | ||
time.strftime "on %b %d, %Y" | ||
else | ||
time_ago_in_words(time) + " ago" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# SQLite version 3.x | ||
# gem install sqlite3-ruby (not necessary on OS X Leopard) | ||
development: | ||
adapter: sqlite3 | ||
database: db/development.sqlite3 | ||
pool: 5 | ||
timeout: 5000 | ||
|
||
# Warning: The database defined as "test" will be erased and | ||
# re-generated from your development database when you run "rake". | ||
# Do not set this db to the same as development or production. | ||
test: | ||
adapter: sqlite3 | ||
database: db/test.sqlite3 | ||
pool: 5 | ||
timeout: 5000 | ||
|
||
production: | ||
adapter: sqlite3 | ||
database: db/production.sqlite3 | ||
pool: 5 | ||
timeout: 5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Be sure to restart your server when you modify this file | ||
|
||
# Uncomment below to force Rails into production mode when | ||
# you don't control web/app server and can't set it the proper way | ||
# ENV['RAILS_ENV'] ||= 'production' | ||
|
||
# Specifies gem version of Rails to use when vendor/rails is not present | ||
RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION | ||
|
||
# Bootstrap the Rails environment, frameworks, and default configuration | ||
require File.join(File.dirname(__FILE__), 'boot') | ||
|
||
Rails::Initializer.run do |config| | ||
# Settings in config/environments/* take precedence over those specified here. | ||
# Application configuration should go into files in config/initializers | ||
# -- all .rb files in that directory are automatically loaded. | ||
# See Rails::Configuration for more options. | ||
|
||
# Skip frameworks you're not going to use. To use Rails without a database | ||
# you must remove the Active Record framework. | ||
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ] | ||
|
||
# Specify gems that this application depends on. | ||
# They can then be installed with "rake gems:install" on new installations. | ||
# config.gem "bj" | ||
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" | ||
# config.gem "aws-s3", :lib => "aws/s3" | ||
config.gem "RedCloth" | ||
config.gem "authlogic" | ||
config.gem "authlogic-oid", :lib => "authlogic_openid" | ||
config.gem "ruby-openid", :lib => "openid" | ||
config.gem "rspec", :lib => false, :version => ">= 1.2.0" | ||
config.gem "rspec-rails", :lib => false, :version => ">= 1.2.0" | ||
config.gem 'will_paginate', :version => '~> 2.3.11', :source => 'http://gemcutter.org' | ||
config.gem "factory_girl", :source => "http://gemcutter.org", :version => '>= 1.2.4' | ||
|
||
# Only load the plugins named here, in the order given. By default, all plugins | ||
# in vendor/plugins are loaded in alphabetical order. | ||
# :all can be used as a placeholder for all plugins not explicitly named | ||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ] | ||
|
||
# Add additional load paths for your own custom dirs | ||
# config.load_paths += %W( #{RAILS_ROOT}/extras ) | ||
|
||
# Force all environments to use the same logger level | ||
# (by default production uses :info, the others :debug) | ||
# config.log_level = :debug | ||
|
||
# Make Time.zone default to the specified zone, and make Active Record store time values | ||
# in the database in UTC, and return them converted to the specified local zone. | ||
# Run "rake -D time" for a list of tasks for finding time zone names. Comment line to use default local time. | ||
config.time_zone = 'UTC' | ||
|
||
# Your secret key for verifying cookie session data integrity. | ||
# If you change this key, all old sessions will become invalid! | ||
# Make sure the secret is at least 30 characters and all random, | ||
# no regular words or you'll be exposed to dictionary attacks. | ||
config.action_controller.session = { | ||
:key => '_site_on_rails_session', | ||
:secret => '42b1a00f9cc222749e00675885e0ff4a2de996cd1586e15cfcb7fa34a76a8e8423f8217986b675df3f1c28c056455fc63d6f98eee85c176b377988b5b72ef15d' | ||
} | ||
|
||
# Use the database for sessions instead of the cookie-based default, | ||
# which shouldn't be used to store highly confidential information | ||
# (create the session table with "rake db:sessions:create") | ||
#config.action_controller.session_store = :active_record_store | ||
|
||
# Use SQL instead of Active Record's schema dumper when creating the test database. | ||
# This is necessary if your schema can't be completely dumped by the schema dumper, | ||
# like if you have constraints or database-specific column types | ||
# config.active_record.schema_format = :sql | ||
|
||
# Activate observers that should always be running | ||
config.active_record.observers = [:wiki_page_observer, :user_observer] | ||
end |
Oops, something went wrong.