Mailboxer宝石,管理员视图 [英] Mailboxer Gem, Admin View

查看:63
本文介绍了Mailboxer宝石,管理员视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用邮箱管理器gem在我的应用程序中的User模型之间进行对话/消息。得益于堆栈溢出方面的一些出色帮助,这些工作一切正常。我现在正在尝试设置一个部分,以便管理员可以查看所有正在发生的对话。

I'm using the mailboxer gem for conversations/messages between the User model in my app. This is all working fine, thanks to some great help in stack overflow. I'm now trying to setup a section so admin can view all the conversations that are happening.

我创建了一个控制器,并查看了嵌套在我管理部分中的对话。 。我已经在索引页面上进行了所有对话:

I have created a controller and view for conversations, nested in my admin section. I've pulled in all conversations on the index page with:

 def index
    @admin_conversations = Conversation.all
  end

这列出了所有对话,并按预期显示了每个对话的链接。

This has listed all the conversations, and a link to show each conversation, as expected.

我遇到的问题是,将邮筒Gem设置为仅允许current_user查看current_user参与的会话。因此,我可以单击其中的一些对话(以管理员身份签名),然后查看内容,但是有些(在其他测试用户之间)看不到,即抛出异常,例如:

The problem I am having, is that the mailboxer Gem is setup to only allow the current_user to view conversations that the current_user is a participant in. So I can click some of the conversations, (signed is as an admin) and see the contents, but some (that are between other test users) I cannot see i.e it throws an exception such as:

Couldn't find Conversation with id=5 [WHERE "notifications"."type" = 'Message' AND "receipts"."receiver_id" = 35 AND "receipts"."receiver_type" = 'User']

如何在管理控制器中定义方法,以便管理员可以看到

How can I define the method in my admin controller so that the admin can see everything?

我目前正在使用cancan,并允许我拥有的所有3个用户角色(管理员,客户和供应商)是这样的:

I'm currently using cancan and allowing all 3 user roles I have (admin, client and supplier) like this:

can :manage, Conversation

。 ..so这不是正常的授权问题。

...so it isn't a normal authorisation problem.

这是我的对话控制器:

class ConversationsController < ApplicationController
  authorize_resource
  helper_method :mailbox, :conversation


  def create
    recipient_emails = conversation_params(:recipients).split(',')
    recipients = User.where(email: recipient_emails).all

    conversation = current_user.
      send_message(recipients, *conversation_params(:body, :subject)).conversation

    redirect_to :back, :notice => "Message Sent! You can view it in 'My Messages'."
  end

 def count
  current_user.mailbox.receipts.where({:is_read => false}).count(:id, :distinct => true).to_s
 end    

  def reply
    current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
    redirect_to conversation
  end

  def trash
    conversation.move_to_trash(current_user)
    redirect_to :conversations
  end

  def untrash
    conversation.untrash(current_user)
    redirect_to :conversations
  end

  private


  def mailbox
    @mailbox ||= current_user.mailbox
  end

  def conversation
    @conversation ||= mailbox.conversations.find(params[:id])
  end


  def conversation_params(*keys)
    fetch_params(:conversation, *keys)
  end

  def message_params(*keys)
    fetch_params(:message, *keys)
  end

  def fetch_params(key, *subkeys)
    params[key].instance_eval do
      case subkeys.size
      when 0 then self
      when 1 then self[subkeys.first]
      else subkeys.map{|k| self[k] }
      end
    end
  end
end

答案可能很愚蠢,但是我对此并不陌生...

The answer is probably something pretty silly, but I am new to this...

谢谢

推荐答案

在您的会话方法中,您呼叫 mailbox.conversations.find(params [:id])

In your conversation method, your calling mailbox.conversations.find(params[:id])

mailbox.conversations是限制您访问当前用户的对话。

mailbox.conversations is what is limiting you to the current user's conversations.

仅尝试 Conversation.find( params [:id])

这篇关于Mailboxer宝石,管理员视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆