app/controllers/settings_controller.rb
##
# attempt to upgrade `user` to instructor unless they already are one.
attempt to upgrade `user` to instructor unless they already are one.
attempt to upgrade ` user ` to instructor unless they already are one .
def attempt_admin_downgrade
    if @user.instructor_permissions?
      message = I18n.t('settings.admin_users.remove.already_instructor', username: @user.username)
      yield json: { message: message }, status: 422
    end
    if @user.super_admin?
      message = I18n.t('settings.admin_users.remove.no_super_admin')
      yield json: { message: message }, status: 422
    end
    @user.update_attributes permissions: User::Permissions::INSTRUCTOR
    message = I18n.t('settings.admin_users.remove.demote_success', username: @user.username)
    yield json: { message: message }, status: 200
  end
def attempt_admin_downgrade if @user . instructor_permissions? message = I18n . t ( 'settings.admin_users.remove.already_instructor' , username : @user . username ) yield json : { message : message } , status : 422 end if @user . super_admin? message = I18n . t ( 'settings.admin_users.remove.no_super_admin' ) yield json : { message : message } , status : 422 end @user . update_attributes permissions : User :: Permissions :: INSTRUCTOR message = I18n . t ( 'settings.admin_users.remove.demote_success' , username : @user . username ) yield json : { message : message } , status : 200 end
attempt to upgrade `user` to instructor unless they already are one.
attempt to upgrade ` user ` to instructor unless they already are one .
# already an instructor # happy path