radiant-basic_page_auth-extension 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +37 -0
- data/Rakefile +109 -0
- data/basic_page_auth_extension.rb +14 -0
- data/lib/radiant-basic_page_auth-extension.rb +8 -0
- data/lib/radiant-basic_page_auth-extension/page.rb +53 -0
- data/lib/radiant-basic_page_auth-extension/site_controller.rb +33 -0
- data/lib/tasks/basic_page_auth_extension_tasks.rake +55 -0
- data/radiant-basic_page_auth-extension.gemspec +28 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +36 -0
- metadata +78 -0
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Basic Page Auth
|
2
|
+
|
3
|
+
Protect a page's contents with HTTP Basic Authentication. The user, password, and realm are set up by adding the following Fields to a page:
|
4
|
+
|
5
|
+
User (required)
|
6
|
+
Password (required)
|
7
|
+
Realm (optional)
|
8
|
+
|
9
|
+
Realm defaults to the page slug. If set to "true" it will use Radiant::Config['site.title'], otherwise set your own value.
|
10
|
+
|
11
|
+
|
12
|
+
## TODO
|
13
|
+
|
14
|
+
- Write some tests
|
15
|
+
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
This has only been tested on Radiant v1.0.0.rc2 +
|
20
|
+
|
21
|
+
Install as a gem :
|
22
|
+
|
23
|
+
```
|
24
|
+
gem install radiant-basic_page_auth-extension
|
25
|
+
```
|
26
|
+
|
27
|
+
Include the gem in your environment.rb :
|
28
|
+
|
29
|
+
```
|
30
|
+
config.gem 'radiant-basic_page_auth-extension', :version => '~> 1.0.0'
|
31
|
+
```
|
32
|
+
|
33
|
+
Run the update task :
|
34
|
+
|
35
|
+
```
|
36
|
+
rake radiant:extensions:filter_toolbars:update
|
37
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Determine where the RSpec plugin is by loading the boot
|
2
|
+
unless defined? RADIANT_ROOT
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
4
|
+
case
|
5
|
+
when ENV["RADIANT_ENV_FILE"]
|
6
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
7
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
8
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
9
|
+
else
|
10
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rake'
|
15
|
+
require 'rake/rdoctask'
|
16
|
+
require 'rake/testtask'
|
17
|
+
|
18
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
19
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
require 'cucumber'
|
22
|
+
require 'cucumber/rake/task'
|
23
|
+
|
24
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
25
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
26
|
+
|
27
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
28
|
+
|
29
|
+
task :default => [:spec, :features]
|
30
|
+
task :stats => "spec:statsetup"
|
31
|
+
|
32
|
+
desc "Run all specs in spec directory"
|
33
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
34
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
35
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
task :features => 'spec:integration'
|
39
|
+
|
40
|
+
namespace :spec do
|
41
|
+
desc "Run all specs in spec directory with RCov"
|
42
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
43
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
44
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
45
|
+
t.rcov = true
|
46
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Print Specdoc for all specs"
|
50
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
51
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
52
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
53
|
+
end
|
54
|
+
|
55
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
56
|
+
desc "Run the specs under spec/#{sub}"
|
57
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
58
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
59
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "Run the Cucumber features"
|
64
|
+
Cucumber::Rake::Task.new(:integration) do |t|
|
65
|
+
t.fork = true
|
66
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
67
|
+
# t.feature_pattern = "#{extension_root}/features/**/*.feature"
|
68
|
+
t.profile = "default"
|
69
|
+
end
|
70
|
+
|
71
|
+
# Setup specs for stats
|
72
|
+
task :statsetup do
|
73
|
+
require 'code_statistics'
|
74
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
75
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
76
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
77
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
78
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
79
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
80
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
81
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
82
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
83
|
+
end
|
84
|
+
|
85
|
+
namespace :db do
|
86
|
+
namespace :fixtures do
|
87
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
88
|
+
task :load => :environment do
|
89
|
+
require 'active_record/fixtures'
|
90
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
91
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
92
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
desc 'Generate documentation for the basic_page_auth extension.'
|
100
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
101
|
+
rdoc.rdoc_dir = 'rdoc'
|
102
|
+
rdoc.title = 'BasicPageAuthExtension'
|
103
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
104
|
+
rdoc.rdoc_files.include('README')
|
105
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
106
|
+
end
|
107
|
+
|
108
|
+
# Load any custom rakefiles for extension
|
109
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'radiant-basic_page_auth-extension'
|
2
|
+
require 'radiant-basic_page_auth-extension/page'
|
3
|
+
require 'radiant-basic_page_auth-extension/site_controller'
|
4
|
+
|
5
|
+
class BasicPageAuthExtension < Radiant::Extension
|
6
|
+
version RadiantBasicPageAuthExtension::VERSION
|
7
|
+
description RadiantBasicPageAuthExtension::DESCRIPTION
|
8
|
+
url RadiantBasicPageAuthExtension::URL
|
9
|
+
|
10
|
+
def activate
|
11
|
+
Page.send :include, RadiantBasicPageAuthExtension::Page
|
12
|
+
SiteController.send :include, RadiantBasicPageAuthExtension::SiteController
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module RadiantBasicPageAuthExtension
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
SUMMARY = %q{HTTP Basic Authentication for Radiant CMS}
|
4
|
+
DESCRIPTION = %{Protect a page's contents with HTTP Basic Authentication.}
|
5
|
+
URL = "https://github.com/jsntv200/radiant-basic_page_auth-extension"
|
6
|
+
AUTHORS = ["Jason Taylor"]
|
7
|
+
EMAIL = ["jsntv200@gmail.com"]
|
8
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module RadiantBasicPageAuthExtension
|
2
|
+
module Page
|
3
|
+
def self.included(base)
|
4
|
+
base.instance_eval {
|
5
|
+
include InstanceMethods
|
6
|
+
}
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
def protected?
|
11
|
+
self.basic_auth_user && self.basic_auth_pass
|
12
|
+
end
|
13
|
+
|
14
|
+
def basic_auth_user
|
15
|
+
user = self.basic_auth_field('User')
|
16
|
+
|
17
|
+
if user && user.content.present?
|
18
|
+
user.content
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def basic_auth_pass
|
23
|
+
pass = self.basic_auth_field('Password')
|
24
|
+
|
25
|
+
if pass && pass.content.present?
|
26
|
+
pass.content
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def basic_auth_realm
|
31
|
+
realm = self.basic_auth_field('Realm')
|
32
|
+
|
33
|
+
if realm && realm.content.present?
|
34
|
+
realm = realm.content
|
35
|
+
|
36
|
+
if realm === 'true'
|
37
|
+
realm = Radiant::Config['site.title']
|
38
|
+
end
|
39
|
+
|
40
|
+
realm
|
41
|
+
else
|
42
|
+
realm = self.slug
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def basic_auth_field(name)
|
47
|
+
self.fields.detect { |f| f.name.downcase == name.to_s.downcase }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module RadiantBasicPageAuthExtension
|
2
|
+
module SiteController
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval {
|
5
|
+
include ClassMethods
|
6
|
+
alias_method_chain :process_page, :basic_auth
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
private
|
12
|
+
|
13
|
+
def process_page_with_basic_auth(page)
|
14
|
+
if page.protected?
|
15
|
+
if authenticate_with_http_basic { |u, p| u == page.basic_auth_user && p == page.basic_auth_pass }
|
16
|
+
page.instance_eval do
|
17
|
+
def cache?
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
process_page_without_basic_auth(page)
|
23
|
+
else
|
24
|
+
request_http_basic_authentication(page.basic_auth_realm)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
process_page_without_basic_auth(page)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
namespace :radiant do
|
2
|
+
namespace :extensions do
|
3
|
+
namespace :basic_page_auth do
|
4
|
+
|
5
|
+
desc "Runs the migration of the Basic Page Auth extension"
|
6
|
+
task :migrate => :environment do
|
7
|
+
require 'radiant/extension_migrator'
|
8
|
+
if ENV["VERSION"]
|
9
|
+
BasicPageAuthExtension.migrator.migrate(ENV["VERSION"].to_i)
|
10
|
+
Rake::Task['db:schema:dump'].invoke
|
11
|
+
else
|
12
|
+
BasicPageAuthExtension.migrator.migrate
|
13
|
+
Rake::Task['db:schema:dump'].invoke
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies public assets of the Basic Page Auth to the instance public/ directory."
|
18
|
+
task :update => :environment do
|
19
|
+
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
|
20
|
+
puts "Copying assets from BasicPageAuthExtension"
|
21
|
+
Dir[BasicPageAuthExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
|
22
|
+
path = file.sub(BasicPageAuthExtension.root, '')
|
23
|
+
directory = File.dirname(path)
|
24
|
+
mkdir_p RAILS_ROOT + directory, :verbose => false
|
25
|
+
cp file, RAILS_ROOT + path, :verbose => false
|
26
|
+
end
|
27
|
+
unless BasicPageAuthExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
|
28
|
+
puts "Copying rake tasks from BasicPageAuthExtension"
|
29
|
+
local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
|
30
|
+
mkdir_p local_tasks_path, :verbose => false
|
31
|
+
Dir[File.join BasicPageAuthExtension.root, %w(lib tasks *.rake)].each do |file|
|
32
|
+
cp file, local_tasks_path, :verbose => false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Syncs all available translations for this ext to the English ext master"
|
38
|
+
task :sync => :environment do
|
39
|
+
# The main translation root, basically where English is kept
|
40
|
+
language_root = BasicPageAuthExtension.root + "/config/locales"
|
41
|
+
words = TranslationSupport.get_translation_keys(language_root)
|
42
|
+
|
43
|
+
Dir["#{language_root}/*.yml"].each do |filename|
|
44
|
+
next if filename.match('_available_tags')
|
45
|
+
basename = File.basename(filename, '.yml')
|
46
|
+
puts "Syncing #{basename}"
|
47
|
+
(comments, other) = TranslationSupport.read_file(filename, basename)
|
48
|
+
words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
|
49
|
+
other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
|
50
|
+
TranslationSupport.write_file(filename, basename, comments, other)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "radiant-basic_page_auth-extension"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "radiant-basic_page_auth-extension"
|
7
|
+
s.version = RadiantBasicPageAuthExtension::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = RadiantBasicPageAuthExtension::AUTHORS
|
10
|
+
s.email = RadiantBasicPageAuthExtension::EMAIL
|
11
|
+
s.homepage = RadiantBasicPageAuthExtension::URL
|
12
|
+
s.summary = RadiantBasicPageAuthExtension::SUMMARY
|
13
|
+
s.description = RadiantBasicPageAuthExtension::DESCRIPTION
|
14
|
+
|
15
|
+
ignores = if File.exist?('.gitignore')
|
16
|
+
File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
|
17
|
+
else
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
s.files = Dir['**/*'] - ignores
|
21
|
+
s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
s.post_install_message = %{
|
25
|
+
Add this to your radiant project with:
|
26
|
+
config.gem 'radiant-basic_page_auth-extension', :version => '~> #{RadiantBasicPageAuthExtension::VERSION}'
|
27
|
+
}
|
28
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
unless defined? RADIANT_ROOT
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
case
|
4
|
+
when ENV["RADIANT_ENV_FILE"]
|
5
|
+
require ENV["RADIANT_ENV_FILE"]
|
6
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
8
|
+
else
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
require "#{RADIANT_ROOT}/spec/spec_helper"
|
13
|
+
|
14
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
15
|
+
|
16
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
17
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
18
|
+
end
|
19
|
+
|
20
|
+
Spec::Runner.configure do |config|
|
21
|
+
# config.use_transactional_fixtures = true
|
22
|
+
# config.use_instantiated_fixtures = false
|
23
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
24
|
+
|
25
|
+
# You can declare fixtures for each behaviour like this:
|
26
|
+
# describe "...." do
|
27
|
+
# fixtures :table_a, :table_b
|
28
|
+
#
|
29
|
+
# Alternatively, if you prefer to declare them only once, you can
|
30
|
+
# do so here, like so ...
|
31
|
+
#
|
32
|
+
# config.global_fixtures = :table_a, :table_b
|
33
|
+
#
|
34
|
+
# If you declare global fixtures, be aware that they will be declared
|
35
|
+
# for all of your examples, even those that don't use them.
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radiant-basic_page_auth-extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jason Taylor
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-29 00:00:00 +10:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Protect a page's contents with HTTP Basic Authentication.
|
23
|
+
email:
|
24
|
+
- jsntv200@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- basic_page_auth_extension.rb
|
33
|
+
- lib/radiant-basic_page_auth-extension/page.rb
|
34
|
+
- lib/radiant-basic_page_auth-extension/site_controller.rb
|
35
|
+
- lib/radiant-basic_page_auth-extension.rb
|
36
|
+
- lib/tasks/basic_page_auth_extension_tasks.rake
|
37
|
+
- radiant-basic_page_auth-extension.gemspec
|
38
|
+
- Rakefile
|
39
|
+
- README.md
|
40
|
+
- spec/spec.opts
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: https://github.com/jsntv200/radiant-basic_page_auth-extension
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-basic_page_auth-extension', :version => '~> 1.0.0'\n "
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.5.0
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: HTTP Basic Authentication for Radiant CMS
|
76
|
+
test_files:
|
77
|
+
- spec/spec.opts
|
78
|
+
- spec/spec_helper.rb
|