Skip to content

Commit

Permalink
Restrict access user select
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterfarrell9 committed Aug 18, 2024
1 parent 6b662ea commit 9d441ff
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 35 deletions.
6 changes: 1 addition & 5 deletions app/abilities/user_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ def initialize(user)
user.admin? || (!user.generic? && user == given_user)
end

can :fill_user_select, User do
user.active_teachable_editor?
end

can :list_generic_users, User do
can [:fill_user_select, :list_generic_users], User do
user.admin?
end
end
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/lectures_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,16 @@ def editors_preselection(lecture)
[editor.info, editor.id]
end, lecture.editor_ids)
end

def teachers_preselection(lecture)
options_for_select(lecture.eligible_as_teachers.map do |teacher|
[teacher.info, teacher.id]
end, lecture.teacher_id)
end

def teachers_preselection_for_new_lecture(lecture)

Check failure on line 145 in app/helpers/lectures_helper.rb

View workflow job for this annotation

GitHub Actions / RuboCop (Ruby)

Lint/UnusedMethodArgument: Unused method argument - `lecture`. If it's necessary, use `_` or `_lecture` as an argument name to indicate that it won't be used. If it's unnecessary, remove it. You can also write as `teachers_preselection_for_new_lecture(*)` if you want the method to accept any arguments but don't care about them.
options_for_select((User.teachers + [current_user]).map do |teacher|
[teacher.info, teacher.id]
end)
end
end
4 changes: 4 additions & 0 deletions app/models/lecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ def eligible_as_editors
# still given by the old system, this will not be true
end

def eligible_as_teachers
(User.teachers + editors + course.editors + [teacher]).uniq
end

def eligible_as_speakers
(speakers + speakers_by_redemption + editors + [teacher]).uniq
# the first one should (in the future) actually be contained in the sum of
Expand Down
14 changes: 8 additions & 6 deletions app/views/administration/index/_my_courses.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
</div>
</div>
<div class="card-body scrollable">
<div id="new-course-area"
class="bg-green-lighten-4 p-3 mb-3 rounded"
style="display: none;">
<%= render partial: 'courses/new',
locals: { course: Course.new } %>
</div>
<% if current_user.admin? %>
<div id="new-course-area"
class="bg-green-lighten-4 p-3 mb-3 rounded"
style="display: none;">
<%= render partial: 'courses/new',
locals: { course: Course.new } %>
</div>
<% end %>
<% if current_user.edited_courses.any? %>
<%= render partial: 'administration/index/courses_card',
locals: { courses:
Expand Down
31 changes: 19 additions & 12 deletions app/views/lectures/_new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,25 @@
t('basics.teacher'),
class: "form-label" %>
<%= helpdesk(t('admin.lecture.info.teacher'), false) %>
<%= f.select :teacher_id,
options_for_select([[current_user.info, current_user.id]],
current_user.id),
{},
{ class: 'selectize',
data: { ajax: true,
model: 'user',
filled: false,
placeholder: t('basics.enter_two_letters'),
no_results: t('basics.no_results'),
current: current_user.id,
modal: modal } } %>
<% if current_user.admin? %>
<%= f.select :teacher_id,
options_for_select([[current_user.info, current_user.id]],
current_user.id),
{},
{ class: 'selectize',
data: { ajax: true,
model: 'user',
filled: false,
placeholder: t('basics.enter_two_letters'),
no_results: t('basics.no_results'),
current: current_user.id,
modal: modal } } %>
<% else %>
<%= f.select :teacher_id,
teachers_preselection_for_new_lecture(lecture),
{},
{ class: 'selectize' } %>
<% end %>
</div>
<div class="col-12" id="newLectureSort"
style="<%= term_independent ? 'display: none;' : '' %>">
Expand Down
31 changes: 19 additions & 12 deletions app/views/lectures/edit/_people.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@
class: "form-label" %>
<%= helpdesk(t('admin.lecture.info.teacher'), false) %>
<div id="lecture_teacher_select" %>
<%= f.select :teacher_id,
options_for_select([[lecture.teacher.info,
lecture.teacher.id]],
lecture.teacher.id),
{},
{ class: 'selectize',
data: { ajax: true,
model: 'user',
filled: false,
placeholder:
t('basics.enter_two_letters'),
no_results:
<% if current_user.admin? %>
<%= f.select :teacher_id,
options_for_select([[lecture.teacher.info,
lecture.teacher.id]],
lecture.teacher.id),
{},
{ class: 'selectize',
data: { ajax: true,
model: 'user',
filled: false,
placeholder:
t('basics.enter_two_letters'),
no_results:
t('basics.no_results') } } %>
<% else %>
<%= f.select :teacher_id,
teachers_preselection(lecture),
{},
{ class: 'selectize' } %>
<% end %>
<div class="invalid-feedback" id="lecture-teacher-error">
</div>
</div>
Expand Down

0 comments on commit 9d441ff

Please sign in to comment.