app/models/plan.rb
# Creates a role for the specified user (will update the user's
# existing role if it already exists)
#
# Expects a User.id and access_type from the following list:
#  :creator, :administrator, :editor, :commenter
#
# Returns Boolean
Creates a role for the specified user (will update the user's
existing role if it already exists)



Returns Boolean
Creates a role for the specified user ( will update the user ' s existing role if it already exists ) Returns Boolean
def add_user!(user_id, access_type = :commenter)
    user = User.where(id: user_id).first
    if user.present?
      role = Role.find_or_initialize_by(user_id: user_id, plan_id: id)
      case access_type
      when :creator
        role.creator = true
        role.administrator = true
        role.editor = true
      when :administrator
        role.administrator = true
        role.editor = true
      when :editor
        role.editor = true
      end
      role.commenter = true
      role.save
    else
      false
    end
  end
def add_user! ( user_id , access_type = :commenter ) user = User . where ( id : user_id ) . first if user . present? role = Role . find_or_initialize_by ( user_id : user_id , plan_id : id ) case access_type when :creator role . creator = true role . administrator = true role . editor = true when :administrator role . administrator = true role . editor = true when :editor role . editor = true end role . commenter = true role . save else false end end
Creates a role for the specified user (will update the user's
existing role if it already exists)
Creates a role for the specified user ( will update the user ' s existing role if it already exists )
# Access is cumulative, so set the appropriate flags # (e.g. an administrator can also edit and comment)
user_id
access_type