diff --git a/app/models/group.rb b/app/models/group.rb index 45b21c0..fe3ae8f 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,8 +1,8 @@ class Group < ActiveRecord::Base has_many :domains validates :name, presence: true, uniqueness: true - has_many :memberships + has_many :memberships, dependent: :delete_all has_many :users, through: :memberships end diff --git a/app/models/user.rb b/app/models/user.rb index c2e1873..90a1009 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,52 +1,52 @@ class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - has_many :memberships + has_many :memberships, dependent: :delete_all has_many :groups, through: :memberships has_many :subscriptions, dependent: :delete_all scope :orphans, -> { includes(:memberships).where(:memberships => { user_id: nil }) } # Check if the user can change his password # # Remote users are not able to change their password def can_change_password? !identifier? end def toggle_admin self.admin = !self.admin end def to_api Hash[ :id, id, :email, email ].with_indifferent_access end def self.find_for_database_authentication(conditions) # Override devise method for database auth # We only want to auth local user via the database. find_first_by_auth_conditions(conditions, identifier: '') end def mute_all_domains ActiveRecord::Base.transaction do domain_ids = Domain.where(group: groups).pluck(:id) domain_ids.each { |did| sub = self.subscriptions.create(domain_id: did) if !sub.valid? # Allow only domain_id (uniqueness) errors raise x.errors.full_messages.join(', ') if sub.errors.size > 1 raise x.errors.full_messages.join(', ') if !sub.errors[:domain_id] end } end end end diff --git a/app/views/groups/show.html.erb b/app/views/groups/show.html.erb index d81de70..2e58964 100644 --- a/app/views/groups/show.html.erb +++ b/app/views/groups/show.html.erb @@ -1,92 +1,92 @@ <% content_for :more_breadcrumbs do %>
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) %> <% if @optouts.include? domain.id %> <%= link_to_unmute user_domain_unmute_path(current_user, domain), method: :put %> <% else %> <%= link_to_mute user_domain_mute_path(current_user, domain), method: :put %> <% end %> <%= 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 %>
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 %>