Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable trusted sources for username matching #928

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading