ruby on rails - How can I allow only a specific user role to update an attribute to a specific value -
afternoon, got bit of issue not sure how resolve.
i trying setup rules allows types of user roles update status attribute on model status.
so looked doing pundit seems authorisation issue, 1 problem cannot pass params pundit policy need access (so can see attribute trying change to), , seems bad practise pass params pundit policy.
the next option make callback in model, problem here don’t have access current_user inside callback , again seems bad practise add current_user helper model.
so left perhaps doing in controller? again not seem right place it?
an example make little easier understand:
i want allow user role of admin allowed change status of post "resolved", no 1 else allowed change status "resolved"
try this, create instance method in user model bellow,
def is_admin? self.has_role(:admin) # if using rolify ---or--- self.status == "admin" # if have status attribute in user table end
then call method on current_user in edit/update method of post controller. check current_user admin or not
Comments
Post a Comment