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

version 0.1.0 #1

Merged
merged 39 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ea541c7
add code
untitledds Nov 30, 2024
fa17298
small fix actions
untitledds Nov 30, 2024
79d5696
small fix dockerfile
untitledds Nov 30, 2024
ce8481f
fix actions
untitledds Nov 30, 2024
2b2cb76
fix name in actions
untitledds Nov 30, 2024
b3ddac5
name
untitledds Nov 30, 2024
cb430e7
Update connector.py
untitledds Dec 1, 2024
a2f2b1c
Update connector.py
untitledds Dec 1, 2024
e3271b3
Update services.py
untitledds Dec 1, 2024
19c2de1
Update config.snippet.py
untitledds Dec 1, 2024
cd59fa6
Update services.py
untitledds Dec 1, 2024
019eb3c
Update services.py
untitledds Dec 1, 2024
7a20f36
Update connector.py
untitledds Dec 1, 2024
d2d49ef
Update connector.py
untitledds Dec 1, 2024
c69f3ae
Update services.py
untitledds Dec 1, 2024
55deddc
Update config.snippet.py
untitledds Dec 1, 2024
e0f1372
Create default.env
untitledds Dec 2, 2024
958510e
Update services.py
untitledds Dec 2, 2024
e8aa535
Update connector.py
untitledds Dec 2, 2024
c77d25b
Update services.py
untitledds Dec 2, 2024
2e6c67e
Update connector.py
untitledds Dec 2, 2024
2f54aaa
Update config.snippet.py
untitledds Dec 2, 2024
6f791ab
Update config.snippet.py
untitledds Dec 2, 2024
5d223d4
Update services.py
untitledds Dec 2, 2024
47013e6
Update config.snippet.py
untitledds Dec 2, 2024
36446a5
Update default.env
untitledds Dec 2, 2024
d37bd20
Update services.py
untitledds Dec 2, 2024
38068c3
Update services.py
untitledds Dec 2, 2024
b2324ff
Update README.md
untitledds Dec 2, 2024
e51c1a4
Update services.py
untitledds Dec 2, 2024
88147a9
Update config.snippet.py
untitledds Dec 2, 2024
f5ab5eb
Update default.env
untitledds Dec 2, 2024
fc80d66
Update services.py
untitledds Dec 2, 2024
db543f6
Update services.py
untitledds Dec 2, 2024
97cbc31
Update config.snippet.py
untitledds Dec 2, 2024
868354b
Update default.env
untitledds Dec 2, 2024
d2810ce
Update services.py
untitledds Dec 2, 2024
fe68a22
Update LICENSE
untitledds Dec 2, 2024
ac8d348
Create RELEASE_NOTES.md
untitledds Dec 2, 2024
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
Prev Previous commit
Next Next commit
Update services.py
  • Loading branch information
untitledds authored Dec 2, 2024
commit c77d25baae7bc6662130f5c246627764d9f35f04
55 changes: 32 additions & 23 deletions back/taiga_contrib_access_token_auth/services.py
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
logger = logging.getLogger(__name__)

USER_KEY = settings.ACCESS_TOKEN_USER_KEY
FILTER_GROUPS = os.getenv("FILTER_GROUPS", "False").lower() == "true"

# Сопоставление проектов
PROJECTS = {}
@@ -41,13 +42,13 @@ def access_token_register(
full_name: str,
oidc_guid: str,
groups: list = None,
token: str=None,
project_id: str=None,
):
logger.info(f"Starting registration process for user: {email}")
auth_data_model = apps.get_model("users", "AuthData")
user_model = apps.get_model("users", "User")
membership_model = apps.get_model("projects", "Membership")
role_model = apps.get_model("projects", "Role")
project_model = apps.get_model("projects", "Project")

try:
auth_data = auth_data_model.objects.get(key=USER_KEY, value=oidc_guid)
@@ -66,22 +67,38 @@ def access_token_register(
user_registered_signal.send(sender=user.__class__, user=user)
logger.info(f"New user created: {email}")

if token:
membership = get_membership_by_token(token)
membership.user = user
membership.save(update_fields=["user"])
logger.info(f"Membership updated for user: {email}")
# Определение project_id на основе групп
project_id = None
for group in groups:
if group in GROUP_PROJECT_MAPPING:
project_id = PROJECTS[GROUP_PROJECT_MAPPING[group]]
break

if groups:
user.groups.set(groups)
logger.info(f"Groups assigned to user: {email}, groups: {groups}")
default_role = determine_role(groups) if groups else settings.ROLES[settings.DEFAULT_ROLE]

if FILTER_GROUPS and not groups:
raise ConnectorBaseException({
"error_message": "Access denied",
"details": "Required groups not found"
})

if project_id:
project = project_model.objects.get(id=project_id)
else:
user.groups.set([settings.GROUPS["WATCHERS"]])
logger.info(f"Default group 'Watchers' assigned to user: {email}")
project_id = settings.DEFAULT_PROJECT_ID
project = project_model.objects.get(id=project_id)

default_role = determine_role(groups) if groups else settings.ROLES[settings.DEFAULT_ROLE]
membership_model.objects.create(user=user, role=default_role, project_id=project_id)
logger.info(f"Role assigned to user: {email}, role: {default_role}, project_id: {project_id}")
role, _ = role_model.objects.get_or_create(
project=project,
name=default_role
)

membership_model.objects.get_or_create(
user=user,
project=project,
role=role
)
logger.info(f"Role assigned to user: {email}, role: {default_role}, project_id: {project.id}")

return user

@@ -91,20 +108,12 @@ def access_token_login_func(request):
user_info = get_user_info(access_token)
groups = user_info.get('groups', [])

# Определение project_id на основе групп
project_id = None
for group in groups:
if group in GROUP_PROJECT_MAPPING:
project_id = PROJECTS[GROUP_PROJECT_MAPPING[group]]
break

user = access_token_register(
username=user_info['username'],
email=user_info['email'],
full_name=user_info['full_name'],
oidc_guid=user_info['guid'],
groups=groups,
project_id=project_id,
)
data = make_auth_response_data(user)
return data