Skip to content

Commit

Permalink
Use collections in routes and avoid matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas16 committed Oct 27, 2024
1 parent 1c2b4ff commit 5155a47
Show file tree
Hide file tree
Showing 42 changed files with 178 additions and 177 deletions.
2 changes: 1 addition & 1 deletion app/controllers/chapters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def all
end

# Show statistics of all chapters
def chapterstats
def stats
end

# Create a chapter (show the form)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/privacypolicies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def index
end

# Show the last privacy policy
def last_policy
def last
@last_policy = Privacypolicy.where(:online => true).order(:publication_time).last
if @last_policy.nil?
flash[:danger] = "Le site n'a actuellement aucune politique de confidentalité."
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ class ProblemsController < ApplicationController
before_action :admin_user, only: [:new, :create, :edit, :update, :destroy, :order, :put_online, :edit_explanation, :update_explanation, :edit_markscheme, :update_markscheme, :add_prerequisite, :delete_prerequisite, :add_virtualtest, :manage_externalsolutions]

before_action :get_problem, only: [:show, :edit, :update, :destroy, :edit_explanation, :update_explanation, :edit_markscheme, :update_markscheme, :order, :add_prerequisite, :delete_prerequisite, :add_virtualtest, :put_online, :manage_externalsolutions]
before_action :get_section, only: [:new, :create]
before_action :get_section, only: [:index, :new, :create]

before_action :offline_problem, only: [:destroy, :put_online, :add_prerequisite, :delete_prerequisite, :add_virtualtest]
before_action :user_that_can_see_problem, only: [:show]
before_action :can_be_online, only: [:put_online]

# Show problems of a section
def index
flash.now[:info] = @no_new_submission_message if @no_new_submission
end

# Show one problem
def show
flash.now[:info] = @no_new_submission_message if @no_new_submission and params.has_key?("sub") and params[:sub] == "0"
Expand Down Expand Up @@ -92,7 +97,7 @@ def update
def destroy
@problem.destroy
flash[:success] = "Problème supprimé."
redirect_to pb_sections_path(@problem.section)
redirect_to section_problems_path(@problem.section)
end

# Put a problem online
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ class SectionsController < ApplicationController
def show
end

# Show the problems of a section
def show_problems
flash.now[:info] = @no_new_submission_message if @no_new_submission
end

# Update a section (show the form)
def edit
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ def destroy
sign_out
redirect_to root_path
end

end
12 changes: 6 additions & 6 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
class SubmissionsController < ApplicationController
skip_before_action :error_if_invalid_csrf_token, only: [:create, :create_intest, :update_draft, :update_intest] # Do not forget to check @invalid_csrf_token instead!

before_action :signed_in_user, only: [:allsub, :allmysub, :allnewsub, :allmynewsub]
before_action :signed_in_user, only: [:all, :allmy, :allnew, :allmynew]
before_action :signed_in_user_danger, only: [:create, :create_intest, :update_draft, :update_intest, :read, :unread, :star, :unstar, :reserve, :unreserve, :destroy, :update_score, :uncorrect, :search_script]
before_action :non_admin_user, only: [:create, :create_intest, :update_draft, :update_intest]
before_action :root_user, only: [:update_score, :star, :unstar]
before_action :corrector_user, only: [:allsub, :allmysub, :allnewsub, :allmynewsub]
before_action :corrector_user, only: [:all, :allmy, :allnew, :allmynew]

before_action :get_submission, only: [:destroy, :read, :unread, :reserve, :unreserve, :star, :unstar, :update_draft, :update_intest, :update_score, :uncorrect, :search_script]
before_action :get_problem, only: [:create, :create_intest, :index]
Expand Down Expand Up @@ -250,17 +250,17 @@ def search_script
end

# Show all submissions
def allsub
def all
@submissions = Submission.joins(:problem).joins(problem: :section).select(needed_columns_for_submissions).includes(:user, followings: :user).where(:visible => true).order("submissions.last_comment_time DESC").paginate(page: params[:page]).to_a
end

# Show all submissions in which we took part
def allmysub
def allmy
@submissions = current_user.sk.followed_submissions.joins(:problem).joins(problem: :section).select(needed_columns_for_submissions).includes(:user).where("status != ? AND status != ?", Submission.statuses[:draft], Submission.statuses[:waiting]).order("submissions.last_comment_time DESC").paginate(page: params[:page]).to_a
end

# Show all new submissions
def allnewsub
def allnew
levels = [1, 2, 3, 4, 5]
if (params.has_key?:levels)
levels = []
Expand All @@ -276,7 +276,7 @@ def allnewsub
end

# Show all new comments to submissions in which we took part
def allmynewsub
def allmynew
@submissions = current_user.sk.followed_submissions.joins(:problem).joins(problem: :section).select(needed_columns_for_submissions).includes(:user).where(followings: {read: false}).order("submissions.last_comment_time").to_a
@submissions_other = Submission.joins(:problem).joins(problem: :section).select(needed_columns_for_submissions).includes(:user, followings: :user).where(:status => :wrong_to_read).order("submissions.last_comment_time").to_a
end
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#encoding: utf-8
class UsersController < ApplicationController
before_action :signed_in_user, only: [:edit, :notifs, :groups, :read_legal, :followed_users, :unset_follow_message]
before_action :signed_in_user, only: [:edit, :notifs, :groups, :read_legal, :followed, :unset_follow_message]
before_action :signed_in_user_danger, only: [:destroy, :destroydata, :update, :set_administrator, :take_skin, :leave_skin, :set_wepion, :unset_wepion, :set_corrector, :unset_corrector, :change_group, :follow, :unfollow, :set_follow_message, :set_can_change_name, :unset_can_change_name, :ban_temporarily]
before_action :admin_user, only: [:set_wepion, :unset_wepion, :change_group]
before_action :root_user, only: [:take_skin, :set_administrator, :destroy, :destroydata, :set_corrector, :unset_corrector, :validate_names, :validate_name, :change_name, :set_can_change_name, :unset_can_change_name, :ban_temporarily]
Expand Down Expand Up @@ -81,7 +81,7 @@ def index
end

# Show all followed users
def followed_users
def followed
fill_sections_max_score

@all_users = current_user.sk.followed_users.where(:admin => false).to_a
Expand All @@ -93,7 +93,8 @@ def followed_users
fill_user_info(@all_users)
end

def search_user
# Search for users by name
def search
return unless params.has_key?:search

search = params[:search].dup # real copy
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/views/discussions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var UserNotFound = function () {
<%= link_to "Destinataire introuvable ?", "javascript:UserNotFound()" %>
</div>

<div class="mb-2 text-color-orange" id="user-not-found-note" style="display:none;">Seuls les utilisateurs actifs récemment sont listés ci-dessus. Pour envoyer un message à un autre utilisateur, <%= link_to "cherchez-le", search_user_path %>, consultez son profil et cliquez sur "Envoyer un message".</div>
<div class="mb-2 text-color-orange" id="user-not-found-note" style="display:none;">Seuls les utilisateurs actifs récemment sont listés ci-dessus. Pour envoyer un message à un autre utilisateur, <%= link_to "cherchez-le", search_users_path %>, consultez son profil et cliquez sur "Envoyer un message".</div>

<script>initializeSelect2WhenPossible("Choisir un destinataire")</script>

Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function setLightTheme() {
</td>
<td style="text-align:right;">
<ul class="nav justify-content-end">
<li class="nav-item"><%= link_to "Confidentialité", last_policy_path %></li>
<li class="nav-item"><%= link_to "Confidentialité", last_privacypolicies_path %></li>
<li class="nav-item"><%= link_to "À propos", about_path %></li>
<li class="nav-item"><%= link_to "Contact", contact_path %></li>
</ul>
Expand Down
22 changes: 11 additions & 11 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@
<% num_notifications_new345 = current_user.sk.num_notifications_new([3, 4, 5]) %>
<% num_notifications_update = current_user.sk.num_notifications_update %>
<% classe = (num_notifications_new12[0] + num_notifications_new12[1] > 0 ? "success" : "ld-light-dark-er") %>
<%= link_to allnewsub_path(:levels => 3), class: "btn btn-#{classe}" do %>
<%= link_to allnew_submissions_path(:levels => 3), class: "btn btn-#{classe}" do %>
<%= num_notifications_new12[0] %>
<% if num_notifications_new12[1] > 0 %>
<sup>+ <%= num_notifications_new12[1] %> j</sup>
<% end %>
<% end %>
<% classe = (num_notifications_new345[0] + num_notifications_new345[1] > 0 ? "danger" : "ld-light-dark-er") %>
<%= link_to allnewsub_path(:levels => 28), class: "btn btn-#{classe}" do %>
<%= link_to allnew_submissions_path(:levels => 28), class: "btn btn-#{classe}" do %>
<%= num_notifications_new345[0] %>
<% if num_notifications_new345[1] > 0 %>
<sup>+ <%= num_notifications_new345[1] %> j</sup>
<% end %>
<% end %>
<% classe = (num_notifications_update > 0 ? "warning" : "ld-light-dark-er") %>
<%= link_to "#{num_notifications_update}", allmynewsub_path, class: "btn btn-#{classe}" %>
<%= link_to "#{num_notifications_update}", allmynew_submissions_path, class: "btn btn-#{classe}" %>

<!-- Nouvelles propositions d'étoiles (pour les root) -->
<% if current_user.sk.root? && num_waiting_starproposals > 0 %>
Expand Down Expand Up @@ -100,9 +100,9 @@
Problèmes
</a>
<ul class="dropdown-menu">
<% sections.each do |f| %>
<% if !f.fondation %>
<li><%= link_to f.name, pb_sections_path(f), :class => "dropdown-item" %></li>
<% sections.each do |s| %>
<% if !s.fondation %>
<li><%= link_to s.name, section_problems_path(s), :class => "dropdown-item" %></li>
<% end %>
<% end %>
<li class="dropdown-divider"></li>
Expand Down Expand Up @@ -133,8 +133,8 @@
<ul class="dropdown-menu">
<li><%= link_to "Scores", users_path, :class => "dropdown-item" %></li>
<li><%= link_to "Résolutions récentes", solvedproblems_path, :class => "dropdown-item" %></li>
<li><%= link_to "Corrections", correctors_path, :class => "dropdown-item" %></li>
<li><%= link_to "Difficulté des chapitres", chapterstats_path, :class => "dropdown-item" %></li>
<li><%= link_to "Corrections", correctors_users_path, :class => "dropdown-item" %></li>
<li><%= link_to "Difficulté des chapitres", stats_chapters_path, :class => "dropdown-item" %></li>
<li><%= link_to "Statistiques diverses", stats_path, :class => "dropdown-item" %></li>
</ul>
</li>
Expand All @@ -161,18 +161,18 @@
<li><%= link_to "Profil", current_user.sk, :class => "dropdown-item" %></li>
<li><%= link_to "Compte", edit_user_path(current_user.sk), :class => "dropdown-item" %></li>
<% if signed_in? && (current_user.sk.admin? || (current_user.sk.wepion? && current_user.sk.group != "")) %>
<li><%= link_to "Groupes Wépion", groups_path, :class => "dropdown-item" %></li>
<li><%= link_to "Groupes Wépion", groups_users_path, :class => "dropdown-item" %></li>
<% end %>
<li><%= link_to "Messages#{' (' + nonlu.to_s + ')' if nonlu > 0 }", new_discussion_path, :class => "dropdown-item" %></li>
<% if current_user.sk.root? %>
<li class="dropdown-divider"></li>
<li><%= link_to "Pièces jointes", myfiles_path, :class => "dropdown-item" %></li>
<% num_users_to_validate = User.where(:valid_name => false, :email_confirm => true, :admin => false).count %>
<li><%= link_to "Valider #{num_users_to_validate} noms", validate_names_path, :class => "dropdown-item" %></li>
<li><%= link_to "Valider #{num_users_to_validate} noms", validate_names_users_path, :class => "dropdown-item" %></li>
<% end %>
<li class="dropdown-divider"></li>
<li>
<%= link_to "Déconnexion", signout_path, method: "delete", :class => "dropdown-item" %>
<%= link_to "Déconnexion", sessions_path, method: "delete", :class => "dropdown-item" %>
</li>
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/privacypolicies/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% provide(:title, 'Politique de confidentialité') %>

<h1><%= title_2((link_to "Politique de confidentialité", last_policy_path), "Mettre à jour") %></h1>
<h1><%= title_2((link_to "Politique de confidentialité", last_privacypolicies_path), "Mettre à jour") %></h1>

<table class="table table-bordered">
<tr class="table-ld-header"><th class="text-center" style="width:150px;">Publication</th><th class="text-center" style="width:80px;">Texte</th><th>Modifications</th></tr>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/views/problems/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% provide(:title, 'Modifier un problème') %>

<h1><%= title_4("Problèmes", (link_to @problem.section.name, pb_sections_path(@problem.section)), (link_to "Problème ##{ @problem.number }", @problem), "Modifier") %></h1>
<h1><%= title_4("Problèmes", (link_to @problem.section.name, section_problems_path(@problem.section)), (link_to "Problème ##{ @problem.number }", @problem), "Modifier") %></h1>

<%= form_for(@problem) do |f| %>
<%= render 'form', f: f, problem: @problem %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/problems/edit_explanation.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% provide(:title, "Modifier la solution d'un problème".html_safe) %>

<h1><%= title_4("Problèmes", (link_to @problem.section.name, pb_sections_path(@problem.section)), (link_to "Problème ##{ @problem.number }", @problem), "Modifier la solution") %></h1>
<h1><%= title_4("Problèmes", (link_to @problem.section.name, section_problems_path(@problem.section)), (link_to "Problème ##{ @problem.number }", @problem), "Modifier la solution") %></h1>

<!-- Enoncé -->
<h3>Énoncé</h3>
Expand Down
2 changes: 1 addition & 1 deletion app/views/problems/edit_markscheme.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% provide(:title, "Modifier le marking scheme d'un problème") %>

<h1><%= title_4("Problèmes", (link_to @problem.section.name, pb_sections_path(@problem.section)), (link_to "Problème ##{ @problem.number }", @problem), "Modifier le marking scheme") %></h1>
<h1><%= title_4("Problèmes", (link_to @problem.section.name, section_problems_path(@problem.section)), (link_to "Problème ##{ @problem.number }", @problem), "Modifier le marking scheme") %></h1>

<!-- Enoncé -->
<h3>Énoncé</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<button class="information-tag" onclick="return Info.toggle();">?</button>
</h1>

<%= render 'info_problems' %>
<%= render 'info' %>
<% if !has_enough_points(signed_in? ? current_user.sk : nil) %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/problems/manage_externalsolutions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% provide(:title, 'Solutions externes') %>

<h1><%= title_4("Problèmes", (link_to @problem.section.name, pb_sections_path(@problem.section)), (link_to "Problème ##{ @problem.number }", @problem), "Solutions externes") %></h1>
<h1><%= title_4("Problèmes", (link_to @problem.section.name, section_problems_path(@problem.section)), (link_to "Problème ##{ @problem.number }", @problem), "Solutions externes") %></h1>

<!-- Enoncé -->
<h3>Énoncé</h3>
Expand Down
2 changes: 1 addition & 1 deletion app/views/problems/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% provide(:title, 'Créer un problème') %>

<h1><%= title_3("Problèmes", (link_to @section.name, pb_sections_path(@section)), "Créer un problème") %></h1>
<h1><%= title_3("Problèmes", (link_to @section.name, section_problems_path(@section)), "Créer un problème") %></h1>

<%= form_for(@problem, url: section_problems_path) do |f| %>
<%= render 'form', f: f, problem: nil %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/problems/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<% problem_solved = current_user.sk.pb_solved?(@problem) %>

<h1><%= title_3("Problèmes", (link_to @problem.section.name, pb_sections_path(@problem.section)), "Problème ##{ @problem.number }#{ (' - Test #' + @problem.virtualtest.number.to_s ) if @problem.virtualtest_id != 0 } #{ '(en construction)' if !@problem.online } <span class='ms-3 text-color-grey'>(#{ pt }&nbsp;points)</span>") %></h1>
<h1><%= title_3("Problèmes", (link_to @problem.section.name, section_problems_path(@problem.section)), "Problème ##{ @problem.number }#{ (' - Test #' + @problem.virtualtest.number.to_s ) if @problem.virtualtest_id != 0 } #{ '(en construction)' if !@problem.online } <span class='ms-3 text-color-grey'>(#{ pt }&nbsp;points)</span>") %></h1>

<!-- Si administrateur -->
<% if current_user.sk.admin? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/submissions/_new_in_test.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_for @submission, url: problem_create_intest_path(@problem), :html => { :multipart => true } do |f| %>
<%= form_for @submission, url: create_intest_problem_submissions_path(@problem), :html => { :multipart => true } do |f| %>
<%= render 'submissions/form', f: f %>
<%= render 'shared/edit_files' %>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% provide(:title, "Commentaires") %>

<h1><%= title_1("Commentaires") %> <span style="font-size:20px;"> - <%= link_to "Tout voir", allmysub_path %></span></h1>
<h1><%= title_1("Commentaires") %> <span style="font-size:20px;"> - <%= link_to "Tout voir", allmy_submissions_path %></span></h1>

<h3>Qui vous concernent</h3>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h1>
<%= title_1("Soumissions") %>
<span style="font-size:20px;"> - <%= link_to "Tout voir", allsub_path %>
<span style="font-size:20px;"> - <%= link_to "Tout voir", all_submissions_path %>
<% if current_user.sk.root? || current_user.sk.suspicions.count > 0 %>
- <%= link_to "Plagiats", suspicions_path %>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@
<div class="form-check">
<label class="form-check-label">
<%= check_box_tag "consent1", "1", false, :class => "form-check-input", :onchange => "javascript:checkChecked();" %>
J'ai lu et j'accepte la <%= link_to "politique de confidentialité", last_policy_path, :target => "_blank" %> de Mathraining.
J'ai lu et j'accepte la <%= link_to "politique de confidentialité", last_privacypolicies_path, :target => "_blank" %> de Mathraining.
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<%= check_box_tag "consent2", "2", false, :class => "form-check-input", :onchange => "javascript:checkChecked();" %>
J'ai au moins 16 ans, ou j'ai lu et accepté la <%= link_to "politique de confidentialité", last_policy_path, :target => "_blank" %> avec mon tuteur légal.
J'ai au moins 16 ans, ou j'ai lu et accepté la <%= link_to "politique de confidentialité", last_privacypolicies_path, :target => "_blank" %> avec mon tuteur légal.
</label>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<% if signed_in? %>
<li class="nav-item"><%= link_to "Utilisateurs suivis", followed_users_path, :class => "nav-link #{ 'active' if t == 2 }" %></li>
<% end %>
<li class="nav-item"><%= link_to "Chercher un utilisateur", search_user_path, :class => "nav-link #{ 'active' if t == 3 }" %></li>
<li class="nav-item"><%= link_to "Chercher un utilisateur", search_users_path, :class => "nav-link #{ 'active' if t == 3 }" %></li>
</ul>
File renamed without changes.
4 changes: 2 additions & 2 deletions app/views/users/groups.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<% if current_user.sk.admin? %>
<p class="text-center">
<% if (!params.has_key?:details) %>
<%= link_to "Afficher les détails", groups_path(:details => 1) %>
<%= link_to "Afficher les détails", groups_users_path(:details => 1) %>
<% else %>
<%= link_to "Masquer les détails", groups_path %>
<%= link_to "Masquer les détails", groups_users_path %>
<% end %>
</p>
<% end %>
Expand Down
Loading

0 comments on commit 5155a47

Please sign in to comment.