From fcdcd45da91dd9d9584561d79d4c449fb2819a98 Mon Sep 17 00:00:00 2001 From: fosterfarrell9 <28628554+fosterfarrell9@users.noreply.github.com> Date: Mon, 10 Apr 2023 14:14:18 +0200 Subject: [PATCH 01/22] make some changes regarding what rights media editors have --- app/abilities/lecture_ability.rb | 2 +- app/abilities/quiz_certificate_ability.rb | 2 +- app/abilities/tutorial_ability.rb | 2 +- app/abilities/user_ability.rb | 8 ++++-- app/assets/javascripts/lectures.coffee | 1 - app/controllers/media_controller.rb | 4 +-- app/controllers/users_controller.rb | 5 ---- app/models/lecture.rb | 10 +++++++ app/models/medium.rb | 17 ++++++++++-- app/models/user.rb | 16 +++++++++-- app/views/lectures/edit/_form.html.erb | 6 +++-- app/views/lectures/edit/_people.html.erb | 3 ++- app/views/media/_basics.html.erb | 33 +++++++---------------- app/views/users/list.json.jbuilder | 4 --- config/locales/de.yml | 4 +-- config/locales/en.yml | 7 ++--- config/routes.rb | 6 +---- 17 files changed, 72 insertions(+), 58 deletions(-) delete mode 100644 app/views/users/list.json.jbuilder diff --git a/app/abilities/lecture_ability.rb b/app/abilities/lecture_ability.rb index 5480923c4..c465cd87d 100644 --- a/app/abilities/lecture_ability.rb +++ b/app/abilities/lecture_ability.rb @@ -33,7 +33,7 @@ def initialize(user) end can :subscribe_page, Lecture do |lecture| - lecture.published? || !user.generic? + lecture.published? || user.can_edit_teachables? end end end \ No newline at end of file diff --git a/app/abilities/quiz_certificate_ability.rb b/app/abilities/quiz_certificate_ability.rb index 206827a25..ec494aec4 100644 --- a/app/abilities/quiz_certificate_ability.rb +++ b/app/abilities/quiz_certificate_ability.rb @@ -7,7 +7,7 @@ def initialize(user) can :claim, QuizCertificate can :validate, QuizCertificate do - user.tutor? || !user.generic? + user.tutor? || user.can_edit_teachables? end end end \ No newline at end of file diff --git a/app/abilities/tutorial_ability.rb b/app/abilities/tutorial_ability.rb index d17014db1..260a09b40 100644 --- a/app/abilities/tutorial_ability.rb +++ b/app/abilities/tutorial_ability.rb @@ -24,7 +24,7 @@ def initialize(user) end can :validate_certificate, Tutorial do - user.tutor? || !user.generic? + user.tutor? || user.can_edit_teachables? end end end diff --git a/app/abilities/user_ability.rb b/app/abilities/user_ability.rb index 77356b1fd..506fcb944 100644 --- a/app/abilities/user_ability.rb +++ b/app/abilities/user_ability.rb @@ -14,8 +14,12 @@ def initialize(user) user.admin? || (!user.generic? && user == given_user) end - can [:fill_user_select, :list, :list_generic_users], User do - !user.generic? + can :fill_user_select, User do + !user.can_edit_teachables? + end + + can :list_generic_users, User do + user.admin? end end end \ No newline at end of file diff --git a/app/assets/javascripts/lectures.coffee b/app/assets/javascripts/lectures.coffee index d47ede273..7fe308c6e 100644 --- a/app/assets/javascripts/lectures.coffee +++ b/app/assets/javascripts/lectures.coffee @@ -187,7 +187,6 @@ $(document).on 'turbolinks:load', -> lecture: lectureId } success: (result) -> - $('#lectureUserCounter').append(result.length) $('#lectureUserModalButton').hide() if result.length == 0 for u in result row = document.createElement('div') diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 3f4c03d8a..a3dbe1560 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -213,7 +213,7 @@ def search authorize! :search, Medium.new # get all media, then set them to only those that are visible to the current user - if current_user.generic? || search_params[:access].blank? + if !current_user.can_edit_teachables? || search_params[:access].blank? filter_media = true params["search"]["access"] = 'irrelevant' end @@ -224,7 +224,7 @@ def search results = search.results @total = search.total - # in the case of a search with tag_operator 'or', we + # in the case of a search with tag_operator 'or', we # execute two searches and merge the results, where media # with the selected tags are now shown at the front of the list if search_params[:tag_operator] == "or" and search_params[:all_tags] == "0" and search_params[:fulltext].size >= 2 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 41889d377..a60f05ff9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -48,11 +48,6 @@ def elevate end end - def list - search = User.search { fulltext params[:term] } - @users = search.results - end - def list_generic_users result = User.where.not(id: @elevated_users.pluck(:id)) .values_for_select diff --git a/app/models/lecture.rb b/app/models/lecture.rb index 4f510aecf..b1d288c23 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -771,6 +771,16 @@ def import_toc!(imported_lecture, import_sections, import_tags) end end + def speakers + return User.none unless seminar? + User.where(id: SpeakerTalkJoin.where(talk: talks).pluck(:speaker_id)) + end + + def older_than?(timespan) + return true unless term + term.begin_date < Term.active.begin_date - timespan + end + private # used for after save callback diff --git a/app/models/medium.rb b/app/models/medium.rb index 687e24a37..af326c2b8 100644 --- a/app/models/medium.rb +++ b/app/models/medium.rb @@ -282,7 +282,7 @@ def self.search_by(search_params, page) .teachables_as_strings search_params[:editor_ids] = [] if search_params[:all_editors] == '1' || search_params[:all_editors].nil? # add media without term to current term - + search_params[:all_terms] = '1' if search_params[:all_terms].blank? search_params[:all_teachers] = '1' if search_params[:all_teachers].blank? search_params[:term_ids].push('0') if search_params[:term_ids].present? @@ -454,6 +454,19 @@ def editors_with_inheritance (result + teachable.speakers).uniq end + # returns the array of users that are eligible to obtain editing rights + # for the given medium from the given user + def eligible_editors(user) + result = editors_with_inheritance + + if teachable.is_a?(Talk) && user.can_edit?(lecture) + result += lecture.speakers + end + + result << user if user.admin? + result.uniq + end + # creates a .vtt tmp file (and returns it), which contains # all data needed by the thyme player to realize the toc @@ -1201,5 +1214,5 @@ def answers_count return -1 unless type == 'Question' becomes(Question).answers.count end - + end diff --git a/app/models/user.rb b/app/models/user.rb index 58a29840f..c29d88f44 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -293,10 +293,22 @@ def teacher? given_lectures.any? end + def teachable_editor? + edited_courses.any? || edited_lectures.any? + end + + def teachable_editor_or_teacher? + teachable_editor? || teacher? + end + + def can_edit_teachables? + admin? || teachable_editor_or_teacher? + end + # a user is an editor iff he/she is a course editor or lecture editor or # editor of media that are not associated to talks def editor? - edited_courses.any? || edited_lectures.any? || + teachable_editor || edited_media.where.not(teachable_type: 'Talk').any? end @@ -525,7 +537,7 @@ def subscribe_lecture!(lecture) return false unless lecture.is_a?(Lecture) return false if lecture.in?(lectures) lectures << lecture - + # make sure subscribed_users is updated in media Sunspot.index! lecture.media diff --git a/app/views/lectures/edit/_form.html.erb b/app/views/lectures/edit/_form.html.erb index 1daabd7d3..1502ac284 100644 --- a/app/views/lectures/edit/_form.html.erb +++ b/app/views/lectures/edit/_form.html.erb @@ -54,8 +54,10 @@ <%= render partial: 'announcements/modal' %> <%= render partial: 'lectures/publish/publish', locals: { lecture: lecture } %> - <%= render partial: 'lectures/edit/user_modal', - locals: { lecture: lecture } %> + <% unless lecture.older_than?(1.year) %> + <%= render partial: 'lectures/edit/user_modal', + locals: { lecture: lecture } %> + <% end %> <% if !lecture.seminar? || lecture.legacy_seminar %> <%= render partial: 'chapters/modal', locals: { lecture: lecture } %> diff --git a/app/views/lectures/edit/_people.html.erb b/app/views/lectures/edit/_people.html.erb index 5361d395d..fb1b53472 100644 --- a/app/views/lectures/edit/_people.html.erb +++ b/app/views/lectures/edit/_people.html.erb @@ -81,9 +81,10 @@
<%= t('basics.subscribers_count_nc') %> + <%= lecture.users.count %> <%= helpdesk(t('admin.lecture.info.subscribers_count'), false) %> - <% if lecture.users.any? %> + <% if lecture.users.any? && !lecture.older_than?(1.year)%> - <% end %> +
+
+ <%= t('basics.subscribers_count_nc') %> + + <%= lecture.users.count %> + + <%= helpdesk(t('admin.lecture.info.subscribers_count'), false) %> + <% if lecture.users.any? && !lecture.older_than?(1.year)%> + + <% end %> +
-
-
-
-
- <%= t('warnings.unsaved_changes') %> - <%= f.submit t('buttons.save'), - class: "btn btn-sm btn-primary" %> - +
+
+
+ <%= t('warnings.unsaved_changes') %> + <%= f.submit t('buttons.save'), + class: "btn btn-sm btn-primary" %> + +
-
+ <% end %> + <% else %> + <%= t('admin.lecture.no_access_to_users_html', + project_mail: mail_to(DefaultSetting::PROJECT_EMAIL, nil)) %> <% end %>
diff --git a/app/views/lectures/edit/_tutorials.html.erb b/app/views/lectures/edit/_tutorials.html.erb index 0d889d08f..0bb1d50a3 100644 --- a/app/views/lectures/edit/_tutorials.html.erb +++ b/app/views/lectures/edit/_tutorials.html.erb @@ -19,43 +19,48 @@ aria-labelledby="heading" data-parent="#lectureAccordion">
-
-
- <%= link_to t('admin.tutorial.new'), - new_tutorial_path(params: { lecture_id: lecture.id }), - class: 'btn btn-sm btn-primary', - id: 'newTutorialButton', - remote: true %> + <% if current_user.can_view_users?(lecture) %> +
+
+ <%= link_to t('admin.tutorial.new'), + new_tutorial_path(params: { lecture_id: lecture.id }), + class: 'btn btn-sm btn-primary', + id: 'newTutorialButton', + remote: true %> +
-
-
-
-
-
-
- <%= t('basics.title') %> -
-
-
-
- <%= t('basics.tutors') %> -
-
-
-
- <%= t('basics.action') %> - <%= helpdesk(t('tutorial.destruction_info'), true) %> -
+
+
+
+
+
+ <%= t('basics.title') %> +
+
+
+
+ <%= t('basics.tutors') %> +
+
+
+
+ <%= t('basics.action') %> + <%= helpdesk(t('tutorial.destruction_info'), true) %> +
+
+ <% lecture.tutorials.each do |t| %> + <%= render partial: 'tutorials/row', + locals: { tutorial: t } %> + <% end %>
- <% lecture.tutorials.each do |t| %> - <%= render partial: 'tutorials/row', - locals: { tutorial: t } %> - <% end %> -
+ <% else %> + <%= t('admin.lecture.no_access_to_users_html', + project_mail: mail_to(DefaultSetting::PROJECT_EMAIL, nil)) %> + <% end %>
\ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index b94370128..88c0d4694 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -650,6 +650,11 @@ de: insert_after_chapter: 'Einfügen nach %{chapter_name}' insert_after_section: 'Einfügen nach Abschnitt' subscribers: 'AbonnentInnen' + no_access_to_users_html: > + Diese Vorlesung ist älter als ein Jahr. Aus Datenschutzgründen können + nur die DozentIn und ModuleditorInnen an dieser Stelle Änderungen + vornehmen. Sollten aus wichtigem Grund noch Änderungen an dieser Stelle + gemacht werden, kannst Du Dich per Email an %{project_mail} wenden. clicker: new_clicker: 'Neuen Clicker anlegen' user_link: 'Link für NutzerInnen' diff --git a/config/locales/en.yml b/config/locales/en.yml index 04cde8f4a..188842953 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -620,6 +620,11 @@ en: insert_after_chapter: 'Insert after %{chapter_name}' insert_after_section: 'Insert after section' subscribers: 'Subscribers' + no_access_to_users_html: > + This lecture is older than 1 year. For reasons of data privacy, + only the teahcer and course editors can make changes here. + If changes are necessary for some reason, you can contact the + site administrators by mail: %{project_mail}. clicker: new_clicker: 'Create new Clicker' user_link: 'Link for users' From ace66cbdde5de145034067d5dc73a9783641b78c Mon Sep 17 00:00:00 2001 From: fosterfarrell9 <28628554+fosterfarrell9@users.noreply.github.com> Date: Sat, 29 Apr 2023 01:22:36 +0200 Subject: [PATCH 04/22] make some changes suggested by referee --- app/models/lecture.rb | 4 ++++ app/models/user.rb | 6 +++--- app/views/lectures/edit/_form.html.erb | 2 +- app/views/lectures/edit/_people.html.erb | 2 +- config/locales/de.yml | 2 +- config/locales/en.yml | 6 +++--- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/models/lecture.rb b/app/models/lecture.rb index b1d288c23..e368dc42f 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -781,6 +781,10 @@ def older_than?(timespan) term.begin_date < Term.active.begin_date - timespan end + def stale? + older_than?(1.year) + end + private # used for after save callback diff --git a/app/models/user.rb b/app/models/user.rb index eefc44b38..79ca5543d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -313,7 +313,7 @@ def active_teachable_editor? return false unless can_edit_teachables? return true if admin || course_editor? || teacher? - edited_lectures.select { |l| l.term.nil? || !l.older_than?(1.year)} + edited_lectures.select { |l| l.term.nil? || !stale? } .any? end @@ -721,9 +721,9 @@ def can_view_users?(lecture) return false unless can_edit?(lecture) return true if can_edit?(lecture.course) || lecture.teacher == self return true if lecture.course.term_independent - return true if !lecture.older_than?(1.year) + return true if !lecture.stale? - false + return false end private diff --git a/app/views/lectures/edit/_form.html.erb b/app/views/lectures/edit/_form.html.erb index 1502ac284..cd5a50857 100644 --- a/app/views/lectures/edit/_form.html.erb +++ b/app/views/lectures/edit/_form.html.erb @@ -54,7 +54,7 @@ <%= render partial: 'announcements/modal' %> <%= render partial: 'lectures/publish/publish', locals: { lecture: lecture } %> - <% unless lecture.older_than?(1.year) %> + <% unless lecture.stale? %> <%= render partial: 'lectures/edit/user_modal', locals: { lecture: lecture } %> <% end %> diff --git a/app/views/lectures/edit/_people.html.erb b/app/views/lectures/edit/_people.html.erb index 1ad86cbc1..0435b8383 100644 --- a/app/views/lectures/edit/_people.html.erb +++ b/app/views/lectures/edit/_people.html.erb @@ -87,7 +87,7 @@ <%= lecture.users.count %> <%= helpdesk(t('admin.lecture.info.subscribers_count'), false) %> - <% if lecture.users.any? && !lecture.older_than?(1.year)%> + <% if lecture.users.any? && !lecture.stale? %>