Add option to create ordergroup together with user

This commit is contained in:
Patrick Gansterer 2019-11-17 15:01:19 +01:00
parent a3946ed3d4
commit 9b889dd643
4 changed files with 13 additions and 1 deletions

View file

@ -20,7 +20,7 @@ class User < ApplicationRecord
has_many :created_orders, :class_name => 'Order', :foreign_key => 'created_by_user_id', :dependent => :nullify has_many :created_orders, :class_name => 'Order', :foreign_key => 'created_by_user_id', :dependent => :nullify
has_many :mail_delivery_status, :class_name => 'MailDeliveryStatus', :foreign_key => 'email', :primary_key => 'email' has_many :mail_delivery_status, :class_name => 'MailDeliveryStatus', :foreign_key => 'email', :primary_key => 'email'
attr_accessor :password, :settings_attributes attr_accessor :create_ordergroup, :password, :settings_attributes
scope :deleted, -> { where.not(deleted_at: nil) } scope :deleted, -> { where.not(deleted_at: nil) }
scope :undeleted, -> { where(deleted_at: nil) } scope :undeleted, -> { where(deleted_at: nil) }
@ -64,6 +64,12 @@ class User < ApplicationRecord
end end
self.settings.merge!(key, value) self.settings.merge!(key, value)
end if settings_attributes end if settings_attributes
if ActiveRecord::Type::Boolean.new.type_cast_from_user(create_ordergroup)
og = Ordergroup.new({name: name})
og.memberships.build({user: self})
og.save!
end
end end
# sorted by display name # sorted by display name

View file

@ -1,5 +1,7 @@
= simple_form_for([:admin, @user]) do |f| = simple_form_for([:admin, @user]) do |f|
= render 'shared/user_form_fields', f: f, password_autocomplete: false = render 'shared/user_form_fields', f: f, password_autocomplete: false
- unless @user.ordergroup
= f.input :create_ordergroup, as: :boolean, label: false, inline_label: t('.create_ordergroup')
.form-actions .form-actions
= f.submit = f.submit
= link_to t('ui.or_cancel'), :back = link_to t('ui.or_cancel'), :back

View file

@ -333,6 +333,8 @@ de:
notice: Benutzer/in wurde gelöscht notice: Benutzer/in wurde gelöscht
edit: edit:
title: Benutzer/in bearbeiten title: Benutzer/in bearbeiten
form:
create_ordergroup: Bestellgruppe mit dem selben Namen erstellen und Benutzer_in hinzufügen.
index: index:
first_paragraph: Hier kannst du Benutzer/innen %{url}, bearbeiten und natürlich auch löschen. first_paragraph: Hier kannst du Benutzer/innen %{url}, bearbeiten und natürlich auch löschen.
new_user: Neue/n Benutzer/in anlegen new_user: Neue/n Benutzer/in anlegen

View file

@ -351,6 +351,8 @@ en:
notice: User was deleted notice: User was deleted
edit: edit:
title: Edit user title: Edit user
form:
create_ordergroup: Create ordergroup with the same name and add user.
index: index:
first_paragraph: Here you can %{url}, edit and delete users. first_paragraph: Here you can %{url}, edit and delete users.
new_user: Create new user new_user: Create new user