Browse Source

permission-aware wiring

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
79bc417fab
  1. 3
      app/controllers/aaaas_controller.rb
  2. 3
      app/controllers/as_controller.rb
  3. 3
      app/controllers/cnames_controller.rb
  4. 3
      app/controllers/mxes_controller.rb
  5. 3
      app/controllers/ns_controller.rb
  6. 3
      app/controllers/records_controller.rb
  7. 3
      app/controllers/soas_controller.rb
  8. 3
      app/controllers/srvs_controller.rb
  9. 3
      app/controllers/txts_controller.rb
  10. 4
      app/models/domain.rb
  11. 3
      app/models/record.rb
  12. 16
      spec/controllers/hosts_controller_spec.rb
  13. 1
      spec/controllers/records_controller_spec.rb
  14. 25
      spec/support/shared_examples/wiring_controller.rb

3
app/controllers/aaaas_controller.rb

@ -27,7 +27,8 @@ class AaaasController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/as_controller.rb

@ -28,7 +28,8 @@ class AsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/cnames_controller.rb

@ -27,7 +27,8 @@ class CnamesController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/mxes_controller.rb

@ -35,7 +35,8 @@ class MxesController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/ns_controller.rb

@ -28,7 +28,8 @@ class NsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/records_controller.rb

@ -55,7 +55,8 @@ class RecordsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
end

3
app/controllers/soas_controller.rb

@ -23,7 +23,8 @@ class SoasController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/srvs_controller.rb

@ -32,7 +32,8 @@ class SrvsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/txts_controller.rb

@ -27,7 +27,8 @@ class TxtsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

4
app/models/domain.rb

@ -116,6 +116,10 @@ class Domain < ActiveRecord::Base
scope :host_domains, where(:name => Settings.host_domains)
def host_domain?
Settings.host_domains.include?(name)
end
def setup(email)
build_soa_record
soa = soa_record

3
app/models/record.rb

@ -50,6 +50,9 @@ class Record < ActiveRecord::Base
end
end
delegate :host_domain?, :to => :domain
delegate :user, :to => :domain, :prefix => :domain
protected
def prepare_name!

16
spec/controllers/hosts_controller_spec.rb

@ -1,7 +1,21 @@
require 'spec_helper'
describe HostsController do
it_should_behave_like "wiring controller"
include_context "data"
before do
sign_in user
@controller.stub(:nested_parent_record => host_domain)
end
it "#new_model is wired" do
@controller.send(:new_model).user.should == user
end
it "#before_create_save wires" do
@controller.send(:before_create_save, host_a_record)
host_a_record.user.should == user
end
end
# TODO implement me

1
spec/controllers/records_controller_spec.rb

@ -8,7 +8,6 @@ describe RecordsController do
before do
sign_in user
controller.stub(:current_user).and_return(user)
end
it "modifies @record when IP given" do

25
spec/support/shared_examples/wiring_controller.rb

@ -1,21 +1,40 @@
shared_examples_for "wiring controller" do
context "wiring" do
include_context "data"
let(:record){Record.new}
context "on owned domain" do
before do
sign_in user
@controller.stub(:nested_parent_record => domain)
end
it "#new_model is wired" do
@controller.send(:new_model).user.should == user
@controller.send(:new_model).user.should == domain.user
end
it "#before_create_save wires" do
@controller.send(:before_create_save, record)
record.user.should == user
record.user.should == domain.user
end
end
context "on permitted domain" do
before do
sign_in other_user
permission # touch to ensure creation
@controller.stub(:nested_parent_record => domain)
end
it "#new_model is wired" do
@controller.send(:new_model).user.should == domain.user
end
it "#before_create_save wires" do
@controller.send(:before_create_save, record)
record.user.should == domain.user
end
end
end
end
Loading…
Cancel
Save