Description:
user_admin ok
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r748:ff7f37009e5e - - 3 files changed: 15 inserted, 7 deleted
@@ -1,45 +1,45 | |||||
|
1 | require 'digest/sha1' |
|
1 | require 'digest/sha1' |
|
2 | require 'net/pop' |
|
2 | require 'net/pop' |
|
3 | require 'net/https' |
|
3 | require 'net/https' |
|
4 | require 'net/http' |
|
4 | require 'net/http' |
|
5 | require 'json' |
|
5 | require 'json' |
|
6 |
|
6 | ||
|
7 | class User < ActiveRecord::Base |
|
7 | class User < ActiveRecord::Base |
|
8 |
|
8 | ||
|
9 | has_and_belongs_to_many :roles |
|
9 | has_and_belongs_to_many :roles |
|
10 |
|
10 | ||
|
11 | #has_and_belongs_to_many :groups |
|
11 | #has_and_belongs_to_many :groups |
|
12 | has_many :groups_users, class_name: GroupUser |
|
12 | has_many :groups_users, class_name: GroupUser |
|
13 | has_many :groups, :through => :groups_users |
|
13 | has_many :groups, :through => :groups_users |
|
14 |
|
14 | ||
|
15 |
- has_many :test_requests, -> {order(submitted_at: |
|
15 | + has_many :test_requests, -> {order(submitted_at: :desc)} |
|
16 |
|
16 | ||
|
17 |
- has_many :messages, -> { order(created_at: |
|
17 | + has_many :messages, -> { order(created_at: :desc) }, |
|
18 | :class_name => "Message", |
|
18 | :class_name => "Message", |
|
19 | :foreign_key => "sender_id" |
|
19 | :foreign_key => "sender_id" |
|
20 |
|
20 | ||
|
21 |
- has_many :replied_messages, -> { order(created_at: |
|
21 | + has_many :replied_messages, -> { order(created_at: :desc) }, |
|
22 | :class_name => "Message", |
|
22 | :class_name => "Message", |
|
23 | :foreign_key => "receiver_id" |
|
23 | :foreign_key => "receiver_id" |
|
24 |
|
24 | ||
|
25 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
25 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
26 |
|
26 | ||
|
27 | belongs_to :site |
|
27 | belongs_to :site |
|
28 | belongs_to :country |
|
28 | belongs_to :country |
|
29 |
|
29 | ||
|
30 | has_and_belongs_to_many :contests, -> { order(:name); uniq} |
|
30 | has_and_belongs_to_many :contests, -> { order(:name); uniq} |
|
31 |
|
31 | ||
|
32 | scope :activated_users, -> {where activated: true} |
|
32 | scope :activated_users, -> {where activated: true} |
|
33 |
|
33 | ||
|
34 | validates_presence_of :login |
|
34 | validates_presence_of :login |
|
35 | validates_uniqueness_of :login |
|
35 | validates_uniqueness_of :login |
|
36 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
36 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
37 | validates_length_of :login, :within => 3..30 |
|
37 | validates_length_of :login, :within => 3..30 |
|
38 |
|
38 | ||
|
39 | validates_presence_of :full_name |
|
39 | validates_presence_of :full_name |
|
40 | validates_length_of :full_name, :minimum => 1 |
|
40 | validates_length_of :full_name, :minimum => 1 |
|
41 |
|
41 | ||
|
42 | validates_presence_of :password, :if => :password_required? |
|
42 | validates_presence_of :password, :if => :password_required? |
|
43 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
43 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
44 | validates_confirmation_of :password, :if => :password_required? |
|
44 | validates_confirmation_of :password, :if => :password_required? |
|
45 |
|
45 |
@@ -20,49 +20,49 | |||||
|
20 | .form-group |
|
20 | .form-group |
|
21 | = label_tag 'user_email', 'email' |
|
21 | = label_tag 'user_email', 'email' |
|
22 | = text_field 'user', 'email', :size => 10,class: 'form-control' |
|
22 | = text_field 'user', 'email', :size => 10,class: 'form-control' |
|
23 | =submit_tag "Create", class: 'btn btn-primary' |
|
23 | =submit_tag "Create", class: 'btn btn-primary' |
|
24 |
|
24 | ||
|
25 | .panel.panel-primary |
|
25 | .panel.panel-primary |
|
26 | .panel-title.panel-heading |
|
26 | .panel-title.panel-heading |
|
27 | Import from site management |
|
27 | Import from site management |
|
28 | .panel-body |
|
28 | .panel-body |
|
29 | = form_tag({:action => 'import'}, :multipart => true,class: 'form form-inline') do |
|
29 | = form_tag({:action => 'import'}, :multipart => true,class: 'form form-inline') do |
|
30 | .form-group |
|
30 | .form-group |
|
31 | = label_tag :file, 'File:' |
|
31 | = label_tag :file, 'File:' |
|
32 | .input-group |
|
32 | .input-group |
|
33 | %span.input-group-btn |
|
33 | %span.input-group-btn |
|
34 | %span.btn.btn-default.btn-file |
|
34 | %span.btn.btn-default.btn-file |
|
35 | Browse |
|
35 | Browse |
|
36 | = file_field_tag 'file' |
|
36 | = file_field_tag 'file' |
|
37 | = text_field_tag '' , nil, {readonly: true, class: 'form-control'} |
|
37 | = text_field_tag '' , nil, {readonly: true, class: 'form-control'} |
|
38 | = submit_tag 'Submit', class: 'btn btn-default' |
|
38 | = submit_tag 'Submit', class: 'btn btn-default' |
|
39 |
|
39 | ||
|
40 |
|
40 | ||
|
41 | %p |
|
41 | %p |
|
42 | = link_to '+ New user', { :action => 'new' }, { class: 'btn btn-success '} |
|
42 | = link_to '+ New user', { :action => 'new' }, { class: 'btn btn-success '} |
|
43 | = link_to '+ New list of users', { :action => 'new_list' }, { class: 'btn btn-success '} |
|
43 | = link_to '+ New list of users', { :action => 'new_list' }, { class: 'btn btn-success '} |
|
44 |
- = link_to 'Bulk Manage', bulk_manage |
|
44 | + = link_to 'Bulk Manage', { action: :bulk_manage} , { class: 'btn btn-default btn-info'} |
|
45 | = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default '} |
|
45 | = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default '} |
|
46 | = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default '} |
|
46 | = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default '} |
|
47 | = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default '} |
|
47 | = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default '} |
|
48 | = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default '} |
|
48 | = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default '} |
|
49 |
|
49 | ||
|
50 | - if GraderConfiguration.multicontests? |
|
50 | - if GraderConfiguration.multicontests? |
|
51 | %br/ |
|
51 | %br/ |
|
52 | %b Multi-contest: |
|
52 | %b Multi-contest: |
|
53 | = link_to '[Manage bulk users in contests]', :action => 'contest_management' |
|
53 | = link_to '[Manage bulk users in contests]', :action => 'contest_management' |
|
54 | View users in: |
|
54 | View users in: |
|
55 | - @contests.each do |contest| |
|
55 | - @contests.each do |contest| |
|
56 | = link_to "[#{contest.name}]", :action => 'contests', :id => contest.id |
|
56 | = link_to "[#{contest.name}]", :action => 'contests', :id => contest.id |
|
57 | = link_to "[no contest]", :action => 'contests', :id => 'none' |
|
57 | = link_to "[no contest]", :action => 'contests', :id => 'none' |
|
58 |
|
58 | ||
|
59 | -# Total #{@user_count} users | |
|
59 | -# Total #{@user_count} users | |
|
60 | -# - if !@paginated |
|
60 | -# - if !@paginated |
|
61 | -# Display all users. |
|
61 | -# Display all users. |
|
62 | -# \#{link_to '[show in pages]', :action => 'index', :page => '1'} |
|
62 | -# \#{link_to '[show in pages]', :action => 'index', :page => '1'} |
|
63 | -# - else |
|
63 | -# - else |
|
64 | -# Display in pages. |
|
64 | -# Display in pages. |
|
65 | -# \#{link_to '[display all]', :action => 'index', :page => 'all'} | |
|
65 | -# \#{link_to '[display all]', :action => 'index', :page => 'all'} | |
|
66 | -# \#{will_paginate @users, :container => false} |
|
66 | -# \#{will_paginate @users, :container => false} |
|
67 |
|
67 | ||
|
68 |
|
68 | ||
@@ -74,33 +74,33 | |||||
|
74 | %th Remark |
|
74 | %th Remark |
|
75 | %th |
|
75 | %th |
|
76 | Activated |
|
76 | Activated |
|
77 | %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'User has already confirmed the email?' } [?] |
|
77 | %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'User has already confirmed the email?' } [?] |
|
78 | %th |
|
78 | %th |
|
79 | Enabled |
|
79 | Enabled |
|
80 | %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'Allow the user to login?' } [?] |
|
80 | %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'Allow the user to login?' } [?] |
|
81 | %th Last IP |
|
81 | %th Last IP |
|
82 | %th |
|
82 | %th |
|
83 | %th |
|
83 | %th |
|
84 | %th |
|
84 | %th |
|
85 | %th |
|
85 | %th |
|
86 | - for user in @users |
|
86 | - for user in @users |
|
87 | %tr |
|
87 | %tr |
|
88 | %td= link_to user.login, stat_user_path(user) |
|
88 | %td= link_to user.login, stat_user_path(user) |
|
89 | %td= user.full_name |
|
89 | %td= user.full_name |
|
90 | %td= user.email |
|
90 | %td= user.email |
|
91 | %td= user.remark |
|
91 | %td= user.remark |
|
92 | %td= toggle_button(user.activated?, toggle_activate_user_path(user),"toggle_activate_user_#{user.id}") |
|
92 | %td= toggle_button(user.activated?, toggle_activate_user_path(user),"toggle_activate_user_#{user.id}") |
|
93 | %td= toggle_button(user.enabled?, toggle_enable_user_path(user),"toggle_enable_user_#{user.id}") |
|
93 | %td= toggle_button(user.enabled?, toggle_enable_user_path(user),"toggle_enable_user_#{user.id}") |
|
94 | %td= user.last_ip |
|
94 | %td= user.last_ip |
|
95 | %td= link_to 'Clear IP', {:action => 'clear_last_ip', :id => user, :page=>params[:page]}, :confirm => 'This will reset last logging in ip of the user, are you sure?', class: 'btn btn-default btn-xs btn-block' |
|
95 | %td= link_to 'Clear IP', {:action => 'clear_last_ip', :id => user, :page=>params[:page]}, :confirm => 'This will reset last logging in ip of the user, are you sure?', class: 'btn btn-default btn-xs btn-block' |
|
96 | %td= link_to 'Show', {:action => 'show', :id => user}, class: 'btn btn-default btn-xs btn-block' |
|
96 | %td= link_to 'Show', {:action => 'show', :id => user}, class: 'btn btn-default btn-xs btn-block' |
|
97 | %td= link_to 'Edit', {:action => 'edit', :id => user}, class: 'btn btn-default btn-xs btn-block' |
|
97 | %td= link_to 'Edit', {:action => 'edit', :id => user}, class: 'btn btn-default btn-xs btn-block' |
|
98 |
- %td= link_to 'Destroy', |
|
98 | + %td= link_to 'Destroy', {action: :destroy, id: user}, data: {confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-danger btn-xs btn-block' |
|
99 | %br/ |
|
99 | %br/ |
|
100 | = link_to '+ New user', { :action => 'new' }, { class: 'btn btn-success '} |
|
100 | = link_to '+ New user', { :action => 'new' }, { class: 'btn btn-success '} |
|
101 | = link_to '+ New list of users', { :action => 'new_list' }, { class: 'btn btn-success '} |
|
101 | = link_to '+ New list of users', { :action => 'new_list' }, { class: 'btn btn-success '} |
|
102 |
|
102 | ||
|
103 | :javascript |
|
103 | :javascript |
|
104 | $('.datatable').DataTable({ |
|
104 | $('.datatable').DataTable({ |
|
105 | 'pageLength': 50 |
|
105 | 'pageLength': 50 |
|
106 | }); |
|
106 | }); |
@@ -70,51 +70,59 | |||||
|
70 | resources :users do |
|
70 | resources :users do |
|
71 | member do |
|
71 | member do |
|
72 | get 'toggle_activate', 'toggle_enable' |
|
72 | get 'toggle_activate', 'toggle_enable' |
|
73 | get 'stat' |
|
73 | get 'stat' |
|
74 | end |
|
74 | end |
|
75 | end |
|
75 | end |
|
76 |
|
76 | ||
|
77 | resources :submissions do |
|
77 | resources :submissions do |
|
78 | member do |
|
78 | member do |
|
79 | get 'download' |
|
79 | get 'download' |
|
80 | get 'compiler_msg' |
|
80 | get 'compiler_msg' |
|
81 | get 'rejudge' |
|
81 | get 'rejudge' |
|
82 | end |
|
82 | end |
|
83 | collection do |
|
83 | collection do |
|
84 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
84 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
85 | get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' |
|
85 | get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' |
|
86 | get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status' |
|
86 | get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status' |
|
87 | end |
|
87 | end |
|
88 | end |
|
88 | end |
|
89 |
|
89 | ||
|
90 |
|
90 | ||
|
91 | #user admin |
|
91 | #user admin |
|
92 | resources :user_admin do |
|
92 | resources :user_admin do |
|
93 | collection do |
|
93 | collection do |
|
94 |
- get 'bulk_manage' |
|
94 | + get 'bulk_manage' |
|
95 | - delete ':id', to: 'user_admin#destroy', as: 'user_admin_destroy' |
|
||
|
96 | get 'user_stat' |
|
95 | get 'user_stat' |
|
|
96 | + get 'import' | ||
|
|
97 | + get 'new_list' | ||
|
|
98 | + get 'admin' | ||
|
|
99 | + get 'random_all_passwords' | ||
|
|
100 | + get 'active' | ||
|
|
101 | + get 'mass_mailing' | ||
|
|
102 | + end | ||
|
|
103 | + member do | ||
|
|
104 | + get 'clear_last_ip' | ||
|
97 | end |
|
105 | end |
|
98 | end |
|
106 | end |
|
99 |
|
107 | ||
|
100 | resources :contest_management, only: [:index] do |
|
108 | resources :contest_management, only: [:index] do |
|
101 | collection do |
|
109 | collection do |
|
102 | get 'user_stat' |
|
110 | get 'user_stat' |
|
103 | get 'clear_stat' |
|
111 | get 'clear_stat' |
|
104 | get 'clear_all_stat' |
|
112 | get 'clear_all_stat' |
|
105 | end |
|
113 | end |
|
106 | end |
|
114 | end |
|
107 |
|
115 | ||
|
108 | #get 'user_admin', to: 'user_admin#index' |
|
116 | #get 'user_admin', to: 'user_admin#index' |
|
109 | #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin' |
|
117 | #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin' |
|
110 | #post 'user_admin', to: 'user_admin#create' |
|
118 | #post 'user_admin', to: 'user_admin#create' |
|
111 | #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy' |
|
119 | #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy' |
|
112 |
|
120 | ||
|
113 | #singular resource |
|
121 | #singular resource |
|
114 | #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly |
|
122 | #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly |
|
115 | #report |
|
123 | #report |
|
116 | resource :report, only: [], controller: 'report' do |
|
124 | resource :report, only: [], controller: 'report' do |
|
117 | get 'login' |
|
125 | get 'login' |
|
118 | get 'multiple_login' |
|
126 | get 'multiple_login' |
|
119 | get 'problem_hof/:id', action: 'problem_hof' |
|
127 | get 'problem_hof/:id', action: 'problem_hof' |
|
120 | get 'current_score' |
|
128 | get 'current_score' |
You need to be logged in to leave comments.
Login now