Page MenuHomeGRNET

No OneTemporary

File Metadata

Created
Sat, Mar 21, 7:43 PM
diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb
index 3a9fd47..bc9ed7a 100644
--- a/app/controllers/records_controller.rb
+++ b/app/controllers/records_controller.rb
@@ -1,143 +1,148 @@
class RecordsController < ApplicationController
before_action :authenticate_user!
before_action :domain, except: [:search]
before_action :editable_transform_params, only: [:editable]
before_action :record, only: [:edit, :update, :editable, :destroy]
# GET /records/new
def new
@record = domain.records.build
end
# GET /records/1/edit
def edit
+ session[:edit_record_redirect_to] = request.referrer
end
# POST /records
def create
@record = domain.records.new(new_record_params)
if @record.save
notify_record(@record, :create)
redirect_to domain, notice: 'Record was successfully created.'
else
flash[:alert] = 'There were some errors creating the record!'
render :new
end
end
# PATCH/PUT /records/1
def update
if @record.update(edit_record_params)
notify_record(@record, :update)
- redirect_to domain, notice: 'Record was successfully updated.'
+
+ ret = session[:edit_record_redirect_to] ? session.delete(:edit_record_redirect_to) : domain
+
+ redirect_to ret, notice: 'Record was successfully updated.'
else
render :edit
end
end
def valid
@record = domain.records.new(new_record_params)
if @record.valid?
response = {
record: @record.as_bulky_json,
errors: false
}
render json: response
else
render json: { errors: @record.errors.full_messages.join(', ') }
end
end
def bulk
ops, err = @domain.bulk(params)
if err.empty?
notify_record_bulk(@domain, ops)
render json: { ok: true }
else
render json: { errors: err }
end
end
def editable
@record.assign_attributes(edit_record_params)
if @record.valid?
if @save
@record.save!
notify_record(@record, :update)
end
response = {
attribute: @attr,
value: @record.read_attribute(@attr),
serial: @domain.soa(true).serial,
record: @record.as_bulky_json,
saved: @save
}
render json: response
else
render text: @record.errors[@attr].join(', '), status: 400
end
end
# DELETE /records/1
def destroy
+ ret = request.referrer
if @record.type == 'SOA'
- redirect_to domain, alert: 'SOA records cannot be deleted!'
+ redirect_to ret, alert: 'SOA records cannot be deleted!'
return
end
@record.destroy
notify_record(@record, :destroy)
- redirect_to domain, notice: 'Record was successfully destroyed.'
+ redirect_to ret, notice: 'Record was successfully destroyed.'
end
# GET /search
def search
@records = Record
.where(domain: show_domain_scope)
.includes(:domain)
.search(params[:q]) # scope by domain
@records = Record.smart_order(@records)
end
private
# Modify params to use standard Rails patterns
def editable_transform_params
@attr = params[:name]
@save = params[:save] != 'false'
params[:record] = { params[:name] => params[:value] }
end
def edit_record_params
if @record.type == 'SOA'
permitted = [:contact, :serial, :refresh, :retry, :expire, :nx]
else
permitted = [:name, :content, :ttl, :prio, :disabled]
end
params.require(:record).permit(*permitted).tap { |r|
r[:drop_privileges] = true if not admin?
}
end
def new_record_params
params.require(:record).permit(:name, :content, :ttl, :type, :prio).tap { |r|
r[:drop_privileges] = true if not admin?
}
end
def notify_record(*args)
notification.notify_record(current_user, *args) if WebDNS.settings[:notifications]
end
def notify_record_bulk(*args)
notification.notify_record_bulk(current_user, *args) if WebDNS.settings[:notifications]
end
end
diff --git a/app/views/domains/_bulk_panel.html.erb b/app/views/domains/_bulk_panel.html.erb
index 999bb52..283300c 100644
--- a/app/views/domains/_bulk_panel.html.erb
+++ b/app/views/domains/_bulk_panel.html.erb
@@ -1,32 +1,32 @@
<div id="bulk-panel" class="panel panel-primary hidden">
<div class="panel-heading">
Bulk Mode
</div>
<div class="panel-body">
<p>
<span class="added">0</span> records added<abbr title="Highlight records that failed to be added" class="failed failed-added"></abbr>,
<abbr class="js-modified-hover" title="Highlight modified records">
<span class="changed">0</span> records modified
</abbr><abbr title="Highlight records that failed to update." class="failed failed-changed"></abbr>,
<span class="deleted">0</span> records deleted<abbr title="Highlight records that failed to delete" class="failed failed-deleted"></abbr>.
</p>
<div>
- <a href="." class="btn btn-default">Cancel (Refresh)</a>
+ <%= link_to 'Cancel (Refresh)', @domain, class: "btn btn-default" %>
<button type="button" class="btn btn-success" id="js-bulky-commit">Commit</button>
</div>
</div>
</div>
<style>
.affix {
top: 55px;
z-index: 100;
}
</style>
<script>
$('#bulk-panel').affix({
offset: {
top: 50
}
});
</script>
diff --git a/config/deploy/production-ci.rb b/config/deploy/production-ci.rb
index 0ee12b8..28672b6 100644
--- a/config/deploy/production-ci.rb
+++ b/config/deploy/production-ci.rb
@@ -1,11 +1,13 @@
set :rails_env, :production
server 'webdns4.grnet.gr', user: 'deployer', roles: %w(web app db)
+set :branch, ENV['BRANCH'] if ENV['BRANCH']
+
set :ssh_options, forward_agent: false, port: 29
#Override commands with sudo, for use with jenkins deployer
#SSHKit.config.command_map = Hash.new do |hash, command|
# hash[command] = "sudo -u webdns #{command}"
#end
diff --git a/config/deploy/staging-ci.rb b/config/deploy/staging-ci.rb
new file mode 100644
index 0000000..5f43a5b
--- /dev/null
+++ b/config/deploy/staging-ci.rb
@@ -0,0 +1,7 @@
+set :rails_env, :production
+
+server 'webdns4.staging.grnet.gr', user: 'deployer', roles: %w(web app db)
+
+set :branch, ENV['BRANCH'] if ENV['BRANCH']
+
+set :ssh_options, forward_agent: false, port: 29
diff --git a/config/deploy/test.rb b/config/deploy/test.rb
index bdc7820..e2a3972 100644
--- a/config/deploy/test.rb
+++ b/config/deploy/test.rb
@@ -1,11 +1,13 @@
set :rails_env, :production
server 'webdns4.test.grnet.gr', user: 'deployer', roles: %w(web app db)
+set :branch, ENV['BRANCH'] if ENV['BRANCH']
+
set :ssh_options, forward_agent: false, port: 29
#Override commands with sudo, for use with jenkins deployer
SSHKit.config.command_map = Hash.new do |hash, command|
hash[command] = "sudo -u webdns #{command}"
end

Event Timeline