Skip to content

Commit

Permalink
Init disputes
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Beljajev committed Feb 5, 2017
1 parent 2a42b55 commit 9eb60e4
Show file tree
Hide file tree
Showing 35 changed files with 795 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/stylesheets/admin-manifest.sass
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
// @import bootstrap-datepicker3
@import admin/admin
@import admin/bootstrap-dialog-fix
@import admin/disputes

18 changes: 18 additions & 0 deletions app/assets/stylesheets/admin/disputes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.admin-disputes-index-page .disputes {
td:nth-child(1) {
width: 25%;
}

td:nth-child(2) {
width: 25%;
}

td:nth-child(3) {
width: 25%;
}

td:nth-child(4) {
text-align: center;
width: 25%;
}
}
5 changes: 5 additions & 0 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Admin
class BaseController < AdminController

end
end
53 changes: 53 additions & 0 deletions app/controllers/admin/disputes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Admin
class DisputesController < BaseController
load_and_authorize_resource

def index
@disputes = @disputes.includes(:domain).latest_on_top
end

def new
@dispute = Dispute.new
end

def create
@dispute = Dispute.new(dispute_params)
created = @dispute.save

if created
flash[:notice] = t('.created')
redirect_to admin_disputes_path
else
render :new
end
end

def edit
end

def update
updated = @dispute.update(dispute_params)

if updated
flash[:notice] = t('.updated')
redirect_to admin_disputes_path
else
render :edit
end
end

def destroy
if @dispute.destroy
flash[:notice] = t('.deleted')
end

redirect_to admin_disputes_path
end

private

def dispute_params
params.require(:dispute).permit(:domain_name, :expire_date, :password)
end
end
end
1 change: 1 addition & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def admin # Admin/admin_user dynamic role
can :destroy, :pending
can :create, :zonefile
can :access, :settings_menu
can :manage, Dispute
end

def static_registrant
Expand Down
26 changes: 26 additions & 0 deletions app/models/dispute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Dispute < ActiveRecord::Base
belongs_to :domain, required: true

validates :expire_date, :password, presence: true
validates :domain, uniqueness: true
validate :validate_expire_date_past

alias_attribute :create_time, :created_at

delegate :name, to: :domain, prefix: true, allow_nil: true

def self.latest_on_top
order(create_time: :desc)
end

def domain_name=(value)
self.domain = Domain.find_by(name: value)
end

private

def validate_expire_date_past
return if expire_date.nil?
errors.add(:expire_date, :past) if expire_date.past?
end
end
1 change: 1 addition & 0 deletions app/views/admin/_menu.haml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
%li= link_to t(:zonefile), admin_zonefile_settings_path
%li= link_to t('.blocked_domains'), admin_blocked_domains_path
%li= link_to t('.reserved_domains'), admin_reserved_domains_path
%li= link_to t('.disputes'), admin_disputes_path
%li= link_to t(:mail_templates), admin_mail_templates_path
%li= link_to t('.epp_log'), admin_epp_logs_path(created_after: 'today')
%li= link_to t('.repp_log'), admin_repp_logs_path(created_after: 'today')
Expand Down
12 changes: 12 additions & 0 deletions app/views/admin/disputes/_dispute.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<tr class="dispute">
<td><%= dispute.domain_name %></td>
<td><%= l dispute.created_at %></td>
<td><%= l dispute.expire_date %></td>
<td>
<%= link_to t('.edit_btn'), edit_admin_dispute_path(dispute), class: 'btn btn-primary btn-xs' %>
<%= link_to t('.delete_btn'), admin_dispute_path(dispute),
method: :delete,
data: { confirm: t('.delete_btn_confirm') },
class: 'btn btn-danger btn-xs' %>
</td>
</tr>
37 changes: 37 additions & 0 deletions app/views/admin/disputes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%= form_for [:admin, dispute], html: { class: 'form-horizontal' }, auto_html5_validation: false do |f| %>
<%= render 'form_errors', target: dispute %>

<div class="form-group">
<%= f.label :domain, class: 'col-sm-2 control-label', for: nil %>

<div class="col-sm-4">
<%= f.text_field :domain_name, class: 'form-control', autofocus: true, required: true,
placeholder: 'example.com' %>
</div>
</div>

<div class="form-group">
<%= f.label :expire_date, class: 'col-sm-2 control-label' %>

<div class="col-sm-4">
<%= f.text_field :expire_date, class: 'form-control datepicker', required: true,
pattern: '[0-9]{4}-[0-9]{2}-[0-9]{2}',
placeholder: Time.zone.today.to_s %>
</div>
</div>

<div class="form-group">
<%= f.label :password, class: 'col-sm-2 control-label' %>

<div class="col-sm-4">
<%= f.text_field :password, class: 'form-control' %>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-2">
<%= f.submit t(".#{dispute.new_record? ? 'create' : 'update'}_btn"), class: 'btn btn-success',
name: nil %>
</div>
</div>
<% end %>
10 changes: 10 additions & 0 deletions app/views/admin/disputes/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ol class="breadcrumb">
<%= link_to t('admin.disputes.index.title'), admin_disputes_path %>
</ol>


<div class="page-header">
<h1><%= t '.title' %></h1>
</div>

<%= render 'form', dispute: @dispute %>
30 changes: 30 additions & 0 deletions app/views/admin/disputes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="page-header">
<div class="row">
<div class="col-sm-10">
<h1><%= t '.title' %></h1>
</div>

<div class="col-sm-2 text-right">
<%= link_to t('.new_btn'), new_admin_dispute_path, class: 'btn btn-primary' %>
</div>
</div>
</div>

<% if @disputes.present? %>
<table class="table table-hover table-bordered disputes">
<thead>
<tr>
<th><%= Domain.model_name.human %></th>
<th><%= Dispute.human_attribute_name :created_at %></th>
<th><%= Dispute.human_attribute_name :expire_date %></th>
<th></th>
</tr>
</thead>

<tbody>
<%= render @disputes %>
</tbody>
</table>
<% else %>
<div class="alert alert-info"><%= t '.not_found' %></div>
<% end %>
9 changes: 9 additions & 0 deletions app/views/admin/disputes/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ol class="breadcrumb">
<%= link_to t('admin.disputes.index.title'), admin_disputes_path %>
</ol>

<div class="page-header">
<h1><%= t '.title' %></h1>
</div>

<%= render 'form', dispute: @dispute %>
11 changes: 11 additions & 0 deletions app/views/application/_form_errors.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% if target.errors.any? %>
<div class="alert alert-danger">
<p><%= pluralize(target.errors.count, 'error') %> prohibited this <%= target.model_name.human.downcase %> from being saved:</p>

<ul>
<% target.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
43 changes: 43 additions & 0 deletions config/locales/admin/disputes.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
en:
admin:
disputes:
index:
new_btn: New dispute
title: Disputes
not_found: No dispute found

new:
title: New dispute

edit:
title: Edit dispute

create:
created: Dispute has been successfully created

update:
updated: Dispute has been successfully updated

destroy:
deleted: Dispute has been successfully deleted

dispute:
edit_btn: Edit
delete_btn: Delete
delete_btn_confirm: Are you sure you want to delete dispute?

form:
create_btn: Create dispute
update_btn: Update dispute

activerecord:
attributes:
dispute:
expire_date: Date of expiry

errors:
models:
dispute:
attributes:
expire_date:
past: cannot be in the past
1 change: 1 addition & 0 deletions config/locales/admin/menu.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ en:
contact_history: Contact history
blocked_domains: Blocked domains
reserved_domains: Reserved domains
disputes: Disputes
epp_log: EPP log
repp_log: REPP log
que: Que
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
resources :pricelists
resources :mail_templates
resources :account_activities
resources :disputes, except: %i(show)

resources :bank_statements do
resources :bank_transactions
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20170131231449_create_disputes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateDisputes < ActiveRecord::Migration
def change
create_table :disputes do |t|
t.integer :domain_id, index: true
t.string :password
t.datetime :expire_time
t.datetime :created_at
end

add_foreign_key :disputes, :domains
end
end
6 changes: 6 additions & 0 deletions db/migrate/20170203102059_change_dispute_expire_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ChangeDisputeExpireTime < ActiveRecord::Migration
def change
change_column :disputes, :expire_time, :date
rename_column :disputes, :expire_time, :expire_date
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddDomainIdUniqueIndexToDisputes < ActiveRecord::Migration
def change
remove_index :disputes, :domain_id
add_index :disputes, :domain_id, unique: true
end
end
12 changes: 11 additions & 1 deletion db/schema-read-only.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20161227193500) do
ActiveRecord::Schema.define(version: 20170205135240) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -268,6 +268,15 @@

add_index "directos", ["item_type", "item_id"], name: "index_directos_on_item_type_and_item_id", using: :btree

create_table "disputes", force: :cascade do |t|
t.integer "domain_id"
t.string "password"
t.date "expire_date"
t.datetime "created_at"
end

add_index "disputes", ["domain_id"], name: "index_disputes_on_domain_id", unique: true, using: :btree

create_table "dnskeys", force: :cascade do |t|
t.integer "domain_id"
t.integer "flags"
Expand Down Expand Up @@ -1159,4 +1168,5 @@
t.text "a4_records"
end

add_foreign_key "disputes", "domains"
end
Loading

0 comments on commit 9eb60e4

Please sign in to comment.