Sha256: 771d80246f1184e0c824dd1a43a758d3f1c2e17ecf8bcd4c596589b4699f48cd

Contents?: true

Size: 902 Bytes

Versions: 62

Compression:

Stored size: 902 Bytes

Contents

module Api
  class RolesController < BaseController
    before_action :set_slug!
    before_action :set_course!
    before_action :set_user!, except: :create
    before_action :authorize_janitor!

    def create
      @user = User.create_if_necessary(user_params)
      @user.attach! role, @course
      render json: @user
    end

    def attach
      @user.attach! role, @course
      head :ok
    end

    def detach
      @user.detach! role, @course
      head :ok
    end

    private

    def role
      raise 'Not Implemented'
    end

    def user_params
      params.require(role).permit(:first_name, :last_name, :email, :uid, :image_url)
    end

    def set_course!
      @course = Course.find_by!(slug: @slug)
    end

    def set_user!
      @user = User.find_by!(uid: params[:uid])
    end

    def set_slug!
      @slug = Mumukit::Auth::Slug.join_s params.to_unsafe_h
    end
  end

end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
mumuki-laboratory-7.0.8 app/controllers/api/roles_controller.rb
mumuki-laboratory-7.0.7 app/controllers/api/roles_controller.rb
mumuki-laboratory-7.0.6 app/controllers/api/roles_controller.rb
mumuki-laboratory-7.0.5 app/controllers/api/roles_controller.rb
mumuki-laboratory-7.0.4 app/controllers/api/roles_controller.rb
mumuki-laboratory-7.0.3 app/controllers/api/roles_controller.rb
mumuki-laboratory-7.0.2 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.7.7 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.7.6 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.7.5 app/controllers/api/roles_controller.rb
mumuki-laboratory-7.0.1 app/controllers/api/roles_controller.rb
mumuki-laboratory-7.0.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.7.4 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.7.3 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.7.2 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.7.1 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.7.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.6.1 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.6.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-6.5.1 app/controllers/api/roles_controller.rb