Page MenuHomeGRNET

No OneTemporary

File Metadata

Created
Fri, Aug 29, 2:12 PM
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 1099405..44c9b9d 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -1,47 +1,48 @@
class GroupsController < ApplicationController
before_action :authenticate_user!
before_action :group, only: [:show, :create_member, :destroy_member, :search_member]
before_action :user, only: [:destroy_member]
# GET /groups/1
def show
+ @domains = @group.domains
end
# POST /groups/1/members/
def create_member
@user = User.find_by_email!(params[:email])
membership = @group.memberships.find_or_create_by!(user_id: @user.id)
redirect_to @group, notice: "#{membership.user.email} is now a member of #{@group.name}"
end
# DELETE /groups/1/member/1
def destroy_member
membership = @group.memberships.find_by!(user_id: user.id)
membership.destroy!
redirect_to @group, notice: "#{membership.user.email} was successfully removed from #{@group.name}"
end
def search_member
results = []
if params[:q].present?
uids = group.users.pluck(:id)
results = User
.where('email like ?', "#{params[:q]}%")
.where.not(id: uids) # Exclude group members
.limit(10)
end
render json: results.map { |r| Hash[:id, r.id, :email, r.email] }
end
private
def user
@user ||= User.find(params[:user_id])
end
end
diff --git a/app/views/groups/show.html.erb b/app/views/groups/show.html.erb
index 42dad77..14ba2b1 100644
--- a/app/views/groups/show.html.erb
+++ b/app/views/groups/show.html.erb
@@ -1,85 +1,85 @@
<% content_for :more_breadcrumbs do %>
<li>
<%= link_to_edit edit_admin_group_path(@group) %>
<%= link_to_destroy admin_group_path(@group), method: :delete, data: { confirm: 'Are you sure?' } %>
</li>
<% end if admin? %>
<ul class="nav nav-tabs">
- <li role="presentation" class="active"><a data-toggle="tab" href="#domains">Domains</a></li>
- <li role="presentation"><a data-toggle="tab" href="#members">Members</a></li>
+ <li role="presentation" class="active"><a data-toggle="tab" href="#domains_tab">Domains</a></li>
+ <li role="presentation"><a data-toggle="tab" href="#members_tab">Members</a></li>
</ul>
<div class="tab-content">
- <div role="tabpanel" class="tab-pane active" id="domains">
- <table class="table table-striped table-hover">
+ <div role="tabpanel" class="tab-pane active" id="domains_tab">
+ <table id="domains" class="table table-striped">
<thead>
<tr>
- <th colspan="2">Domain</th>
+ <th>Domain</th>
+ <th>Serial</th>
+ <th>Group</th>
<th>State</th>
- <th colspan="2">Controls</th>
+ <th>Slave</th>
+ <th>DNSSEC</th>
+ <th class="no-order-and-search">Controls</th>
</tr>
</thead>
<tbody>
- <% @group.domains.each do |domain| %>
- <tr>
- <td>
- <% if domain.reverse? %>
- <%= abbr_glyph('chevron-left', 'Reverse') %>
- <% elsif domain.enum? %>
- <%= abbr_glyph('phone-alt', 'Enum') %>
- <% else %>
- <%= abbr_glyph('chevron-right', 'Forward') %>
- <% end %>
- <% if domain.slave? %>
- <%= abbr_glyph('link', 'Slave') %>
- <% end %>
- <% if domain.dnssec? %>
- <%= abbr_glyph('flash', 'DNSSEC') %>
- <% end %>
- </td>
- <td><%= link_to domain.name, domain %></td>
- <td><%= human_state(domain.state) %></td>
- <td><%= link_to_edit edit_domain_path(domain) %></td>
- <td><%= link_to_destroy domain, method: :delete, data: { confirm: 'Are you sure?' } if domain.can_remove? %></td>
- </tr>
+ <% @domains.group_by(&:group).each do |group, domains| %>
+ <% domains.each do |domain| %>
+ <tr class="group-<%= group.id =%>">
+ <td><%= link_to domain.name, domain %></td>
+ <td><%= domain.soa.serial %></td>
+ <td><%= link_to group.name, group_path(group) %></td>
+ <td><%= human_state(domain.state) %></td>
+ <td><%= domain.slave? ? domain.master : '-' %></td>
+ <td><%= domain.dnssec? ? 'secure' : '-' %></td>
+ <td>
+ <%= link_to_edit edit_domain_path(domain) %>
+ <%= link_to_destroy domain, method: :delete, data: { confirm: 'Are you sure?' } if domain.can_remove? %>
+ </td>
+ </tr>
+ <% end %>
<% end %>
</tbody>
</table>
<p>
- <%= link_to 'Add Domain', new_domain_path(group_id: @group.id), class: 'btn btn-primary' %>
+ <% if current_user.memberships.any? %>
+ <%= link_to 'Add Domain', new_domain_path(group_id: @group.id), class: 'btn btn-primary' %>
+ <% else %>
+ <%= link_to 'Add Domain', new_domain_path(group_id: @group.id), class: 'btn btn-primary disabled' %>
+ <% end %>
</p>
-
</div>
- <div role="tabpanel" class="tab-pane" id="members">
+ <div role="tabpanel" class="tab-pane" id="members_tab">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Member</th>
<th>Controls</th>
</tr>
</thead>
<tbody>
<% @group.memberships.includes(:user).each do |membership| %>
<tr>
<td><%= membership.user.email %><%= " (you)" if current_user == membership.user %></td>
<td>
<%= link_to_destroy destroy_member_group_path(@group, membership.user_id), method: :delete %>
</td>
</tr>
<% end %>
</tbody>
</table>
<p>
<%= bootstrap_form_tag(url: create_member_group_path(@group), layout: :inline) do |f| %>
<%= f.text_field :email, prepend: 'Add Member', hide_label: true, id: 'js-search-member', data: { group: @group.id } %>
<%= f.submit 'Add', class: 'btn btn-primary' %>
<% end %>
</p>
</div>
</div>

Event Timeline