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 |
@@ -2,6 +2,7 | |||||
|
2 | before_action :set_group, only: [:show, :edit, :update, :destroy, |
|
2 | before_action :set_group, only: [:show, :edit, :update, :destroy, |
|
3 | :add_user, :remove_user,:remove_all_user, |
|
3 | :add_user, :remove_user,:remove_all_user, |
|
4 | :add_problem, :remove_problem,:remove_all_problem, |
|
4 | :add_problem, :remove_problem,:remove_all_problem, |
|
|
5 | + :toggle, | ||
|
5 | ] |
|
6 | ] |
|
6 | before_action :admin_authorization |
|
7 | before_action :admin_authorization |
|
7 |
|
8 | ||
@@ -49,6 +50,11 | |||||
|
49 | redirect_to groups_url, notice: 'Group was successfully destroyed.' |
|
50 | redirect_to groups_url, notice: 'Group was successfully destroyed.' |
|
50 | end |
|
51 | end |
|
51 |
|
52 | ||
|
|
53 | + def toggle | ||
|
|
54 | + @group.enabled = @group.enabled? ? false : true | ||
|
|
55 | + @group.save | ||
|
|
56 | + end | ||
|
|
57 | + | ||
|
52 | def remove_user |
|
58 | def remove_user |
|
53 | user = User.find(params[:user_id]) |
|
59 | user = User.find(params[:user_id]) |
|
54 | @group.users.delete(user) |
|
60 | @group.users.delete(user) |
@@ -99,6 +105,6 | |||||
|
99 |
|
105 | ||
|
100 | # Only allow a trusted parameter "white list" through. |
|
106 | # Only allow a trusted parameter "white list" through. |
|
101 | def group_params |
|
107 | def group_params |
|
102 | - params.require(:group).permit(:name, :description) |
|
108 | + params.require(:group).permit(:name, :description, :enabled) |
|
103 | end |
|
109 | end |
|
104 | end |
|
110 | end |
@@ -188,7 +188,7 | |||||
|
188 | @user = user |
|
188 | @user = user |
|
189 | end |
|
189 | end |
|
190 | end |
|
190 | end |
|
191 | - |
|
191 | + |
|
192 | protected |
|
192 | protected |
|
193 |
|
193 | ||
|
194 | def prepare_announcements(recent=nil) |
|
194 | def prepare_announcements(recent=nil) |
@@ -113,8 +113,9 | |||||
|
113 |
|
113 | ||
|
114 | def toggle_button(on,toggle_url,id, option={}) |
|
114 | def toggle_button(on,toggle_url,id, option={}) |
|
115 | btn_size = option[:size] || 'btn-xs' |
|
115 | btn_size = option[:size] || 'btn-xs' |
|
|
116 | + btn_block = option[:block] || 'btn-block' | ||
|
116 | link_to (on ? "Yes" : "No"), toggle_url, |
|
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 | id: id, |
|
119 | id: id, |
|
119 | data: {remote: true, method: 'get'}} |
|
120 | data: {remote: true, method: 'get'}} |
|
120 | end |
|
121 | end |
@@ -273,9 +273,10 | |||||
|
273 | end |
|
273 | end |
|
274 | end |
|
274 | end |
|
275 |
|
275 | ||
|
|
276 | + # new feature, get list of available problem in all enabled group that the user belongs to | ||
|
276 | def available_problems_in_group |
|
277 | def available_problems_in_group |
|
277 | problem = [] |
|
278 | problem = [] |
|
278 | - self.groups.each do |group| |
|
279 | + self.groups.where(enabled: true).each do |group| |
|
279 | group.problems.where(available: true).each { |p| problem << p } |
|
280 | group.problems.where(available: true).each { |p| problem << p } |
|
280 | end |
|
281 | end |
|
281 | problem.uniq! |
|
282 | problem.uniq! |
@@ -296,6 +297,8 | |||||
|
296 | end |
|
297 | end |
|
297 | end |
|
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 | def can_view_problem?(problem) |
|
302 | def can_view_problem?(problem) |
|
300 | return true if admin? |
|
303 | return true if admin? |
|
301 | return available_problems.include? problem |
|
304 | return available_problems.include? problem |
@@ -10,7 +10,7 | |||||
|
10 | %td |
|
10 | %td |
|
11 | = submission.source_filename |
|
11 | = submission.source_filename |
|
12 | = " (#{submission.language.pretty_name}) " |
|
12 | = " (#{submission.language.pretty_name}) " |
|
13 | - = link_to('[load]',{:action => 'source', :id => submission.id}) |
|
13 | + = link_to '[load]', download_submission_path(submission) |
|
14 | %td |
|
14 | %td |
|
15 | - if submission.graded_at |
|
15 | - if submission.graded_at |
|
16 | = "Graded at #{format_short_time(submission.graded_at)}." |
|
16 | = "Graded at #{format_short_time(submission.graded_at)}." |
@@ -5,12 +5,23 | |||||
|
5 | %ul |
|
5 | %ul |
|
6 | - @group.errors.full_messages.each do |msg| |
|
6 | - @group.errors.full_messages.each do |msg| |
|
7 | %li= msg |
|
7 | %li= msg |
|
8 | - |
|
8 | + .row |
|
9 | - .form-group.field |
|
9 | + .col-md-6 |
|
10 | - = f.label :name |
|
10 | + .form-group.field |
|
11 | - = f.text_field :name, class: 'form-control' |
|
11 | + = f.label :name |
|
12 | - .form-group.field |
|
12 | + = f.text_field :name, class: 'form-control' |
|
13 | - = f.label :description |
|
13 | + .row |
|
14 | - = f.text_field :description, class: 'form-control' |
|
14 | + .col-md-6 |
|
15 |
- .form-group. |
|
15 | + .form-group.field |
|
16 | - = f.submit 'Save', class: 'btn btn-primary' |
|
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' |
@@ -7,14 +7,16 | |||||
|
7 | %tr |
|
7 | %tr |
|
8 | %th Name |
|
8 | %th Name |
|
9 | %th Description |
|
9 | %th Description |
|
|
10 | + %th Enabled? | ||
|
10 | %th |
|
11 | %th |
|
11 | %th |
|
12 | %th |
|
12 |
|
13 | ||
|
13 | %tbody |
|
14 | %tbody |
|
14 | - @groups.each do |group| |
|
15 | - @groups.each do |group| |
|
15 | - %tr |
|
16 | + %tr{:class => "#{(group.enabled?) ? "success" : "danger"}", id: "group-#{group.id}"} |
|
16 | %td= group.name |
|
17 | %td= group.name |
|
17 | %td= group.description |
|
18 | %td= group.description |
|
|
19 | + %td= toggle_button(group.enabled?, toggle_group_path(group), "group-enabled-#{group.id}", size: ' ', block: ' ') | ||
|
18 | %td= link_to 'View', group, class: 'btn btn-default' |
|
20 | %td= link_to 'View', group, class: 'btn btn-default' |
|
19 | %td= link_to 'Destroy', group, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger' |
|
21 | %td= link_to 'Destroy', group, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger' |
|
20 |
|
22 |
@@ -54,6 +54,7 | |||||
|
54 | post 'add_problem', to: 'groups#add_problem', as: 'add_problem' |
|
54 | post 'add_problem', to: 'groups#add_problem', as: 'add_problem' |
|
55 | delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem' |
|
55 | delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem' |
|
56 | delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem' |
|
56 | delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem' |
|
|
57 | + get 'toggle' | ||
|
57 | end |
|
58 | end |
|
58 | collection do |
|
59 | collection do |
|
59 |
|
60 | ||
@@ -92,7 +93,6 | |||||
|
92 | get 'download' |
|
93 | get 'download' |
|
93 | get 'compiler_msg' |
|
94 | get 'compiler_msg' |
|
94 | get 'rejudge' |
|
95 | get 'rejudge' |
|
95 | - get 'source' |
|
||
|
96 | end |
|
96 | end |
|
97 | collection do |
|
97 | collection do |
|
98 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
98 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
@@ -10,7 +10,7 | |||||
|
10 | # |
|
10 | # |
|
11 | # It's strongly recommended that you check this file into your version control system. |
|
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 | create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
15 | create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
16 | t.string "author" |
|
16 | t.string "author" |
@@ -80,6 +80,7 | |||||
|
80 | create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
80 | create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
81 | t.string "name" |
|
81 | t.string "name" |
|
82 | t.string "description" |
|
82 | t.string "description" |
|
|
83 | + t.boolean "enabled", default: true | ||
|
83 | end |
|
84 | end |
|
84 |
|
85 | ||
|
85 | create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
86 | create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
You need to be logged in to leave comments.
Login now