Description:
group enable
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r795:08d968fa05d5 - - 11 files changed: 54 inserted, 17 deleted
@@ -0,0 +1,8 | |||
|
1 | + = render partial: 'toggle_button', | |
|
2 | + locals: {button_id: "#group-enabled-#{@group.id}",button_on: @group.enabled } | |
|
3 | + :plain | |
|
4 | + r = $("#group-#{@group.id}"); | |
|
5 | + r.removeClass('success'); | |
|
6 | + r.removeClass('danger'); | |
|
7 | + r.addClass("#{@group.enabled? ? 'success' : 'danger'}"); | |
|
8 | + |
@@ -0,0 +1,5 | |||
|
1 | + class AddEnabledToGroup < ActiveRecord::Migration[5.2] | |
|
2 | + def change | |
|
3 | + add_column :groups, :enabled, :boolean, default: true | |
|
4 | + end | |
|
5 | + end |
@@ -1,10 +1,11 | |||
|
1 | 1 | class GroupsController < ApplicationController |
|
2 | 2 | before_action :set_group, only: [:show, :edit, :update, :destroy, |
|
3 | 3 | :add_user, :remove_user,:remove_all_user, |
|
4 | 4 | :add_problem, :remove_problem,:remove_all_problem, |
|
5 | + :toggle, | |
|
5 | 6 | ] |
|
6 | 7 | before_action :admin_authorization |
|
7 | 8 | |
|
8 | 9 | # GET /groups |
|
9 | 10 | def index |
|
10 | 11 | @groups = Group.all |
@@ -46,12 +47,17 | |||
|
46 | 47 | # DELETE /groups/1 |
|
47 | 48 | def destroy |
|
48 | 49 | @group.destroy |
|
49 | 50 | redirect_to groups_url, notice: 'Group was successfully destroyed.' |
|
50 | 51 | end |
|
51 | 52 | |
|
53 | + def toggle | |
|
54 | + @group.enabled = @group.enabled? ? false : true | |
|
55 | + @group.save | |
|
56 | + end | |
|
57 | + | |
|
52 | 58 | def remove_user |
|
53 | 59 | user = User.find(params[:user_id]) |
|
54 | 60 | @group.users.delete(user) |
|
55 | 61 | redirect_to group_path(@group), flash: {success: "User #{user.login} was removed from the group #{@group.name}"} |
|
56 | 62 | end |
|
57 | 63 | |
@@ -96,9 +102,9 | |||
|
96 | 102 | def set_group |
|
97 | 103 | @group = Group.find(params[:id]) |
|
98 | 104 | end |
|
99 | 105 | |
|
100 | 106 | # Only allow a trusted parameter "white list" through. |
|
101 | 107 | def group_params |
|
102 | - params.require(:group).permit(:name, :description) | |
|
108 | + params.require(:group).permit(:name, :description, :enabled) | |
|
103 | 109 | end |
|
104 | 110 | end |
@@ -185,13 +185,13 | |||
|
185 | 185 | redirect_to :action => 'list' |
|
186 | 186 | else |
|
187 | 187 | @contests = user.contests |
|
188 | 188 | @user = user |
|
189 | 189 | end |
|
190 | 190 | end |
|
191 | - | |
|
191 | + | |
|
192 | 192 | protected |
|
193 | 193 | |
|
194 | 194 | def prepare_announcements(recent=nil) |
|
195 | 195 | if GraderConfiguration.show_tasks_to?(@user) |
|
196 | 196 | @announcements = Announcement.published(true) |
|
197 | 197 | else |
@@ -110,14 +110,15 | |||
|
110 | 110 | nil |
|
111 | 111 | end |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def toggle_button(on,toggle_url,id, option={}) |
|
115 | 115 | btn_size = option[:size] || 'btn-xs' |
|
116 | + btn_block = option[:block] || 'btn-block' | |
|
116 | 117 | link_to (on ? "Yes" : "No"), toggle_url, |
|
117 |
- {class: "btn |
|
|
118 | + {class: "btn #{btn_block} #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle", | |
|
118 | 119 | id: id, |
|
119 | 120 | data: {remote: true, method: 'get'}} |
|
120 | 121 | end |
|
121 | 122 | |
|
122 | 123 | def get_ace_mode(language) |
|
123 | 124 | # return ace mode string from Language |
@@ -270,15 +270,16 | |||
|
270 | 270 | end |
|
271 | 271 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
272 | 272 | return contest_problems + other_avaiable_problems |
|
273 | 273 | end |
|
274 | 274 | end |
|
275 | 275 | |
|
276 | + # new feature, get list of available problem in all enabled group that the user belongs to | |
|
276 | 277 | def available_problems_in_group |
|
277 | 278 | problem = [] |
|
278 | - self.groups.each do |group| | |
|
279 | + self.groups.where(enabled: true).each do |group| | |
|
279 | 280 | group.problems.where(available: true).each { |p| problem << p } |
|
280 | 281 | end |
|
281 | 282 | problem.uniq! |
|
282 | 283 | if problem |
|
283 | 284 | problem.sort! do |a,b| |
|
284 | 285 | case |
@@ -293,12 +294,14 | |||
|
293 | 294 | return problem |
|
294 | 295 | else |
|
295 | 296 | return [] |
|
296 | 297 | end |
|
297 | 298 | end |
|
298 | 299 | |
|
300 | + #check if the user has the right to view that problem | |
|
301 | + #this also consider group based problem policy | |
|
299 | 302 | def can_view_problem?(problem) |
|
300 | 303 | return true if admin? |
|
301 | 304 | return available_problems.include? problem |
|
302 | 305 | end |
|
303 | 306 | |
|
304 | 307 | def self.clear_last_login |
@@ -7,13 +7,13 | |||
|
7 | 7 | %td |
|
8 | 8 | = l submission.submitted_at, format: :long |
|
9 | 9 | = "( #{time_ago_in_words(submission.submitted_at)} ago)" |
|
10 | 10 | %td |
|
11 | 11 | = submission.source_filename |
|
12 | 12 | = " (#{submission.language.pretty_name}) " |
|
13 | - = link_to('[load]',{:action => 'source', :id => submission.id}) | |
|
13 | + = link_to '[load]', download_submission_path(submission) | |
|
14 | 14 | %td |
|
15 | 15 | - if submission.graded_at |
|
16 | 16 | = "Graded at #{format_short_time(submission.graded_at)}." |
|
17 | 17 | %br/ |
|
18 | 18 | = "Score: #{(submission.points*100/submission.problem.full_score).to_i} " if GraderConfiguration['ui.show_score'] |
|
19 | 19 | = " [" |
@@ -2,15 +2,26 | |||
|
2 | 2 | - if @group.errors.any? |
|
3 | 3 | #error_explanation |
|
4 | 4 | %h2= "#{pluralize(@group.errors.count, "error")} prohibited this group from being saved:" |
|
5 | 5 | %ul |
|
6 | 6 | - @group.errors.full_messages.each do |msg| |
|
7 | 7 | %li= msg |
|
8 | - | |
|
9 | - .form-group.field | |
|
10 | - = f.label :name | |
|
11 | - = f.text_field :name, class: 'form-control' | |
|
12 | - .form-group.field | |
|
13 | - = f.label :description | |
|
14 | - = f.text_field :description, class: 'form-control' | |
|
15 |
- .form-group. |
|
|
16 | - = f.submit 'Save', class: 'btn btn-primary' | |
|
8 | + .row | |
|
9 | + .col-md-6 | |
|
10 | + .form-group.field | |
|
11 | + = f.label :name | |
|
12 | + = f.text_field :name, class: 'form-control' | |
|
13 | + .row | |
|
14 | + .col-md-6 | |
|
15 | + .form-group.field | |
|
16 | + = f.label :description | |
|
17 | + = f.text_field :description, class: 'form-control' | |
|
18 | + .row | |
|
19 | + .col-md-6 | |
|
20 | + .checkbox | |
|
21 | + = f.label :enabled do | |
|
22 | + = f.check_box :enabled | |
|
23 | + Enabled | |
|
24 | + .row | |
|
25 | + .col-md-6 | |
|
26 | + .form-group.actions | |
|
27 | + = f.submit 'Save', class: 'btn btn-primary' |
@@ -4,19 +4,21 | |||
|
4 | 4 | = link_to 'New Group', new_group_path, class: 'btn btn-primary' |
|
5 | 5 | %table.table.table-hover |
|
6 | 6 | %thead |
|
7 | 7 | %tr |
|
8 | 8 | %th Name |
|
9 | 9 | %th Description |
|
10 | + %th Enabled? | |
|
10 | 11 | %th |
|
11 | 12 | %th |
|
12 | 13 | |
|
13 | 14 | %tbody |
|
14 | 15 | - @groups.each do |group| |
|
15 | - %tr | |
|
16 | + %tr{:class => "#{(group.enabled?) ? "success" : "danger"}", id: "group-#{group.id}"} | |
|
16 | 17 | %td= group.name |
|
17 | 18 | %td= group.description |
|
19 | + %td= toggle_button(group.enabled?, toggle_group_path(group), "group-enabled-#{group.id}", size: ' ', block: ' ') | |
|
18 | 20 | %td= link_to 'View', group, class: 'btn btn-default' |
|
19 | 21 | %td= link_to 'Destroy', group, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger' |
|
20 | 22 | |
|
21 | 23 | %br |
|
22 | 24 |
@@ -51,12 +51,13 | |||
|
51 | 51 | post 'add_user', to: 'groups#add_user', as: 'add_user' |
|
52 | 52 | delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user' |
|
53 | 53 | delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user' |
|
54 | 54 | post 'add_problem', to: 'groups#add_problem', as: 'add_problem' |
|
55 | 55 | delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem' |
|
56 | 56 | delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem' |
|
57 | + get 'toggle' | |
|
57 | 58 | end |
|
58 | 59 | collection do |
|
59 | 60 | |
|
60 | 61 | end |
|
61 | 62 | end |
|
62 | 63 | |
@@ -89,13 +90,12 | |||
|
89 | 90 | |
|
90 | 91 | resources :submissions do |
|
91 | 92 | member do |
|
92 | 93 | get 'download' |
|
93 | 94 | get 'compiler_msg' |
|
94 | 95 | get 'rejudge' |
|
95 | - get 'source' | |
|
96 | 96 | end |
|
97 | 97 | collection do |
|
98 | 98 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
99 | 99 | get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' |
|
100 | 100 | get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status' |
|
101 | 101 | end |
@@ -7,13 +7,13 | |||
|
7 | 7 | # system, you should be using db:schema:load, not running all the migrations |
|
8 | 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
9 | 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
10 | 10 | # |
|
11 | 11 | # It's strongly recommended that you check this file into your version control system. |
|
12 | 12 | |
|
13 |
- ActiveRecord::Schema.define(version: 20 |
|
|
13 | + ActiveRecord::Schema.define(version: 2020_08_13_083020) do | |
|
14 | 14 | |
|
15 | 15 | create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
16 | 16 | t.string "author" |
|
17 | 17 | t.text "body" |
|
18 | 18 | t.boolean "published" |
|
19 | 19 | t.datetime "created_at" |
@@ -77,12 +77,13 | |||
|
77 | 77 | t.index ["host", "pid"], name: "index_grader_processes_on_host_and_pid" |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
81 | 81 | t.string "name" |
|
82 | 82 | t.string "description" |
|
83 | + t.boolean "enabled", default: true | |
|
83 | 84 | end |
|
84 | 85 | |
|
85 | 86 | create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
86 | 87 | t.integer "problem_id", null: false |
|
87 | 88 | t.integer "group_id", null: false |
|
88 | 89 | t.index ["group_id", "problem_id"], name: "index_groups_problems_on_group_id_and_problem_id" |
You need to be logged in to leave comments.
Login now