Skip to content

Commit

Permalink
users and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Oct 29, 2010
1 parent d6d4b35 commit 3eb919a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .rspec
@@ -1 +1 @@
--colour
--colour --format documentation
20 changes: 19 additions & 1 deletion app/models/user.rb
Expand Up @@ -29,10 +29,20 @@ def initialize(name, locale, pass, groups)
@groups = groups
end

def in_group?(group_name)

@groups.include?(group_name)
end

def admin?

in_group?('admin')
end

def self.admin?(name)

if u = find(name)
u.groups.include?('admin')
u.admin?
else
false
end
Expand Down Expand Up @@ -76,5 +86,13 @@ def self.all
a
}
end

# Returns a list of all the known groups (all the groups mentioned in
# the passwd file).
#
def self.groups

all.collect { |user| user.groups }.flatten.uniq.sort
end
end

16 changes: 13 additions & 3 deletions app/models/workitem.rb
Expand Up @@ -18,10 +18,20 @@ def participant_name=(name)

def self.for_user(username)

return RuoteKit.engine.storage_participant.all if User.admin?(username)
user = User.find(username)

RuoteKit.engine.storage_participant.by_participant(username) +
RuoteKit.engine.storage_participant.by_participant('anyone')
return RuoteKit.engine.storage_participant.all if user.admin?

# note : ruote 2.1.12 should make it possible to write
#
# RuoteKit.engine.storage_participant.by_participant(
# [ username, user.groups, 'anyone' ].flatten)
#
# directly.

[ username, user.groups, 'anyone' ].flatten.collect { |pname|
RuoteKit.engine.storage_participant.by_participant(pname)
}.flatten
end

#--
Expand Down
2 changes: 1 addition & 1 deletion app/views/workitems/index.haml
Expand Up @@ -22,5 +22,5 @@
%td
= workitem.params['task']
%td
= link_to t('.show'), workitem_path(workitem)
-#= link_to t('.show'), workitem_path(workitem)
32 changes: 32 additions & 0 deletions spec/requests/workitems_spec.rb
Expand Up @@ -20,13 +20,45 @@

context 'when there are workitems' do

before(:each) do

%w[ alice bob ].each_with_index do |pname, i|

RuoteKit.storage_participant.update(Ruote::Workitem.new(
'fei' => {
'engineid' => 'engine',
'wfid' => "20101029#{i}-abcd",
'expid' => '0.0.0' },
'participant_name' => pname,
'fields' => { 'params' => { 'task' => "task for #{pname}" } }))
end
end

after(:each) do

RuoteKit.engine.storage.purge!
end

it 'shows them' do

login_as('bob')

get '/workitems'

response.status.should == 200
response.should_not contain('for alice')
response.should contain('for bob')
end

it 'shows all the workitems to admins' do

login_as('admin')

get '/workitems'

response.status.should == 200
response.should contain('for alice')
response.should contain('for bob')
end
end
end
Expand Down

0 comments on commit 3eb919a

Please sign in to comment.