Class: CollaborationsController

Inherits:
Object
  • Object
show all
Defined in:
lib/etherpad_canvas/collaborations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/etherpad_canvas/collaborations_controller.rb', line 32

def create
  # This code was taken fro the original canvas controller in an effort to get around
  # the limitations of Rails' version 5.0 to escape a redirect. The only changes that have
  # been made from the original code are on lines 46 where a .delete was removed from between the 
  # params[:collaboration][:collaboration_type] and line 56
  content_item = params["contentItems"] ? JSON.parse(params["contentItems"]).first : nil
  if content_item
    @collaboration = collaboration_from_content_item(content_item)
    users, group_ids = content_item_visibility(content_item)
  else
    users = User.where(id: Array(params[:user])).to_a
    group_ids = Array(params[:group])
    collaboration_params = params.require(:collaboration).permit(:title, :description, :url)
    collaboration_params[:user] = @current_user
    @collaboration = Collaboration.typed_collaboration_instance(params[:collaboration][:collaboration_type])
    collaboration_params.delete(:url) unless @collaboration.is_a?(ExternalToolCollaboration)
    @collaboration.attributes = collaboration_params
  end
  @collaboration.context = @context
  if @collaboration.collaboration_type == "EtherPad"
    respond_to do |format|
      if @collaboration.save
        Lti::ContentItemUtil.new(content_item).success_callback if content_item
        @collaboration.update_members(users, group_ids)
        format.html { redirect_to EtherpadCollaboration.sign_url(@current_user, @collaboration) }
        format.json {
          render json: @collaboration.as_json(
            methods: [:collaborator_ids], permissions: {
              user: @current_user,
              session: session,
            }
          )
        }
      else
        Lti::ContentItemUtil.new(content_item).failure_callback if content_item
        flash[:error] = t "errors.create_failed", "Collaboration creation failed"
        format.html { redirect_to named_context_url(@context, :context_collaborations_url) }
        format.json { render json: @collaboration.errors, status: :bad_request }
      end
    end
  else
    create_without_etherpad
  end
end

#create_without_etherpadObject



21
# File 'lib/etherpad_canvas/collaborations_controller.rb', line 21

alias create_without_etherpad create

#showObject



23
24
25
26
27
28
29
30
# File 'lib/etherpad_canvas/collaborations_controller.rb', line 23

def show
  @collaboration = @context.collaborations.find(params[:id])
  if @collaboration.collaboration_type == "EtherPad"
    return redirect_to EtherpadCollaboration.sign_url(@current_user, @collaboration)
  else
    show_without_etherpad
  end
end

#show_without_etherpadObject



20
# File 'lib/etherpad_canvas/collaborations_controller.rb', line 20

alias show_without_etherpad show