Skip to content

Commit

Permalink
Customizable trusted sources for username matching
Browse files Browse the repository at this point in the history
Enable customization of trusted sources for username matching in
settings. This feature allows to define and manage the trusted data
sources for username matching from the configuration.

Signed-off-by: Jose Javier Merchante <jjmerchante@bitergia.com>
  • Loading branch information
jjmerchante committed Sep 16, 2024
1 parent d07cc1e commit d765488
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config/settings/config_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

SORTINGHAT_GENDERIZE_API_KEY = 'fake-key'

MATCH_TRUSTED_SOURCES = ['github', 'gitlab', 'slack']

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

INSTALLED_APPS = [
Expand Down
3 changes: 3 additions & 0 deletions config/settings/devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,6 @@
}

MULTI_TENANT = os.environ.get('SORTINGHAT_MULTI_TENANT', 'False').lower() in ('true', '1')

MATCH_TRUSTED_SOURCES = os.environ.get('SORTINGHAT_MATCH_TRUSTED_SOURCES',
'github,gitlab,slack').split(',')
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Customizable trusted sources for username matching
category: added
author: Jose Javier Merchante <jjmerchante@bitergia.com>
issue: null
notes: >
Enable customization of trusted sources for username matching in
settings. This feature allows to define and manage the trusted data
sources for username matching from the configuration.
7 changes: 7 additions & 0 deletions sortinghat/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,10 @@

PERMISSION_GROUPS_LIST_PATH = os.environ.get('SORTINGHAT_PERMISSION_GROUPS_LIST_PATH',
os.path.join(BASE_DIR, 'config', 'permission_groups.json'))

#
# Trusted data sources for matching by username
#

MATCH_TRUSTED_SOURCES = os.environ.get('SORTINGHAT_MATCH_TRUSTED_SOURCES',
'github,gitlab,slack').split(',')
6 changes: 3 additions & 3 deletions sortinghat/core/recommendations/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import numpy

from collections import defaultdict

from django.conf import settings
from django.forms.models import model_to_dict

from ..db import (find_individual_by_uuid)
Expand All @@ -39,8 +41,6 @@
EMAIL_ADDRESS_REGEX = r"^(?P<email>[^\s@]+@[^\s@.]+\.[^\s@]+)$"
NAME_REGEX = r"^\w+\s\w+"

MATCH_USERNAME_SOURCES = ['github', 'gitlab', 'slack']


def recommend_matches(source_uuids, target_uuids,
criteria, exclude=True,
Expand Down Expand Up @@ -199,7 +199,7 @@ def _filter_criteria(df, c, strict=True, match_source=False):
if match_source and c == 'username':
cols += ['source']
cdf = df[cols]
cdf = cdf[cdf['source'].isin(MATCH_USERNAME_SOURCES)]
cdf = cdf[cdf['source'].isin(settings.MATCH_TRUSTED_SOURCES)]
else:
cdf = df[cols]
cdf = cdf.dropna(subset=[c])
Expand Down

0 comments on commit d765488

Please sign in to comment.