Sha256: e6bc0337628eaa95096380c1530a039275311ef11343a53e4bf96c55a457c54d

Contents?: true

Size: 1 KB

Versions: 46

Compression:

Stored size: 1 KB

Contents

module Api
  class RolesController < BaseController
    include WithUserParams

    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(*permissible_params)
    end

    def permissible_params
      super + [:image_url, :email, :uid]
    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

    def authorization_slug
      @slug
    end
  end

end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
mumuki-laboratory-9.23.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.22.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.21.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.20.1 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.20.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.19.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.18.1 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.18.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.17.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.16.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.15.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.14.1 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.14.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.13.2 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.13.1 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.13.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.12.1 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.12.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.11.0 app/controllers/api/roles_controller.rb
mumuki-laboratory-9.10.0 app/controllers/api/roles_controller.rb