59
65
def __init__(self, context):
60
66
self.context = context
62
def getAffiliationBadge(self, person):
66
# XXX: wallyworld 2011-05-24 bug=81692: TODO Work is required to determine
67
# exactly what is required in terms of figuring out affiliation..
70
class BugTaskPillarAffiliation(PillarAffiliation):
71
"""An affiliation adapter for bug tasks."""
73
def getAffiliationBadge(self, person):
74
pillar = self.context.pillar
75
affiliated = person.inTeam(pillar.owner)
71
def _getAffiliationDetails(self, person, pillar):
72
""" Return the affiliation information for a person, if any.
74
A person is affiliated with a pillar if they are in the list of
75
drivers or are the maintainer.
77
if person.inTeam(pillar.owner):
78
return pillar.displayname, 'maintainer'
79
for driver in pillar.drivers:
80
if person.inTeam(driver):
81
return pillar.displayname, 'driver'
84
def getAffiliationBadge(self, person):
85
""" Return the affiliation badge details for a person given a context.
87
pillar = self.getPillar()
88
affiliation_details = self._getAffiliationDetails(person, pillar)
89
if not affiliation_details:
79
def getIconUrl(context, default_url):
92
def getIconUrl(context, pillar, default_url):
80
93
if IHasIcon.providedBy(context) and context.icon is not None:
81
94
icon_url = context.icon.getURL()
96
if IHasIcon.providedBy(pillar) and pillar.icon is not None:
97
icon_url = context.icon.getURL()
85
alt_text = "Affiliated with %s" % pillar.displayname
101
alt_text = "%s %s" % affiliation_details
86
102
if IDistribution.providedBy(pillar):
87
icon_url = getIconUrl(pillar, "/@@/distribution-badge")
103
default_icon_url = "/@@/distribution-badge"
89
icon_url = getIconUrl(pillar, "/@@/product-badge")
105
default_icon_url = "/@@/product-badge"
106
icon_url = getIconUrl(self.context, pillar, default_icon_url)
90
107
return BadgeDetails(icon_url, alt_text)
111
class BugTaskPillarAffiliation(PillarAffiliation):
112
"""An affiliation adapter for bug tasks."""
114
return self.context.pillar
116
def _getAffiliationDetails(self, person, pillar):
117
""" A person is affiliated with a bugtask based on (in order):
118
- owner of bugtask pillar
119
- driver of bugtask pillar
120
- bug supervisor of bugtask pillar
121
- security contact of bugtask pillar
123
result = super(BugTaskPillarAffiliation, self)._getAffiliationDetails(
125
if result is not None:
127
if person.inTeam(pillar.bug_supervisor):
128
return pillar.displayname, 'bug supervisor'
129
if person.inTeam(pillar.security_contact):
130
return pillar.displayname, 'security contact'
133
@adapter(IDistroSeries)
134
class DistroSeriesPillarAffiliation(PillarAffiliation):
135
"""An affiliation adapter for distroseries."""
137
return self.context.distribution
140
@adapter(IProductSeries)
141
class ProductSeriesPillarAffiliation(PillarAffiliation):
142
"""An affiliation adapter for productseries."""
144
return self.context.product
147
@adapter(ISpecification)
148
class SpecificationPillarAffiliation(PillarAffiliation):
149
"""An affiliation adapter for blueprints."""
151
return (self.context.target)
155
class QuestionPillarAffiliation(PillarAffiliation):
156
"""An affiliation adapter for questions."""
158
return self.context.product or self.context.distribution
160
def _getAffiliationDetails(self, person, pillar):
161
""" A person is affiliated with a question based on (in order):
162
- answer contact for question target
163
- owner of question target
164
- driver of question target
166
target = self.context.target
167
answer_contacts = target.answer_contacts
168
for answer_contact in answer_contacts:
169
if person.inTeam(answer_contact):
170
return target.displayname, 'answer contact'
171
return super(QuestionPillarAffiliation, self)._getAffiliationDetails(