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 %>
Domain | +Domain | +Serial | +Group | State | -Controls | +Slave | +DNSSEC | +Controls | ||
---|---|---|---|---|---|---|---|---|---|---|
- <% 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 %> - | -<%= link_to domain.name, domain %> | -<%= human_state(domain.state) %> | -<%= link_to_edit edit_domain_path(domain) %> | -<%= link_to_destroy domain, method: :delete, data: { confirm: 'Are you sure?' } if domain.can_remove? %> | -||||||
<%= link_to domain.name, domain %> | +<%= domain.soa.serial %> | +<%= link_to group.name, group_path(group) %> | +<%= human_state(domain.state) %> | +<%= domain.slave? ? domain.master : '-' %> | +<%= domain.dnssec? ? 'secure' : '-' %> | ++ <%= link_to_edit edit_domain_path(domain) %> + <%= link_to_destroy domain, method: :delete, data: { confirm: 'Are you sure?' } if domain.can_remove? %> + | +
- <%= 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 %>
-Member | Controls |
---|---|
<%= membership.user.email %><%= " (you)" if current_user == membership.user %> | <%= link_to_destroy destroy_member_group_path(@group, membership.user_id), method: :delete %> |
<%= 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 %>