Commit e330f35 1 parent 45ab9ed commit e330f35 Copy full SHA for e330f35
File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 10
10
# hubot what roles does <user> have - Find out what roles a user has
11
11
# hubot what roles do I have - Find out what roles you have
12
12
# hubot who has <role> role - Find out who has the given role
13
+ # hubot list assigned roles - List all roles and users assigned to them
13
14
#
14
15
# Notes:
15
16
# * Call the method: robot.auth.hasRole(msg.envelope.user,'<role>')
@@ -64,6 +65,7 @@ module.exports = (robot) ->
64
65
65
66
robot .auth = new Auth
66
67
68
+
67
69
robot .respond / @? ([^ \s ] + ) ha(?:s| ve) (["'\w : -_ ] + ) role/ i , (msg ) ->
68
70
name = msg .match [1 ].trim ()
69
71
if name .toLowerCase () is ' i' then name = msg .message .user .name
@@ -129,3 +131,15 @@ module.exports = (robot) ->
129
131
msg .reply " The following people have the '#{ role} ' role: #{ userNames .join (' , ' )} "
130
132
else
131
133
msg .reply " There are no people that have the '#{ role} ' role."
134
+
135
+ robot .respond / list assigned roles/ i , (msg ) ->
136
+ roles = []
137
+ unless robot .auth .isAdmin msg .message .user
138
+ msg .reply " Sorry, only admins can list assigned roles."
139
+ else
140
+ for i, user of robot .brain .data .users when user .roles
141
+ roles .push role for role in user .roles when role not in roles
142
+ if roles .length > 0
143
+ msg .reply " The following roles are available: #{ roles .join (' , ' )} "
144
+ else
145
+ msg .reply " No roles to list."
Original file line number Diff line number Diff line change @@ -121,3 +121,18 @@ describe 'auth', ->
121
121
done ()
122
122
123
123
adapter .receive (new TextMessage anon_user, " hubot: what roles does admin-user have?" )
124
+
125
+ it ' successfully list assigned roles' , (done ) ->
126
+ adapter .receive (new TextMessage admin_user, " hubot: admin-user has demo role" )
127
+ adapter .receive (new TextMessage admin_user, " hubot: anon-user has test role" )
128
+ adapter .receive (new TextMessage admin_user, " hubot: admin-user has test role" )
129
+
130
+ adapter .on " reply" , (envelope , strings ) ->
131
+ if strings[0 ].match / OK, . * has . * role/ i
132
+ return
133
+
134
+
135
+ expect (strings[0 ]).to .match (/ following roles . * :. * demo. * test/ )
136
+ done ()
137
+
138
+ adapter .receive (new TextMessage admin_user, " hubot: list assigned roles" )
You can’t perform that action at this time.
0 commit comments