7

मेरे पास दो मॉडल (आइटम और थीम) हैं। वे दोनों एक तीसरे मॉडल के स्वामित्व वाले हैं जिनके पास has_many एसोसिएशन है (उपयोगकर्ता के पास कई थीम्स और आइटम हैं)। आइटम और थीम दोनों हैं Imany: छवियों।रूबी: घोषणात्मक_आधिकरण पॉलिमॉर्फिक संघ

छवि मॉडल एक पॉलिमॉर्फिक एसोसिएशन है इसलिए तालिका में कॉलम imageable_id और imageable_type है। अगर मैं आईडी 1 और आईडी 1 के साथ एक विषय के साथ दोनों एक आइटम था तालिका

id imageable_id imageable_type 
------------------------------------ 
1  1    Item 
2  1    Theme 

की तरह लग रहा declarative_authorization उपयोग कर रहा हूँ मेरी डेटाबेस की एसक्यूएल प्रश्नों को फिर से लिखने के लिए उपयोगकर्ताओं के बाहर आइटम तक पहुँचने से रखने के लिए होगा उनके लेखा। मैं एक प्राधिकरण नियम लिखना चाहता हूं जो उपयोगकर्ता को केवल एक छवि पढ़ने की अनुमति देगा यदि वे उस आइटम को पढ़ सकते हैं जो वे स्वयं हैं। मैं सही सिंटैक्स प्राप्त नहीं कर पा रहे है (शायद यह समर्थित नहीं है):

has_permission_on [:images], :to => [:manage], :join_as => :and do 
    if_attribute :imageable => is { "Theme" } 
    if_permitted_to :manage, :themes # Somehow I need to tell declarative_auth to imageable_id is a theme_id in this case. 
end 

कोई भी विचार:

has_permission_on [:images], :to => [:manage], :join_as => :and do 
    if_attribute :imageable => is { "Item" } 
    if_permitted_to :manage, :items # Somehow I need to tell declarative_auth to imageable_id is an item_id in this case. 
end 

तो मैं एक और नियम से ऊपर लेकिन के लिए विषयों की नकल उतार होगा? अग्रिम में धन्यवाद!

  • Corith मालिन
+0

बहुत पुराना मणि, बहुलक संघों को समर्थित नहीं लगता है: https://github.com/stffn/declarative_authorization/issues/114। कैनकनन जैसे कुछ का उपयोग क्यों नहीं करते? https://github.com/CanCanCommunity/cancancan – gdurelle

+0

मेरा मतलब है ... जब मैंने इसे लिखा और इसे 2010 में पोस्ट किया तो यह पुराना मणि नहीं था। –

उत्तर

0

ऐसा लगता है कि आप has_permission_on विधि

में एक गलती के रूप में मैं आशा has_permission_on

has_permission_on(:images, :to => :manage, :join_as => :and) do 
    if_attribute :imageable => "Item" 
    if_permitted_to :manage, :items 
    end 

पर और if_attribute

यह सहायता आप जाँच !! !

+0

@ कोरिथ मालिंन हमें बताएं कि क्या हमारा उत्तर आपके लिए काम करता है या नहीं ? – VKatz

संबंधित मुद्दे