diff --git a/app/controllers/domains_controller.rb b/app/controllers/domains_controller.rb index 5a157ea..13d2bae 100644 --- a/app/controllers/domains_controller.rb +++ b/app/controllers/domains_controller.rb @@ -1,66 +1,67 @@ class DomainsController < ApplicationController before_action :authenticate_user! before_action :group_scope before_action :domain, only: [:show, :edit, :update, :destroy] before_action :group, only: [:show, :edit, :update, :destroy] # GET /domains def index @domains = domain_scope.all end # GET /domains/1 def show + @record = Record.new(domain_id: @domain.id) end # GET /domains/new def new @domain = Domain.new end # GET /domains/1/edit def edit end # POST /domains def create @domain = Domain.new(domain_params) if @domain.save redirect_to @domain, notice: "#{@domain.name} was successfully created." else render :new end end # PATCH/PUT /domains/1 def update if @domain.update(domain_params) redirect_to @domain, notice: "#{@domain.name} was successfully updated." else render :edit end end # DELETE /domains/1 def destroy @domain.destroy redirect_to domains_url, notice: "#{@domain.name} was successfully destroyed." end private def group domain.group end def domain_params params.require(:domain).tap { |d| # Make sure group id is permitted (belongs to group_scope) d[:group_id] = group_scope.find_by_id(d[:group_id]).try(:id) }.permit(:name, :type, :group_id) end end diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index 4ff086b..2090230 100644 --- a/app/controllers/records_controller.rb +++ b/app/controllers/records_controller.rb @@ -1,61 +1,62 @@ class RecordsController < ApplicationController before_action :authenticate_user! before_action :domain before_action :record, only: [:edit, :update, :destroy] # GET /records/new def new @record = domain.records.build end # GET /records/1/edit def edit end # POST /records def create @record = domain.records.new(new_record_params) if @record.save 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) redirect_to domain, notice: 'Record was successfully updated.' else render :edit end end # DELETE /records/1 def destroy @record.destroy redirect_to domain, notice: 'Record was successfully destroyed.' end private def edit_record_params if @record.type == 'SOA' permitted = [:contact, :serial, :refresh, :retry, :expire, :nx] else permitted = [:name, :content, :ttl, :prio, :disable] 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 end diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index 8330b7c..c216917 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -1,60 +1,58 @@ module BreadcrumbHelper # Domain # Domain / group / example.com # Domain / group / example.com / ns1.example.com IN A # Domain / group / example.com / new def breadcrumbs(leaf) crumbs = generate_crumbs_for(leaf) crumbs.each { |c| # Last element should not be a link if c == crumbs.last || c[:link].nil? yield c[:name] else yield link_to(c[:name], c[:link]) end } end private # rubocop:disable all def generate_crumbs_for(leaf) stack = [] crumbs = [] stack.push leaf if leaf while crumb = stack.pop # rubocop:disable Lint/AssignmentInCondition case crumb when Record if crumb.persisted? crumbs.push( name: "#{crumb.name} IN #{crumb.type}", link: domain_record_path(crumb.domain_id, crumb)) - else - crumbs.push(name: :new) end stack.push crumb.domain when Domain if crumb.persisted? crumbs.push(name: crumb.name, link: domain_path(crumb)) else crumbs.push(name: :new) end stack.push crumb.group when Group if crumb.persisted? crumbs.push(name: crumb.name, link: group_path(crumb)) else crumbs.push(name: :new) end end end crumbs.push(name: glyph(:home), link: '/') crumbs.reverse end # rubocop:enable all end diff --git a/app/views/domains/show.html.erb b/app/views/domains/show.html.erb index a838d6e..f95db1c 100644 --- a/app/views/domains/show.html.erb +++ b/app/views/domains/show.html.erb @@ -1,38 +1,44 @@
Records | Controls | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
<%= record.name %> | <%= record.ttl %> | IN | <%= record.type %> | <%= record.supports_prio? ? record.prio : '' %> | <%= record.content %> | <% if can_edit?(record) %><% if record.disabled? %> <%= link_to_enable enable_domain_record_path(@domain, record), method: :put %> <% else %> <%= link_to_disable disable_domain_record_path(@domain, record), method: :put %> <% end %> | <%= link_to_edit edit_domain_record_path(@domain, record) if can_edit?(record) %> | <%= link_to_destroy [@domain, record], method: :delete, data: { confirm: 'Are you sure?' } %> | <% else %><% end %> |
<%= link_to 'New Record', new_domain_record_path(@domain) %>
++ <%= link_to 'Add Record', '#new_record', class: 'btn btn-primary', onclick: '$("#new_record_wrapper").toggleClass("hidden");' %> +
+ +