diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 44c9b9d..5c806af 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -1,48 +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}" + redirect_to group_path(@group, anchor: 'tab-members'), 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 20db4ba..7874355 100644 --- a/app/views/groups/show.html.erb +++ b/app/views/groups/show.html.erb @@ -1,87 +1,87 @@ <% content_for :more_breadcrumbs do %>
  • <%= link_to_edit edit_admin_group_path(@group) %> <%= link_to_destroy admin_group_path(@group), method: :delete, data: { confirm: 'Are you sure?' } %>
  • <% end if admin? %>
    <% @domains.group_by(&:group).each do |group, domains| %> <% domains.each do |domain| %> <% end %> <% end %>
    Domain Serial Group State Slave DNSSEC Controls
    <%= link_to domain.name, domain %> <%= domain.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_full_destroy full_destroy_domain_path(domain), method: :delete, data: { confirm: 'Are you sure?' } if domain.can_remove? && domain.dnssec? %>

    <% 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 %>

    <% @group.memberships.includes(:user).each do |membership| %> <% 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 %>