readding codeharbor_link views and actions

This commit is contained in:
Karol
2019-08-26 19:06:52 +02:00
parent ecabd9d05c
commit ec48d1f447
20 changed files with 136 additions and 127 deletions

View File

@ -1,68 +0,0 @@
class CodeHarborLinksController < ApplicationController
include CommonBehavior
before_action :set_code_harbor_link, only: [:show, :edit, :update, :destroy]
def authorize!
authorize(@code_harbor_link || @code_harbor_links)
end
private :authorize!
# GET /code_harbor_links
# GET /code_harbor_links.json
def index
@code_harbor_links = CodeHarborLink.where(user_id: current_user.id).paginate(page: params[:page])
authorize!
end
# GET /code_harbor_links/1
# GET /code_harbor_links/1.json
def show
authorize!
end
# GET /code_harbor_links/new
def new
@code_harbor_link = CodeHarborLink.new
authorize!
end
# GET /code_harbor_links/1/edit
def edit
authorize!
end
# POST /code_harbor_links
# POST /code_harbor_links.json
def create
@code_harbor_link = CodeHarborLink.new(code_harbor_link_params)
@code_harbor_link.user = current_user
authorize!
create_and_respond(object: @code_harbor_link)
end
# PATCH/PUT /code_harbor_links/1
# PATCH/PUT /code_harbor_links/1.json
def update
update_and_respond(object: @code_harbor_link, params: code_harbor_link_params)
authorize!
end
# DELETE /code_harbor_links/1
# DELETE /code_harbor_links/1.json
def destroy
destroy_and_respond(object: @code_harbor_link)
end
private
# Use callbacks to share common setup or constraints between actions.
def set_code_harbor_link
@code_harbor_link = CodeHarborLink.find(params[:id])
@code_harbor_link.user = current_user
authorize!
end
# Never trust parameters from the scary internet, only allow the white list through.
def code_harbor_link_params
params.require(:code_harbor_link).permit(:oauth2token)
end
end

View File

@ -0,0 +1,55 @@
class CodeharborLinksController < ApplicationController
include CommonBehavior
before_action :set_codeharbor_link, only: [:show, :edit, :update, :destroy]
def authorize!
authorize(@codeharbor_link || @codeharbor_links)
end
private :authorize!
def index
@codeharbor_links = CodeharborLink.where(user_id: current_user.id).paginate(page: params[:page])
authorize!
end
def show
authorize!
end
def new
@codeharbor_link = CodeharborLink.new
authorize!
end
def edit
authorize!
end
def create
@codeharbor_link = CodeharborLink.new(codeharbor_link_params)
@codeharbor_link.user = current_user
authorize!
create_and_respond(object: @codeharbor_link)
end
def update
update_and_respond(object: @codeharbor_link, params: codeharbor_link_params)
authorize!
end
def destroy
destroy_and_respond(object: @codeharbor_link)
end
private
def set_codeharbor_link
@codeharbor_link = CodeharborLink.find(params[:id])
@codeharbor_link.user = current_user
authorize!
end
def codeharbor_link_params
params.require(:codeharbor_link).permit(:push_url, :oauth2token, :client_id, :client_secret)
end
end

View File

@ -108,34 +108,17 @@ class ExercisesController < ApplicationController
end end
def import_proforma_xml def import_proforma_xml
# begin
# user = user_for_oauth2_request
# exercise = Exercise.new
# request_body = request.body.read # needs to be some kind of a zip file
tempfile = Tempfile.new('codeharbor_import.zip') tempfile = Tempfile.new('codeharbor_import.zip')
tempfile.write request.body.read.force_encoding('UTF-8') tempfile.write request.body.read.force_encoding('UTF-8')
tempfile.rewind tempfile.rewind
exercise = ProformaService::Import.call(zip: tempfile, user: user_for_oauth2_request) exercise = ProformaService::Import.call(zip: tempfile, user: user_for_oauth2_request)
# exercise.from_proforma_xml(request_body)
# exercise.user = user
# saved = exercise.save
if exercise.save if exercise.save
# render text: 'SUCCESS', status: 200
render json: {}, status: 201 render json: {}, status: 201
else else
logger.info(exercise.errors.full_messages) logger.info(exercise.errors.full_messages)
render json: {}, status: 400 render json: {}, status: 400
end end
# rescue => error
# if error.class == Hash
# render :text => error.message, :status => error.status
# else
# raise error
# render :text => '', :status => 500
# end
# end
end end
def user_for_oauth2_request def user_for_oauth2_request

View File

@ -13,6 +13,7 @@ class User < ApplicationRecord
has_many :user_proxy_exercise_exercises, as: :user has_many :user_proxy_exercise_exercises, as: :user
has_many :user_exercise_interventions, as: :user has_many :user_exercise_interventions, as: :user
has_many :interventions, through: :user_exercise_interventions has_many :interventions, through: :user_exercise_interventions
has_one :codeharbor_link
accepts_nested_attributes_for :user_proxy_exercise_exercises accepts_nested_attributes_for :user_proxy_exercise_exercises

View File

@ -1,3 +1,31 @@
class CodeharborLinkPolicy < AdminOnlyPolicy # frozen_string_literal: true
class CodeharborLinkPolicy < ApplicationPolicy
def index?
teacher?
end
def create?
teacher?
end
def show?
teacher?
end
def edit?
teacher?
end
def destroy?
teacher?
end
def new?
teacher?
end
def update?
teacher?
end
end end

View File

@ -19,5 +19,5 @@
models: [ErrorTemplate, ErrorTemplateAttribute], cached: true) models: [ErrorTemplate, ErrorTemplateAttribute], cached: true)
= render('navigation_submenu', title: t('navigation.sections.files'), models: [FileType, FileTemplate], = render('navigation_submenu', title: t('navigation.sections.files'), models: [FileType, FileTemplate],
cached: true) cached: true)
= render('navigation_submenu', title: t('navigation.sections.integrations'), models: [Consumer], = render('navigation_submenu', title: t('navigation.sections.integrations'), models: [Consumer, CodeharborLink],
cached: true) cached: true)

View File

@ -1,6 +0,0 @@
= form_for(@code_harbor_link) do |f|
= render('shared/form_errors', object: @code_harbor_link)
.form-group
= f.label(:oauth2token)
= f.text_field(:oauth2token, class: 'form-control', required: true)
.actions = render('shared/submit_button', f: f, object: @code_harbor_link)

View File

@ -1,3 +0,0 @@
h1 = @code_harbor_link
= render('form')

View File

@ -1,18 +0,0 @@
h1 = CodeHarborLink.model_name.human(count: 2)
.table-responsive
table.table
thead
tr
th = t('activerecord.attributes.code_harbor_link.oauth2token')
th colspan=3 = t('shared.actions')
tbody
- @code_harbor_links.each do |code_harbor_link|
tr
td = link_to_if(policy(code_harbor_link).show?, code_harbor_link.oauth2token, code_harbor_link)
td = link_to(t('shared.show'), code_harbor_link) if policy(code_harbor_link).show?
td = link_to(t('shared.edit'), edit_code_harbor_link_path(code_harbor_link)) if policy(code_harbor_link).edit?
td = link_to(t('shared.destroy'), code_harbor_link, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(code_harbor_link).destroy?
= render('shared/pagination', collection: @code_harbor_links)
p = render('shared/new_button', model: CodeHarborLink)

View File

@ -1,3 +0,0 @@
h1 = t('shared.new_model', model: CodeHarborLink.model_name.human)
= render('form')

View File

@ -1,7 +0,0 @@
h1
= @code_harbor_link
= render('shared/edit_button', object: @code_harbor_link)
- %w[oauth2token].each do |attribute|
= row(label: "code_harbor_link.#{attribute}") do
= content_tag(:input, nil, class: 'form-control', readonly: true, value: @code_harbor_link.send(attribute))

View File

@ -0,0 +1,6 @@
= form_for(@codeharbor_link) do |f|
= render('shared/form_errors', object: @codeharbor_link)
.form-group
= f.label(:oauth2token)
= f.text_field(:oauth2token, class: 'form-control', required: true)
.actions = render('shared/submit_button', f: f, object: @codeharbor_link)

View File

@ -0,0 +1,3 @@
h1 = @codeharbor_link
= render('form')

View File

@ -0,0 +1,18 @@
h1 = CodeharborLink.model_name.human(count: 2)
.table-responsive
table.table
thead
tr
th = t('activerecord.attributes.codeharbor_link.oauth2token')
th colspan=3 = t('shared.actions')
tbody
- @codeharbor_links.each do |codeharbor_link|
tr
td = link_to_if(policy(codeharbor_link).show?, codeharbor_link.oauth2token, codeharbor_link)
td = link_to(t('shared.show'), codeharbor_link) if policy(codeharbor_link).show?
td = link_to(t('shared.edit'), edit_codeharbor_link_path(codeharbor_link)) if policy(codeharbor_link).edit?
td = link_to(t('shared.destroy'), codeharbor_link, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(codeharbor_link).destroy?
= render('shared/pagination', collection: @codeharbor_links)
p = render('shared/new_button', model: CodeharborLink)

View File

@ -0,0 +1,3 @@
h1 = t('shared.new_model', model: CodeharborLink.model_name.human)
= render('form')

View File

@ -0,0 +1,7 @@
h1
= @codeharbor_link
= render('shared/edit_button', object: @codeharbor_link)
- %w[oauth2token].each do |attribute|
= row(label: "codeharbor_link.#{attribute}") do
= content_tag(:input, nil, class: 'form-control', readonly: true, value: @codeharbor_link.send(attribute))

View File

@ -7,3 +7,9 @@ h1
= row(label: 'internal_user.consumer', value: @user.consumer ? link_to_if(policy(@user.consumer).show?, @user.consumer, @user.consumer) : nil) = row(label: 'internal_user.consumer', value: @user.consumer ? link_to_if(policy(@user.consumer).show?, @user.consumer, @user.consumer) : nil)
= row(label: 'internal_user.role', value: t("users.roles.#{@user.role}")) = row(label: 'internal_user.role', value: t("users.roles.#{@user.role}"))
= row(label: 'internal_user.activated', value: @user.activated?) = row(label: 'internal_user.activated', value: @user.activated?)
- if @user.codeharbor_link.nil?
= row(label: 'codeharbor_link.new', value: link_to(t('codeharbor_link.new'), codeharbor_link_new_path, class: 'btn btn-secondary'))
- else
= row(label: 'codeharbor_link.edit', value: link_to(t('codeharbor_link.edit'), edit_codeharbor_link_path(@user.codeharbor_link), class: 'btn btn-secondary'))

View File

@ -1,7 +1,7 @@
de: de:
activerecord: activerecord:
attributes: attributes:
code_harbor_link: codeharbor_link:
oauth2token: OAuth2 Token oauth2token: OAuth2 Token
consumer: consumer:
name: Name name: Name

View File

@ -1,7 +1,7 @@
en: en:
activerecord: activerecord:
attributes: attributes:
code_harbor_link: codeharbor_link:
oauth2token: OAuth2 Token oauth2token: OAuth2 Token
consumer: consumer:
name: Name name: Name
@ -240,6 +240,10 @@ en:
consumers: consumers:
show: show:
link: Consumer link: Consumer
codeharbor_link:
profile_label: Codeharbor Link
new: Create link to Codeharbor
edit: Edit existing link
execution_environments: execution_environments:
form: form:
hints: hints:

View File

@ -13,7 +13,7 @@ Rails.application.routes.draw do
get 'by_file_type/:file_type_id', as: :by_file_type, action: :by_file_type get 'by_file_type/:file_type_id', as: :by_file_type, action: :by_file_type
end end
end end
# resources :code_harbor_links resources :codeharbor_links
resources :request_for_comments do resources :request_for_comments do
member do member do
get :mark_as_solved, defaults: { format: :json } get :mark_as_solved, defaults: { format: :json }