Skip to content

Commit 0db5d1a

Browse files
authored
Merge pull request linuxfrorg#293 from Trim/maintainer
Create a maintainer role to manage trackers
2 parents fec5af4 + 9c10ad3 commit 0db5d1a

File tree

13 files changed

+68
-8
lines changed

13 files changed

+68
-8
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# encoding: utf-8
2+
class Admin::MaintainersController < AdminController
3+
before_action :load_account
4+
5+
def create
6+
@account.give_maintainer_rights!
7+
Board.amr_notification("Le compte #{@account.login} #{user_url @account.login} a reçu le rôle mainteneur par #{current_user.name} #{user_url(current_user)}")
8+
redirect_to @account.user, notice: "Nouveau rôle : mainteneur"
9+
end
10+
11+
def destroy
12+
@account.remove_all_rights!
13+
Board.amr_notification("Le compte #{@account.login} #{user_url @account.login} a perdu le rôle mainteneur par #{current_user.name} #{user_url(current_user)}")
14+
redirect_to @account.user, notice: "Rôle retiré : mainteneur"
15+
end
16+
17+
protected
18+
19+
def load_account
20+
@account = Account.find(params[:account_id])
21+
end
22+
23+
end

app/controllers/trackers_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def destroy
8888
protected
8989

9090
def tracker_params
91-
if current_account.try(:admin?)
91+
if current_account.try(:tracker_admin?)
9292
params.require(:tracker).permit!
9393
else
9494
params.require(:tracker).permit(:title, :wiki_body, :category_id, :state)

app/helpers/static_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def helper_moderator_list
2626
people_list Account.moderator
2727
end
2828

29+
def helper_maintainer_list
30+
people_list Account.maintainer
31+
end
32+
2933
def helper_friend_sites_list
3034
sites = FriendSite.all.map { |s| content_tag(:li, link_to(s.title, s.url)) }
3135
content_tag(:ul, safe_join(sites), class: "people-list")

app/models/account.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# There are several levels of users:
4040
# * anonymous -> they have no account and can only read public contents
4141
# * authenticated -> they can read public contents and submit new ones
42+
# * maintainer -> they can manage the tracker system
4243
# * moderator -> they make the order and the security ruling
4344
# * editor -> they edit the news in the redaction space
4445
# * admin -> the almighty users
@@ -127,6 +128,8 @@ def update_with_password(params={}, *options)
127128
### Role ###
128129

129130
scope :active, -> { where("role != 'inactive'") }
131+
scope :maintainer, -> { where(role: "maintainer") }
132+
scope :tracker_admin, -> { where(role: %w[admin maintainer]) }
130133
scope :moderator, -> { where(role: "moderator") }
131134
scope :editor, -> { where(role: "editor") }
132135
scope :admin, -> { where(role: "admin") }
@@ -136,6 +139,7 @@ def update_with_password(params={}, *options)
136139
event :inactivate do transition all => :inactive end
137140
event :reactivate do transition :inactive => :visitor end
138141
event :remove_all_rights do transition all - :inactive => :visitor end
142+
event :give_maintainer_rights do transition all - :inactive => :maintainer end
139143
event :give_moderator_rights do transition all - :inactive => :moderator end
140144
event :give_editor_rights do transition all - :inactive => :editor end
141145
event :give_admin_rights do transition all - :inactive => :admin end
@@ -145,6 +149,7 @@ def update_with_password(params={}, *options)
145149
def display_role(hasContents)
146150
case role
147151
when 'visitor' then hasContents ? 'contributeur' : 'visiteur'
152+
when 'maintainer' then 'mainteneur'
148153
when 'editor' then 'animateur'
149154
when 'moderator' then 'modérateur'
150155
when 'admin' then 'admin'
@@ -158,6 +163,11 @@ def log_role
158163
logs.create(description: "Changement de rôle : #{roles.join ' → '}", user_id: amr_id)
159164
end
160165

166+
# A tracker admin can update, assign and delete a node of the tracker
167+
def tracker_admin?
168+
admin? || maintainer?
169+
end
170+
161171
# An AMR is someone who is either an admin or a moderator
162172
def amr?
163173
admin? || moderator?

app/models/tracker.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ def assigned_to
7575
### ACL ###
7676

7777
def updatable_by?(account)
78-
account.moderator? || account.admin? || account.user_id == node.user_id
78+
account.maintainer? || account.moderator? || account.admin? || account.user_id == node.user_id
7979
end
8080

8181
def destroyable_by?(account)
82-
account.moderator? || account.admin?
82+
account.maintainer? || account.moderator? || account.admin?
8383
end
8484

8585
def too_old_for_comments?

app/views/admin/accounts/index.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@
7272
%td
7373
- if account.editor?
7474
= button_to "Simple visiteur", admin_account_editor_path(account.id), method: :delete, class: "change_role"
75+
- if account.maintainer?
76+
= button_to "Simple visiteur", admin_account_maintainer_path(account.id), method: :delete, class: "change_role"
7577
- elsif account.moderator?
7678
= button_to "Simple visiteur", admin_account_moderator_path(account.id), method: :delete, class: "change_role"
7779
- elsif account.admin?
7880
= button_to "Simple visiteur", admin_account_admin_path(account.id), method: :delete, class: "change_role"
7981
- elsif !account.inactive?
82+
= button_to "Mainteneur", admin_account_maintainer_path(account.id), class: "change_role"
8083
= button_to "Modérateur", admin_account_moderator_path(account.id), class: "change_role"
8184
= button_to "Animateur", admin_account_editor_path(account.id), class: "change_role"
8285
= button_to "Admin", admin_account_admin_path(account.id), class: "change_role"

app/views/statistics/tracker.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
- if @stats.good_workers.any?
3838
- maxval = @stats.good_workers.map {|a| a["cnt"] }.max
39-
%h2#nbfermees Nombre d’entrées fermées par les administrateurs
39+
%h2#nbfermees Nombre d’entrées fermées par les mainteneurs et administrateurs
4040
%table
4141
%tr
4242
%th Personne

app/views/trackers/_form.html.haml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
%p
1818
= form.label :state, "État"
1919
= form.select :state, Tracker::States.invert
20-
%p
21-
= form.label :assigned_to_user_id, "Assigné à"
22-
= form.collection_select :assigned_to_user_id, Account.admin, :user_id, :login, include_blank: true
20+
- if current_account.tracker_admin?
21+
%p
22+
= form.label :assigned_to_user_id, "Assigné à"
23+
= form.collection_select :assigned_to_user_id, Account.tracker_admin, :user_id, :login, include_blank: true
2324
%p
2425
= form.submit "Prévisualiser", id: "tracker_preview"
2526
= form.submit "Soumettre", 'data-disable-with' => "Enregistrement en cours" if @preview_mode || @tracker.persisted?

app/views/trackers/_tracker.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
%span.tracker_id ##{tracker.id}
55
= posted_by(tracker)
66
État de l’entrée : #{tracker.state_name}.
7+
- if tracker.assigned_to_user_id?
8+
Assigné à #{tracker.assigned_to}.
79
- if current_account && current_account.can_update?(tracker)
810
- c.actions = link_to("Modifier", "/suivi/#{tracker.to_param}/modifier", class: 'action')

app/views/trackers/index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
= f.collection_select :category_id, Category.all, :id, :title, include_blank: true
2323
%p
2424
= f.label :assigned_to_user_id, "Assigné à : "
25-
= f.collection_select :assigned_to_user_id, Account.admin, :user_id, :name, include_blank: true
25+
= f.collection_select :assigned_to_user_id, Account.tracker_admin, :user_id, :name, include_blank: true
2626
%p
2727
= label_tag :order, "Trier par : "
2828
= select_tag :order, options_for_select({ "Date d’ouverture" => "created_at", "Note" => "score", "Nombre de commentaires" => "comments_count", "Dernier commentaire" => "last_commented_at" }, @order)

0 commit comments

Comments
 (0)