Class: Course::EnrolRequestsController

Inherits:
ComponentController show all
Defined in:
app/controllers/course/enrol_requests_controller.rb

Instance Method Summary collapse

Methods included from ApplicationSignInCallbacksConcern

#sign_in

Methods included from ApplicationPaginationConcern

#page_param

Methods included from ApplicationAnnouncementsConcern

#global_announcements, #unread_global_announcements

Methods included from ApplicationInstanceUserConcern

#current_instance_user

Methods included from ApplicationUserTimeZoneConcern

#set_time_zone

Methods included from ApplicationUserConcern

#handle_access_denied, #publicly_accessible?

Methods included from ApplicationComponentsConcern

#handle_component_not_found

Instance Method Details

#approveObject

Approve the given role request and creates the course user.


33
34
35
36
37
38
39
40
41
# File 'app/controllers/course/enrol_requests_controller.rb', line 33

def approve
  course_user = create_course_user
  if course_user.persisted?
    flash.now[:success] = t('.success', name: course_user.name, role: course_user.role)
    Course::Mailer.user_added_email(current_course, course_user).deliver_later
  else
    flash.now[:danger] = course_user.errors.full_messages.to_sentence
  end
end

#createObject


10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/course/enrol_requests_controller.rb', line 10

def create
  @enrol_request.user = current_user
  if @enrol_request.save
    Course::Mailer.user_enrol_requested_email(@enrol_request).deliver_later
    redirect_to course_path(current_course), success: t('.success')
  else
    redirect_to course_path(current_course),
                danger: @enrol_request.errors.full_messages.to_sentence
  end
end

#destroyObject

Allow users to withdraw their requests to register for a course that are pending approval/rejection.


23
24
25
26
27
28
29
30
# File 'app/controllers/course/enrol_requests_controller.rb', line 23

def destroy
  if @enrol_request.destroy
    redirect_back fallback_location: course_path(current_course), success: t('.success')
  else
    redirect_back fallback_location: course_path(current_course),
                  danger: @enrol_request.errors.full_messages.to_sentence
  end
end

#indexObject


6
7
8
# File 'app/controllers/course/enrol_requests_controller.rb', line 6

def index
  @enrol_requests = @enrol_requests.includes(:user)
end