Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draft flag to activities #4998

Merged
merged 35 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5a45932
Add draft flag to DB (and config?)
jorg-vr Sep 22, 2023
08a6d41
Add draft mode to edit screen
jorg-vr Sep 22, 2023
685ed5d
Update access rights for draft activities
jorg-vr Sep 22, 2023
8be1451
Do not email draft errors
jorg-vr Sep 22, 2023
64b2d96
Fix don't sent email function
jorg-vr Sep 22, 2023
4c4d4c3
Allow editing draft in the policy
jorg-vr Sep 22, 2023
2f570b8
Show draft images on home page
jorg-vr Sep 25, 2023
adb0e50
Visualise draft modus for lists
jorg-vr Sep 25, 2023
a4307f5
Filter activities by draft flag
jorg-vr Sep 25, 2023
8535338
Add draft warning to the top of the page
jorg-vr Sep 26, 2023
71c5747
Fix server file
jorg-vr Sep 26, 2023
0c56209
Fix existing tests
jorg-vr Sep 26, 2023
ea8a8ef
Fix linting
jorg-vr Sep 26, 2023
fb6cbae
Add page access tests
jorg-vr Sep 26, 2023
4e0fceb
Update app/views/pages/_user_card.html.erb
jorg-vr Sep 27, 2023
7b8bfaa
Update config/locales/views/activities/nl.yml
jorg-vr Sep 27, 2023
2e9dfbf
Mark as draft during repository reprocess
jorg-vr Oct 11, 2023
15736e2
Update translation from ontwerp to concept
jorg-vr Oct 11, 2023
d34e984
Revert "Mark as draft during repository reprocess"
jorg-vr Oct 11, 2023
5cf0f25
Always update draft flag
jorg-vr Oct 11, 2023
a8647ac
Apply suggestions from code review
jorg-vr Oct 19, 2023
0d493d2
Concept => ongepubliceerd
jorg-vr Oct 19, 2023
29deee3
Merge branch 'main' into feat/add-draft-flag
jorg-vr Oct 19, 2023
925b65a
Add links to doc
jorg-vr Oct 19, 2023
3a39a7a
Undo unwanted annotations
jorg-vr Oct 19, 2023
4817cf4
Merge branch 'main' into feat/add-draft-flag
jorg-vr Oct 26, 2023
9a4499c
Apply feedback to simplify pr
jorg-vr Oct 26, 2023
242f61a
Do not allow reset to draft
jorg-vr Oct 26, 2023
7fc6a26
Fix tests
jorg-vr Oct 26, 2023
87a0c7d
Update icon layout in lists
jorg-vr Oct 26, 2023
4f601a9
Restore always showing col
jorg-vr Oct 26, 2023
715f25c
Reset code to original
jorg-vr Oct 26, 2023
587056b
Add some draft activities in the seed
jorg-vr Oct 26, 2023
bd08828
Add draft notice to all pages
jorg-vr Oct 26, 2023
a17cb6a
Move validation to policy
jorg-vr Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ActivitiesController < ApplicationController
has_scope :by_description_languages, as: 'description_languages', type: :array
has_scope :by_judge, as: 'judge_id'
has_scope :by_popularities, as: 'popularity', type: :array
has_scope :is_draft, as: 'draft', type: :boolean

has_scope :repository_scope, as: 'tab' do |controller, scope, value|
course = Series.find(controller.params[:id]).course if controller.params[:id]
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def home
@homepage_series = courses.map { |c| c.homepage_series(current_user, 0) }.flatten.sort_by(&:deadline)

@jump_back_in = current_user.jump_back_in

@draft_exercises = current_user.draft_exercises.reorder(updated_at: :desc) if current_user.a_repository_admin?
else
set_metrics
respond_to do |format|
Expand Down
19 changes: 15 additions & 4 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# description_nl_present :boolean default(FALSE)
# description_en_present :boolean default(FALSE)
# series_count :integer default(0), not null
# draft :boolean default(FALSE)
#

require 'pathname'
Expand Down Expand Up @@ -66,6 +67,7 @@ class Activity < ApplicationRecord
before_create :generate_repository_token,
if: ->(ex) { ex.repository_token.nil? }
before_create :generate_access_token
before_create :activate_draft_mode
before_update :update_config

scope :content_pages, -> { where(type: ContentPage.name) }
Expand All @@ -80,6 +82,7 @@ class Activity < ApplicationRecord
scope :by_programming_language, ->(programming_language) { includes(:programming_language).where(programming_languages: { name: programming_language }) }
scope :by_type, ->(type) { where(type: type) }
scope :by_judge, ->(judge) { where(judge_id: judge) }
scope :is_draft, -> { where(draft: true) }
scope :by_description_languages, lambda { |languages|
by_language = all # allow chaining of scopes
by_language = by_language.where(description_en_present: true) if languages.include? 'en'
Expand Down Expand Up @@ -298,6 +301,7 @@ def update_config
c = config
c.delete('visibility')
c['access'] = access if defined?(access) && access != merged_config['access']
c['draft'] = draft if defined?(draft)
c['description']['names']['nl'] = name_nl if name_nl.present? || c['description']['names']['nl'].present?
c['description']['names']['en'] = name_en if name_en.present? || c['description']['names']['en'].present?
c['internals'] = {}
Expand All @@ -316,19 +320,22 @@ def accessible?(user, course)
if user&.course_admin? course
return false unless course.activities.pluck(:id).include? id
elsif user&.member_of? course
return false unless course.accessible_activities.pluck(:id).include? id
else
return false unless course.visible_activities.pluck(:id).include? id
return false if course.accessible_activities.pluck(:id).exclude?(id) || draft?
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
elsif course.visible_activities.pluck(:id).exclude?(id) || draft?
return false
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
end
return true if user&.zeus?
return false unless access_public? \
|| repository.allowed_courses.pluck(:id).include?(course&.id)
return true if user&.member_of? course
return true if user&.course_admin? course
return false if draft?
return true if user&.member_of?(course)
return false if course.moderated && access_private?

course.open_for_user?(user)
else
return true if user&.repository_admin? repository
return false if draft?

access_public?
end
Expand Down Expand Up @@ -506,4 +513,8 @@ def unique_labels(hash)
hash['labels'] = hash['labels'].uniq if hash.key? 'labels'
hash
end

def activate_draft_mode
self.draft = true
end
end
1 change: 1 addition & 0 deletions app/models/content_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# description_nl_present :boolean default(FALSE)
# description_en_present :boolean default(FALSE)
# series_count :integer default(0), not null
# draft :boolean default(FALSE)
#

class ContentPage < Activity
Expand Down
1 change: 1 addition & 0 deletions app/models/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# description_nl_present :boolean default(FALSE)
# description_en_present :boolean default(FALSE)
# series_count :integer default(0), not null
# draft :boolean default(FALSE)
#

require 'pathname'
Expand Down
1 change: 1 addition & 0 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ def update_fs
end

def report_if_internal_error
return if exercise&.draft?
return unless status_changed? && send(:'internal error?')

ExceptionNotifier.notify_exception(
Expand Down
7 changes: 7 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class User < ApplicationRecord
has_many :repositories,
through: :repository_admins,
source: :repository
has_many :draft_exercises,
lambda {
where activities:
{ draft: true }
},
through: :repositories,
source: :exercises

has_many :annotations, dependent: :restrict_with_error
has_many :questions, dependent: :restrict_with_error
Expand Down
4 changes: 2 additions & 2 deletions app/policies/activity_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def resolve
if user&.zeus?
scope.all
else
scope.where(access: :public, status: :ok).or(scope.where(repository: user&.repositories))
scope.where(access: :public, status: :ok, draft: false).or(scope.where(repository: user&.repositories))
end
end
end
Expand Down Expand Up @@ -75,7 +75,7 @@ def read?

def permitted_attributes
if update?
%i[access name_nl name_en]
%i[access name_nl name_en draft]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also check here that draft can only be updated if it's currently true. Might be a more clear than the validates in the model.

else
[]
end
Expand Down
21 changes: 12 additions & 9 deletions app/views/activities/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<% content_for :javascripts do %>
<% # TODO rename pack to activity %>
<% javascript_include_tag 'exercise' %>
<% end %>
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
<%= form_for(activity.becomes(Activity), :url => activity_scoped_path(activity: activity, course: @course, series: @series), :html => {:class => 'form-horizontal'}) do |f| %>
<% if activity.errors.any? %>
<div class="callout callout-danger" id="error_explanation">
Expand Down Expand Up @@ -30,15 +26,22 @@
<div class="col-sm-6 col-12"><%= f.text_field :labels, class: 'form-control', disable: !f.permission?(:labels), value: activity.labels.map(&:name).join(','), placeholder: t(".labels") %></div>
<span class="help-block offset-sm-3 col-sm-6 col-12"><%= t '.labels_delimiter' %></span>
</div>
<div class="field form-group row">
<%= f.label :draft, t(".draft.title"), :class => "col-sm-3 col-12 col-form-label" %>
<div class="col-sm-6 col-12 pt-2">
<div class="form-check">
<%= f.check_box :draft, class: 'form-check-input' %>
<%= f.label :draft, t(".draft.toggle-label"), class: 'form-check-label' %>
</div>
</div>
<span class="help-block offset-sm-3 col-sm-6 col-12"><%= t '.draft.help' %></span>
</div>
<div class="field form-group row">
<label class="col-sm-3 col-12 col-form-label"><%= t ".edit_activity" %></label>
<div class="col-sm-6 col-12 form-control-static"><%= link_to t(".open_on_github"), activity.github_url, target: '_blank', rel: 'noopener' %></div>
<div class="col-sm-6 col-12 form-control-static pt-2"><%= link_to t(".open_on_github"), activity.github_url, target: '_blank', rel: 'noopener' %></div>
</div>
<div class="field form-group row">
<label class="col-sm-3 col-12 col-form-label"><%= t ".info" %></label>
<div class="col-sm-6 col-12 form-control-static"><%= link_to t(".info_description"), info_activity_scoped_path(activity: @activity, course: @course, series: @series), rel: 'noopener' %></div>
<div class="col-sm-6 col-12 form-control-static pt-2"><%= link_to t(".info_description"), info_activity_scoped_path(activity: @activity, course: @course, series: @series), rel: 'noopener' %></div>
</div>
<% end %>
<script>
dodona.initLabelsEdit(<%= raw render template: 'labels/index', formats: :json %>, <%= raw (activity.merged_dirconfig['labels'] || []).to_json %>);
</script>
3 changes: 3 additions & 0 deletions app/views/activities/_repository_status.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
<% elsif activity.not_valid? %>
<i class="mdi mdi-alert-circle mdi-18" title="<%= t('activities.index.invalid') %>"></i>
<% end %>
<% if activity.draft? %>
<i class="mdi mdi-file-document-edit-outline mdi-18 colored-warning" title="<%= t('activities.index.draft-notice') %>"></i>
<% end %>
15 changes: 15 additions & 0 deletions app/views/activities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@
next_tooltip_actionable = next_activity ? t('.navigation.next_actionable') : t('.navigation.back_to_course_actionable')
end %>

<% if @activity.draft? %>
<div class="alert alert-warning">
<i class="mdi mdi-file-document-edit-outline"></i>
<%= t "activities.show.alert_draft" %>
<% if policy(@activity).edit? %>
<% edit_path = @series.present? ?
course_series_activity_path(@series&.course, @series, @activity, {activity: {draft: false}}) :
activity_path(@activity, {activity: {draft: false}})
%>
<%= link_to t("activities.show.alert_draft_edit"), edit_path, method: :put %>

<% end %>
</div>
<% end %>

<div class="row">
<% if @activity.exercise? %>
<div class="col-md-1 p-0">
Expand Down
21 changes: 21 additions & 0 deletions app/views/pages/_user_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@
</div>
</div>

<% if @draft_exercises.present? %>
<div class="card home-summary-card user">
<div class="card-supporting-text recents">
<h5><%= t ".draft-exercises" %></h5>
<% @draft_exercises.first(5).each do |exercise| %>
<p>
<%= link_to activity_submissions_path(exercise), class: 'btn-icon float-end' do %>
<i class="mdi mdi-chevron-right"></i>
<% end %>
<span class='float-start'><%= activity_icon exercise %></span>
<%= link_to exercise.name, activity_path(exercise), class: "course-link", title: exercise.name %>
<%= link_to exercise.repository.name, repository_path(exercise.repository), class: "small text-muted course-link", title: exercise.repository.name %>
</p>
<% end %>
<% if @draft_exercises.count > 5 %>
<%= link_to t(".all-draft-exercises") ,activities_path(draft: true) %>
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
<% end %>
</div>
</div>
<% end %>

<% deadlines = @homepage_series %>
<% if deadlines.any? %>
<div class="card home-summary-card user">
Expand Down
7 changes: 7 additions & 0 deletions config/locales/views/activities/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ en:
labels: New label
info: Information
info_description: Go to the information page of this learning activity
draft:
title: "Draft"
toggle-label: "Put activity in draft mode."
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
help: "Draft mode provides better error logging for teachers and hides the activity from students. Draft mode is activated by default for new activities."
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
index:
title: Exercises
exercise: Exercise
Expand Down Expand Up @@ -67,6 +71,7 @@ en:
mine: "My activities"
featured: "Featured activities"
all: "All activities"
draft-notice: "This activity is in draft mode. It is not visible for students."
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
show:
code: Code
handin: Hand in
Expand Down Expand Up @@ -97,6 +102,8 @@ en:
preloaded_info: "We have preloaded your latest submission into the editor."
preloaded_clear: Clear editor.
preloaded_restore: Restore the initial code.
alert_draft: This activity is in draft mode. It is not visible for students.
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
alert_draft_edit: Disable draft mode.
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
series_activities_add_table:
course_added_to_usable: "Adding this exercise will allow this course to use all of the private exercises in this exercise's repository. Are you sure?"
edit:
Expand Down
7 changes: 7 additions & 0 deletions config/locales/views/activities/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ nl:
labels: Nieuw label
info: Informatie
info_description: Ga naar de informatiepagina van deze leeractiviteit
draft:
title: "Ontwerp"
toggle-label: "Activeer de ontwerpmodus."
help: "Ontwerpmodus zorgt voor betere foutmeldingen voor leerkrachten en verbergt de activiteit voor studenten."
index:
title: Oefeningen
exercise: Oefening
Expand Down Expand Up @@ -67,6 +71,7 @@ nl:
mine: "Mijn activiteiten"
featured: "Uitgelichte activiteiten"
all: "Alle activiteiten"
draft-notice: "Deze activiteit is in ontwerpmodus. Ze is niet zichtbaar voor studenten."
show:
code: Code
handin: Indienen
Expand Down Expand Up @@ -97,6 +102,8 @@ nl:
preloaded_info: We hebben jouw laatste oplossing ingeladen in de editor.
preloaded_clear: Maak de editor leeg.
preloaded_restore: Zet de voorbeeldcode terug.
alert_draft: Deze activiteit is in ontwerpmodus. Ze is niet zichtbaar voor studenten.
alert_draft_edit: Ze de ontwerpmodus uit.
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
series_activities_add_table:
course_added_to_usable: "Deze oefening toevoegen zal deze cursus toegang geven tot alle privé oefeningen in de repository van deze oefening. Ben je zeker?"
edit:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/views/pages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ en:
submissions: Submissions
correct-exercises: Correct exercises
recent-exercises: Recent exercises
draft-exercises: Draft exercises
all-draft-exercises: All draft exercises
getting_started_card:
title: Hi there,
text: It looks like you're new here. To get started, register for a course.
Expand Down
2 changes: 2 additions & 0 deletions config/locales/views/pages/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ nl:
submissions: Ingediende oplossingen
correct-exercises: Correcte oefeningen
recent-exercises: Recente oefeningen
draft-exercises: Oefeningen in ontwerpmodus
all-draft-exercises: Alle oefeningen in ontwerpmodus
getting_started_card:
title: Hallo,
text: Welkom op Dodona! Registreer je voor een cursus om van start te gaan.
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230922115708_add_draft_to_activities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDraftToActivities < ActiveRecord::Migration[7.0]
def change
add_column :activities, :draft, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_08_10_105908) do
ActiveRecord::Schema[7.0].define(version: 2023_09_22_115708) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down Expand Up @@ -59,6 +59,7 @@
t.boolean "description_nl_present", default: false
t.boolean "description_en_present", default: false
t.integer "series_count", default: 0, null: false
t.boolean "draft", default: false
t.index ["judge_id"], name: "index_activities_on_judge_id"
t.index ["name_nl"], name: "index_activities_on_name_nl"
t.index ["path", "repository_id"], name: "index_activities_on_path_and_repository_id", unique: true
Expand Down
Loading