Slide 27
Slide 27 text
͓·͚1ɿPunditɾCanCanCanͷൺֱ
Pundit CanCanCan
ಋೖ GemΛΠϯετʔϧ͠ɺBaseContollerͰPunditΛ
include͢Ε༻Մೳɻ
GemΛΠϯετʔϧ͠ɺAbilityΫϥεΛ࡞Ε༻Մ
ೳɻControllerͰͷincludeෆཁɻ
ݖݶઃఆ ֤ModelʹରԠͨ͠PolicyΫϥεΛ࡞͠ɺݖݶຖͷઃ
ఆΛهड़͢Δɻ
1ͭͷAbilityΫϥεʹϩʔϧຖͷ֤Ϟσϧʹର͢Δશͯͷ
ݖݶΛهࡌ͍ͯ͘͠ɻ
ControllerͰͷೝՄ authorizeϝιουΛݺͼग़͢͜ͱͰϞσϧʹରԠ͢Δ
PolicyΫϥε͕ࣗಈతʹࢀর͞ΕΔɻControllerͷΞΫ
γϣϯ໊ͱϚονͨ͠PolicyΫϥεͷϝιου͕ݺ
Εɺ࣮ߦՄೳ͔ఆ͢Δɻ
authorize!ϝιουͰݖݶͷೝՄ͕Ͱ͖ɺAbilityΫϥεʹ
ఆٛͨ͠ݖݶઃఆΛࢀর͠ɺ࣮ߦՄೳ͔ఆ͢Δɻ
ViewͰͷೝՄ policyϝιουΛ༻͢Δ͜ͱͰఆͰ͖Δɻ can?cannot?ϝιουͰఆͰ͖Δɻ
Ϩίʔυͷ੍ scopeͱ͍͏ػೳΛ༻͍ͯɺPolicyϑΝΠϧʹΠϯφ
ʔΫϥεͱͯ͠ScopeΫϥεΛఆٛ͢Δ͜ͱͰϢʔβ
ͷϨίʔυͷΞΫηεΛ੍ݶͰ͖Δɻ
policy_scopeϝιουͰݺͼग़͠Մೳɻ
Hash of Conditionsͱ͍͏ػೳΛ༻͍ͯɺ݅Λ͢ͱऔ
ಘ͢ΔϨίʔυΛ੍ݶग़དྷΔɻ
accessible_byϝιουͰݺͼग़͠Մೳɻ
૯߹ ֤ϞσϧຖʹରԠͨ͠PolicyϑΝΠϧΛఆٛ͢Δɻ
σʔλϞσϧ͕ଟ͍߹ͰɺPolicyϑΝΠϧγϯ
ϓϧʹอͯΔ͕ɺݸʑͷPolicyϑΝΠϧʹݖݶ͕ݸผ
࣮͞Ε͍ͯΔͷͰશମͷݟ௨͕͠ѱ͍ɻ
1ͭͷAbilityΫϥεʹ֤ϩʔϧͷ֤ϞσϧͷݖݶΛఆ
ٛ͢Δɻ1ϑΝΠϧʹશͯͷݖݶใ͕ू·ΔͷͰݟ௨
͠ྑ͍͕ɺΞϓϦέʔγϣϯͷ֦େͱڞʹංେԽͷҰ
్ΛḷΔɻ