diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 0304abb4..45fd04d9 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -9,7 +9,6 @@ class ExercisesController < ApplicationController before_action :set_exercise, only: MEMBER_ACTIONS + [:clone, :implement, :run, :statistics, :submit, :reload] before_action :set_external_user, only: [:statistics] before_action :set_file_types, only: [:create, :edit, :new, :update] - before_action :set_teams, only: [:create, :edit, :new, :update] skip_before_filter :verify_authenticity_token, only: [:import_proforma_xml] skip_after_action :verify_authorized, only: [:import_proforma_xml] @@ -119,7 +118,7 @@ class ExercisesController < ApplicationController private :user_by_code_harbor_token def exercise_params - params[:exercise].permit(:description, :execution_environment_id, :file_id, :instructions, :public, :hide_file_tree, :allow_file_creation, :team_id, :title, files_attributes: file_attributes).merge(user_id: current_user.id, user_type: current_user.class.name) + params[:exercise].permit(:description, :execution_environment_id, :file_id, :instructions, :public, :hide_file_tree, :allow_file_creation, :title, files_attributes: file_attributes).merge(user_id: current_user.id, user_type: current_user.class.name) end private :exercise_params @@ -195,11 +194,6 @@ class ExercisesController < ApplicationController end private :set_file_types - def set_teams - @teams = Team.all.order(:name) - end - private :set_teams - def show end diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 4a1e0486..24570dc6 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -10,8 +10,7 @@ class Exercise < ActiveRecord::Base after_initialize :set_default_values belongs_to :execution_environment - has_many :submissions - belongs_to :team + has_many :submission has_many :external_users, source: :user, source_type: ExternalUser, through: :submissions has_many :internal_users, source: :user, source_type: InternalUser, through: :submissions diff --git a/app/models/internal_user.rb b/app/models/internal_user.rb index e5cebde9..8f1bf04b 100644 --- a/app/models/internal_user.rb +++ b/app/models/internal_user.rb @@ -3,8 +3,6 @@ class InternalUser < ActiveRecord::Base authenticates_with_sorcery! - has_and_belongs_to_many :teams - validates :email, presence: true, uniqueness: true validates :password, confirmation: true, if: :password_void?, on: :update, presence: true validates :role, inclusion: {in: ROLES} diff --git a/app/policies/exercise_policy.rb b/app/policies/exercise_policy.rb index 29a1c570..d30c4aff 100644 --- a/app/policies/exercise_policy.rb +++ b/app/policies/exercise_policy.rb @@ -13,23 +13,19 @@ class ExercisePolicy < AdminOrAuthorPolicy end [:clone?, :destroy?, :edit?, :statistics?, :update?].each do |action| - define_method(action) { admin? || author? || team_member? } + define_method(action) { admin? || author?} end [:implement?, :submit?, :reload?].each do |action| define_method(action) { everyone } end - def team_member? - @record.team.try(:members, []).include?(@user) if @record.team - end - private :team_member? - class Scope < Scope def resolve if @user.admin? @scope.all elsif @user.internal_user? + #need to remove team query @scope.where('user_id = ? OR public = TRUE OR (team_id IS NOT NULL AND team_id IN (SELECT t.id FROM teams t JOIN internal_users_teams iut ON t.id = iut.team_id WHERE iut.internal_user_id = ?))', @user.id, @user.id) else @scope.none diff --git a/app/views/exercises/_form.html.slim b/app/views/exercises/_form.html.slim index f0f69f7a..968540af 100644 --- a/app/views/exercises/_form.html.slim +++ b/app/views/exercises/_form.html.slim @@ -17,9 +17,6 @@ = f.label(:instructions) = f.hidden_field(:instructions) .form-control.markdown - /.form-group - = f.label(:team_id) - = f.collection_select(:team_id, @teams, :id, :name, {include_blank: true}, class: 'form-control') .checkbox label = f.check_box(:public) diff --git a/app/views/exercises/show.html.slim b/app/views/exercises/show.html.slim index b4b72932..5c554da8 100644 --- a/app/views/exercises/show.html.slim +++ b/app/views/exercises/show.html.slim @@ -12,7 +12,6 @@ h1 = row(label: 'exercise.description', value: render_markdown(@exercise.description)) = row(label: 'exercise.execution_environment', value: link_to_if(policy(@exercise.execution_environment).show?, @exercise.execution_environment, @exercise.execution_environment)) /= row(label: 'exercise.instructions', value: render_markdown(@exercise.instructions)) -= row(label: 'exercise.team', value: @exercise.team ? link_to(@exercise.team, @exercise.team) : nil) = row(label: 'exercise.maximum_score', value: @exercise.maximum_score) = row(label: 'exercise.public', value: @exercise.public?) = row(label: 'exercise.hide_file_tree', value: @exercise.hide_file_tree?) diff --git a/config/locales/de.yml b/config/locales/de.yml index 53df1858..ce8ba98f 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -34,8 +34,6 @@ de: instructions: Anweisungen maximum_score: Erreichbare Punktzahl public: Öffentlich - team: Team - team_id: Team title: Titel user: Autor allow_file_creation: "Dateierstellung erlauben" @@ -91,9 +89,6 @@ de: files: Dateien score: Punktzahl user: Autor - team: - internal_user_ids: Mitglieder - name: Name models: code_harbor_link: one: CodeHarbor-Link @@ -128,9 +123,6 @@ de: submission: one: Abgabe other: Abgaben - team: - one: Team - other: Teams errors: messages: together: 'muss zusammen mit %{attribute} definiert werden' diff --git a/config/locales/en.yml b/config/locales/en.yml index 1e72cb34..86acbb15 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -34,8 +34,6 @@ en: instructions: Instructions maximum_score: Maximum Score public: Public - team: Team - team_id: Team title: Title user: Author allow_file_creation: "Allow file creation" @@ -91,9 +89,6 @@ en: files: Files score: Score user: Author - team: - internal_user_ids: Members - name: Name models: code_harbor_link: one: CodeHarbor Link @@ -128,9 +123,6 @@ en: submission: one: Submission other: Submissions - team: - one: Team - other: Teams errors: messages: together: 'has to be set along with %{attribute}' diff --git a/config/routes.rb b/config/routes.rb index a6ca545c..f13d1c9f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,5 +99,4 @@ Rails.application.routes.draw do end end - resources :teams end