Skip to content

Commit a0c9e12

Browse files
committed
account: add maintainer role to give rights to manage tracker
1 parent 83fb9d8 commit a0c9e12

File tree

9 files changed

+39
-7
lines changed

9 files changed

+39
-7
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(:admin?) or current_account.try(:maintainer?)
9292
params.require(:tracker).permit!
9393
else
9494
params.require(:tracker).permit(:title, :wiki_body, :category_id, :state)

app/models/account.rb

Lines changed: 4 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,7 @@ def update_with_password(params={}, *options)
127128
### Role ###
128129

129130
scope :active, -> { where("role != 'inactive'") }
131+
scope :maintainer, -> { where(role: %w[admin maintainer]) }
130132
scope :moderator, -> { where(role: "moderator") }
131133
scope :editor, -> { where(role: "editor") }
132134
scope :admin, -> { where(role: "admin") }
@@ -136,6 +138,7 @@ def update_with_password(params={}, *options)
136138
event :inactivate do transition all => :inactive end
137139
event :reactivate do transition :inactive => :visitor end
138140
event :remove_all_rights do transition all - :inactive => :visitor end
141+
event :give_maintainer_rights do transition all - :inactive => :maintainer end
139142
event :give_moderator_rights do transition all - :inactive => :moderator end
140143
event :give_editor_rights do transition all - :inactive => :editor end
141144
event :give_admin_rights do transition all - :inactive => :admin end
@@ -145,6 +148,7 @@ def update_with_password(params={}, *options)
145148
def display_role(hasContents)
146149
case role
147150
when 'visitor' then hasContents ? 'contributeur' : 'visiteur'
151+
when 'maintainer' then 'mainteneur'
148152
when 'editor' then 'animateur'
149153
when 'moderator' then 'modérateur'
150154
when 'admin' then 'admin'

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
- elsif account.admin?
7878
= button_to "Simple visiteur", admin_account_admin_path(account.id), method: :delete, class: "change_role"
7979
- elsif !account.inactive?
80+
= button_to "Mainteneur", admin_account_maintainer_path(account.id), class: "change_role"
8081
= button_to "Modérateur", admin_account_moderator_path(account.id), class: "change_role"
8182
= button_to "Animateur", admin_account_editor_path(account.id), class: "change_role"
8283
= button_to "Admin", admin_account_admin_path(account.id), class: "change_role"

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.admin? or current_account.maintainer?
21+
%p
22+
= form.label :assigned_to_user_id, "Assigné à"
23+
= form.collection_select :assigned_to_user_id, Account.maintainer, :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.maintainer, :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)

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
get "/admin/debug" => "admin#debug"
179179
namespace :admin do
180180
resources :comptes, controller: "accounts", as: "accounts", only: [:index, :update, :destroy] do
181+
resource :maintainer, only: [:create, :destroy]
181182
resource :moderator, only: [:create, :destroy]
182183
resource :editor, only: [:create, :destroy]
183184
resource :admin, only: [:create, :destroy]

0 commit comments

Comments
 (0)