aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2023-03-31 13:43:07 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2023-03-31 13:43:07 -0400
commit48648eadcaae14247a87fbc3f2f9a48b14e6c5a4 (patch)
tree0bb18425fd2a2aed580a7782f17ea1e70d4b1055
parent85c735ca89603cea95c55b6967eea592dfd7d93f (diff)
downloadpeebz-48648eadcaae14247a87fbc3f2f9a48b14e6c5a4.tar.gz
Add privacy mode that doesn't leak addresses
In privacy mode, any addresses not viewable to an anonymous user will not be included into outgoing mail. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--default.config.toml1
-rw-r--r--peebz/__init__.py23
-rw-r--r--peebz/bz2pi.py30
3 files changed, 39 insertions, 15 deletions
diff --git a/default.config.toml b/default.config.toml
index a490f19..993b9af 100644
--- a/default.config.toml
+++ b/default.config.toml
@@ -35,6 +35,7 @@ pi_must_bz_groups = ['editbugs']
pi_url = 'https://lore.kernel.org/all/'
pi_assign_regex = '^bugbot assign to (\S+)'
bz_new_bugs_quicksearch = 'OPEN flag:bugbot+'
+bz_privacy_mode = true
alwayscc = ['bugs@lists.linux.dev']
[templates]
diff --git a/peebz/__init__.py b/peebz/__init__.py
index 05c48e2..78d83b8 100644
--- a/peebz/__init__.py
+++ b/peebz/__init__.py
@@ -381,7 +381,7 @@ def bz_get_changed_bugs(since: str, include_untracked: bool = False) -> List:
logger.debug('Querying for changed bugs since %s', since)
params = {
'chfieldfrom': since,
- 'include_fields': 'id,summary',
+ 'include_fields': 'id,summary,product,component',
}
rdata = bz_rest('bug', params=params)
if include_untracked:
@@ -406,7 +406,7 @@ def bz_get_changed_bugs(since: str, include_untracked: bool = False) -> List:
def bz_quicksearch_bugs(query: str) -> Dict:
params = {
- 'include_fields': 'id,summary',
+ 'include_fields': 'id,summary,product,component',
'quicksearch': query,
}
return bz_rest('bug', params=params)
@@ -414,7 +414,7 @@ def bz_quicksearch_bugs(query: str) -> Dict:
def bz_get_query_bugs(params: Dict, exclude: Set[int]) -> List[int]:
if 'include_fields' not in params:
- params['include_fields'] = 'id,summary'
+ params['include_fields'] = 'id,summary,product,component'
rdata = bz_rest('bug', params=params)
bids = list()
for bdata in rdata['bugs']:
@@ -755,12 +755,19 @@ def get_bug_recipients(bid: int) -> Set[str]:
logger.debug('No in-database recipients for bid=%s', bid)
# Now get all bug cc recipients
bdata = bz_get_bug(bid, resolve_dupes=True)
- bugr = set(bdata['cc'])
- bugr.add(bdata['assigned_to'])
- bugr.add(bdata['creator'])
- bugr.update(get_recipients_by_product_component(bdata['product'], bdata['component']))
- allrecip.update(bugr)
+ product = bdata['product']
+ component = bdata['component']
config = get_config()
+ cconf = get_component_config(product, component)
+ bugr = get_recipients_by_product_component(product, component)
+ if config['bugzilla'].get('privacy_mode', False) or cconf.get('bz_privacy_mode', False):
+ logger.debug('Privacy mode on, not adding addresses from the bug')
+ else:
+ bugr.update(bdata['cc'])
+ bugr.add(bdata['assigned_to'])
+ bugr.add(bdata['creator'])
+
+ allrecip.update(bugr)
subsystem_cf = config['bugzilla'].get('subsystem_cf')
if subsystem_cf:
subr = get_recipients_by_subsystem(bdata[subsystem_cf])
diff --git a/peebz/bz2pi.py b/peebz/bz2pi.py
index b78a648..1726d30 100644
--- a/peebz/bz2pi.py
+++ b/peebz/bz2pi.py
@@ -16,7 +16,7 @@ from fnmatch import fnmatch
logger = peebz.logger
-def process_new_comments(bid: int, dry_run: bool = False):
+def process_new_comments(bid: int, privacy_mode: bool = False, dry_run: bool = False):
config = peebz.get_config()
cdatas = peebz.bz_get_newest_comments_for_bid(bid)
for cdata in cdatas:
@@ -47,11 +47,16 @@ def process_new_comments(bid: int, dry_run: bool = False):
continue
clines = cdata['text'].strip().splitlines()
inre_cid = None
+ comment_author = cdata['creator']
+ if privacy_mode:
+ comment_author = comment_author.split('@')[0]
+ logger.debug('Privacy mode, comment_author=%s', comment_author)
+
bodyvals = {
'bzname': config['bugzilla'].get('name'),
'bug_url': config['bugzilla'].get('bugmask', '').format(bug_id=bid),
'comment_url': config['bugzilla'].get('bugmask', '').format(bug_id=bid) + f"#c{cdata['count']}",
- 'comment_author': cdata['creator'],
+ 'comment_author': comment_author,
}
if cdata['attachment_id']:
logger.info('Processing new attachment for bug_id=%s, comment_id=%s', bid, cid)
@@ -80,14 +85,16 @@ def process_new_comments(bid: int, dry_run: bool = False):
bodytpt = peebz.get_template_by_bid('new_comment_notify', bid)
msg = email.message.EmailMessage()
- msg['Reply-To'] = b4.format_addrs([('', cdata['creator'])])
+ if not privacy_mode:
+ msg['Reply-To'] = b4.format_addrs([('', cdata['creator'])])
body = bodytpt.safe_substitute(bodyvals)
body = peebz.add_bot_signature(body)
msg.set_payload(body, charset='utf-8')
msgid = peebz.notify_bug(bid, cid, msg, inre_cid=inre_cid, dry_run=dry_run)
if msgid and not dry_run:
peebz.db_store_msgid_bid_cid(msgid, bid, cid)
- peebz.db_store_recipients(bid, {cdata['creator']})
+ if not privacy_mode:
+ peebz.db_store_recipients(bid, {cdata['creator']})
# TODO: This assumes that comments are always in incremental order
lastcheck = cdata['creation_time'].replace('T', ' ').rstrip('Z')
peebz.db_store_notify_last_check(bid, lastcheck)
@@ -109,17 +116,22 @@ def main(cmdargs: argparse.Namespace) -> None:
logger.info('Getting a list of changed bugs since %s', since)
buglist = peebz.bz_get_changed_bugs(since)
seen = set()
+ config = peebz.get_config()
if buglist:
for bdata in buglist:
logger.debug('Looking at %s: %s', bdata['id'], bdata['summary'])
bid = bdata['id']
+ cconf = peebz.get_component_config(bdata['product'], bdata['component'])
+ if config['bugzilla'].get('privacy_mode', False) or cconf.get('bz_privacy_mode', False):
+ privacy_mode = True
+ else:
+ privacy_mode = False
+ process_new_comments(bid, privacy_mode=privacy_mode, dry_run=cmdargs.dry_run)
seen.add(bid)
- process_new_comments(bid, dry_run=cmdargs.dry_run)
else:
logger.info('No changes to any tracked bugs')
# Now go by product/component and handle new bug queries if defined
- config = peebz.get_config()
for bz_product, bz_components in config['components'].items():
for bz_component in bz_components.keys():
cconf = peebz.get_component_config(bz_product, bz_component)
@@ -136,11 +148,15 @@ def main(cmdargs: argparse.Namespace) -> None:
'quicksearch': qs,
}
buglist = peebz.bz_get_query_bugs(params, exclude=seen)
+ if config['bugzilla'].get('privacy_mode', False) or cconf.get('bz_privacy_mode', False):
+ privacy_mode = True
+ else:
+ privacy_mode = False
if buglist:
logger.info('Processing %s matching quicksearch bugs', len(buglist))
for bid in buglist:
seen.add(bid)
- process_new_comments(bid, dry_run=cmdargs.dry_run)
+ process_new_comments(bid, privacy_mode=privacy_mode, dry_run=cmdargs.dry_run)
else:
logger.info('No changed bugs matching these parameters.')