Class: Spree::Admin::VendorAuthorizedUsersController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/vendor_authorized_users_controller.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



10
11
12
13
14
# File 'app/controllers/spree/admin/vendor_authorized_users_controller.rb', line 10

def collection
  load_vendor

  @users = @vendor.users
end

#collection_url(options = {}) ⇒ Object



48
49
50
# File 'app/controllers/spree/admin/vendor_authorized_users_controller.rb', line 48

def collection_url(options = {})
  admin_vendor_vendor_authorized_users_url(options)
end

#load_vendorObject



6
7
8
# File 'app/controllers/spree/admin/vendor_authorized_users_controller.rb', line 6

def load_vendor
  @vendor ||= Spree::Vendor.by_vendor_id!(params[:vendor_id])
end

#model_classObject



38
39
40
# File 'app/controllers/spree/admin/vendor_authorized_users_controller.rb', line 38

def model_class
  Spree::User
end

#object_nameObject



43
44
45
# File 'app/controllers/spree/admin/vendor_authorized_users_controller.rb', line 43

def object_name
  'user'
end

#update_telegram_chatObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/spree/admin/vendor_authorized_users_controller.rb', line 16

def update_telegram_chat
  context = ::SpreeCmCommissioner::TelegramChatsFinder.call(
    telegram_chat_name: params['vendor']['preferred_telegram_chat_name'],
    telegram_chat_type: params['vendor']['preferred_telegram_chat_type']
  )

  if context.chats.present? && context.chats.is_a?(Hash)
    vendor_attributes = {
      preferred_telegram_chat_name: params['vendor']['preferred_telegram_chat_name'],
      preferred_telegram_chat_type: params['vendor']['preferred_telegram_chat_type'],
      preferred_telegram_chat_id: context.chats[:id]
    }

    flash[:error] = @vendor.errors.full_messages.to_sentence unless @vendor.update(vendor_attributes)
  else
    flash[:error] = I18n.t('vendor.validation.could_not_find_telegram_chat')
  end

  redirect_to collection_url(@vendor)
end