diff --git a/.rspec b/.rspec index 53607ea..660778b 100644 --- a/.rspec +++ b/.rspec @@ -1 +1 @@ ---colour +--colour --format documentation diff --git a/app/models/user.rb b/app/models/user.rb index 97819f0..453f09d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 @@ -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 diff --git a/app/models/workitem.rb b/app/models/workitem.rb index 66982f8..bc955d6 100644 --- a/app/models/workitem.rb +++ b/app/models/workitem.rb @@ -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 #-- diff --git a/app/views/workitems/index.haml b/app/views/workitems/index.haml index e623d05..541c6c1 100644 --- a/app/views/workitems/index.haml +++ b/app/views/workitems/index.haml @@ -22,5 +22,5 @@ %td = workitem.params['task'] %td - = link_to t('.show'), workitem_path(workitem) + -#= link_to t('.show'), workitem_path(workitem) diff --git a/spec/requests/workitems_spec.rb b/spec/requests/workitems_spec.rb index cbc243c..29e5fa3 100644 --- a/spec/requests/workitems_spec.rb +++ b/spec/requests/workitems_spec.rb @@ -20,6 +20,25 @@ 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') @@ -27,6 +46,19 @@ 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