Always create a default study group for new consumers
This commit is contained in:

committed by
Sebastian Serth

parent
521626275f
commit
cb1b163b30
@@ -12,6 +12,13 @@ class Consumer < ApplicationRecord
|
||||
validates :oauth_key, presence: true, uniqueness: true
|
||||
validates :oauth_secret, presence: true
|
||||
|
||||
after_create :generate_internal_study_group
|
||||
|
||||
def generate_internal_study_group
|
||||
StudyGroup.create!(consumer: self, name: "Default Study Group for #{name}", external_id: nil)
|
||||
end
|
||||
private :generate_internal_study_group
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
@@ -5,10 +5,17 @@ class StudyGroupPolicy < AdminOnlyPolicy
|
||||
admin? || teacher?
|
||||
end
|
||||
|
||||
%i[show? destroy? edit? update? stream_la?].each do |action|
|
||||
%i[show? edit? update? stream_la?].each do |action|
|
||||
define_method(action) { admin? || (@user.teacher? && @record.present? && @user.study_groups.exists?(@record.id)) }
|
||||
end
|
||||
|
||||
def destroy?
|
||||
# A default study group should not get deleted without the consumer
|
||||
return no_one if @record.external_id.blank?
|
||||
|
||||
admin? || teacher_in_study_group?
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
if @user.admin?
|
||||
|
Reference in New Issue
Block a user