From f7292fdd1a8a9bc6843e34e5bb878e27086ab10d Mon Sep 17 00:00:00 2001 From: Jose Javier Merchante Date: Mon, 16 Sep 2024 11:54:25 +0200 Subject: [PATCH] Customizable trusted sources for username matching 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 --- config/settings/config_testing.py | 2 ++ config/settings/devel.py | 3 +++ ...ustomizable-trusted-sources-for-username-matching.yml | 9 +++++++++ sortinghat/config/settings.py | 7 +++++++ sortinghat/core/recommendations/matching.py | 6 +++--- 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 releases/unreleased/customizable-trusted-sources-for-username-matching.yml diff --git a/config/settings/config_testing.py b/config/settings/config_testing.py index 8153e8f0..83a507ca 100644 --- a/config/settings/config_testing.py +++ b/config/settings/config_testing.py @@ -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 = [ diff --git a/config/settings/devel.py b/config/settings/devel.py index fa9a2acb..cd644fb1 100644 --- a/config/settings/devel.py +++ b/config/settings/devel.py @@ -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(',') diff --git a/releases/unreleased/customizable-trusted-sources-for-username-matching.yml b/releases/unreleased/customizable-trusted-sources-for-username-matching.yml new file mode 100644 index 00000000..507cc243 --- /dev/null +++ b/releases/unreleased/customizable-trusted-sources-for-username-matching.yml @@ -0,0 +1,9 @@ +--- +title: Customizable trusted sources for username matching +category: added +author: Jose Javier Merchante +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. diff --git a/sortinghat/config/settings.py b/sortinghat/config/settings.py index e7cf6fee..9615f751 100644 --- a/sortinghat/config/settings.py +++ b/sortinghat/config/settings.py @@ -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(',') diff --git a/sortinghat/core/recommendations/matching.py b/sortinghat/core/recommendations/matching.py index fcf4f318..36dbbfe5 100644 --- a/sortinghat/core/recommendations/matching.py +++ b/sortinghat/core/recommendations/matching.py @@ -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) @@ -39,8 +41,6 @@ EMAIL_ADDRESS_REGEX = r"^(?P[^\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, @@ -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])