mirror of
https://github.com/wahyd4/ocelots.git
synced 2026-08-09 04:56:21 +10:00
add all accessable team to show
This commit is contained in:
+14
-2
@@ -52,12 +52,24 @@ class Person < ActiveRecord::Base
|
||||
|
||||
def allowed_to_view? person
|
||||
return false unless person
|
||||
blessed? or person == self or !(teams & person.approved_teams).empty?
|
||||
omnipotent? or person == self or !(teams & person.approved_teams).empty?
|
||||
end
|
||||
|
||||
def allowed_to_view_team? team
|
||||
return false unless team
|
||||
blessed? or team.creator == self or teams.include?(team)
|
||||
team.public? or blessed?(team) or team.creator == self or teams.include?(team)
|
||||
end
|
||||
|
||||
def viewable_teams
|
||||
Team.find(:all).select{|team| allowed_to_view_team?(team)}
|
||||
end
|
||||
|
||||
def blessed?(team)
|
||||
return true if omnipotent?
|
||||
team.blessed?(email_domain)
|
||||
end
|
||||
|
||||
def email_domain
|
||||
email.split('@').last
|
||||
end
|
||||
end
|
||||
@@ -17,4 +17,11 @@ class Team < ActiveRecord::Base
|
||||
att[:members] = memberships.includes(:person).approved.map(&:person).map(&:api_attributes) if params[:include] and params[:include].include? :members
|
||||
att
|
||||
end
|
||||
|
||||
def blessed?(domain)
|
||||
organisations.map{|org| org.domains.split(',')}.flatten.include?(domain)
|
||||
end
|
||||
def public?
|
||||
organisations.empty?
|
||||
end
|
||||
end
|
||||
@@ -44,3 +44,15 @@ div id="add_new" style="display:none;"
|
||||
= form_tag "/membership/leave" do
|
||||
input type="hidden" name="id" value="#{membership.id}"
|
||||
= submit_tag 'Leave', class: 'btn btn-danger btn-block'
|
||||
div.clearfix
|
||||
- current_person.viewable_teams.each do |team|
|
||||
a href="/teams/#{team.slug}"
|
||||
span.badge.badge-info Viewable
|
||||
div.hero-unit.highlight
|
||||
div.row
|
||||
div.span4
|
||||
img src="/assets/team.png"
|
||||
div.span4
|
||||
h1 = team.name
|
||||
p = team.description
|
||||
|
||||
|
||||
@@ -6,9 +6,4 @@ module Omnipotence
|
||||
def omnipotent?
|
||||
Omnipotence.omnipotent? email
|
||||
end
|
||||
|
||||
def blessed?
|
||||
return true if omnipotent?
|
||||
(ENV['BLESSED_DOMAINS'] || '').split(',').include? email.split('@').last
|
||||
end
|
||||
end
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
module TeamFilter
|
||||
def with_team
|
||||
@team = Team.find_by_slug params[:slug]
|
||||
unless current_person.blessed?
|
||||
unless current_person.blessed?(@team)
|
||||
@team = nil unless current_person.teams.include?(@team) or @team.creator == current_person
|
||||
end
|
||||
if @team
|
||||
|
||||
@@ -44,4 +44,26 @@ describe Person do
|
||||
created_person.account.should =~ /\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/
|
||||
end
|
||||
end
|
||||
|
||||
describe :viewable_teams do
|
||||
let(:email) { 'fake_user@thoughtworks.com' }
|
||||
let(:person) { Person.create_for_email(email) }
|
||||
let(:blessed_organisation) { Organisation.create(name: 'ThoughtWorks', domains: 'thoughtworks.com') }
|
||||
let(:viewable_team) { blessed_organisation.teams.create(name: 'TW Project', slug: 'tw_project') }
|
||||
let(:non_blessed_organisation) { Organisation.create(name: 'Microsoft', domains: 'microsoft.com') }
|
||||
let(:non_viewable_team){ non_blessed_organisation.teams.create(name: 'MS Project', slug: 'ms_project') }
|
||||
let(:public_team){Team.create(name: 'Public Test Team', slug: 'public.com')}
|
||||
|
||||
before(:each) do
|
||||
viewable_team.reload
|
||||
public_team.reload
|
||||
non_viewable_team.reload
|
||||
end
|
||||
|
||||
it 'lists viewable teams but not non-viewable teams' do
|
||||
person.viewable_teams.should be_include(viewable_team)
|
||||
person.viewable_teams.should_not be_include(non_viewable_team)
|
||||
person.viewable_teams.should be_include(public_team)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user