mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-23 11:53:08 -05:00
* Added permission syncing on the backend * Rewored to work with celery alembic fix fixed test * frontend changes * got groups working * added comments and fixed public docs * fixed merge issues * frontend complete! * frontend cleanup and mypy fixes * refactored connector access_type selection * mypy fixes * minor refactor and frontend improvements * get to fetch * renames and comments * minor change to var names * got curator stuff working * addressed pablo's comments * refactored user_external_group to reference users table * implemented polling * small refactor * fixed a whoopsies on the frontend * added scripts to seed dummy docs and test query times * fixed frontend build issue * alembic fix * handled is_public overlap * yuhong feedback * added more checks for sync * black * mypy * fixed circular import * todos * alembic fix * alembic
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
from dataclasses import dataclass
|
|
|
|
from danswer.access.utils import prefix_external_group
|
|
from danswer.access.utils import prefix_user_email
|
|
from danswer.access.utils import prefix_user_group
|
|
from danswer.configs.constants import PUBLIC_DOC_PAT
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ExternalAccess:
|
|
# Emails of external users with access to the doc externally
|
|
external_user_emails: set[str]
|
|
# Names or external IDs of groups with access to the doc
|
|
external_user_group_ids: set[str]
|
|
# Whether the document is public in the external system or Danswer
|
|
is_public: bool
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class DocumentAccess(ExternalAccess):
|
|
# User emails for Danswer users, None indicates admin
|
|
user_emails: set[str | None]
|
|
# Names of user groups associated with this document
|
|
user_groups: set[str]
|
|
|
|
def to_acl(self) -> set[str]:
|
|
return set(
|
|
[
|
|
prefix_user_email(user_email)
|
|
for user_email in self.user_emails
|
|
if user_email
|
|
]
|
|
+ [prefix_user_group(group_name) for group_name in self.user_groups]
|
|
+ [
|
|
prefix_user_email(user_email)
|
|
for user_email in self.external_user_emails
|
|
]
|
|
+ [
|
|
# The group names are already prefixed by the source type
|
|
# This adds an additional prefix of "external_group:"
|
|
prefix_external_group(group_name)
|
|
for group_name in self.external_user_group_ids
|
|
]
|
|
+ ([PUBLIC_DOC_PAT] if self.is_public else [])
|
|
)
|
|
|
|
@classmethod
|
|
def build(
|
|
cls,
|
|
user_emails: list[str | None],
|
|
user_groups: list[str],
|
|
external_user_emails: list[str],
|
|
external_user_group_ids: list[str],
|
|
is_public: bool,
|
|
) -> "DocumentAccess":
|
|
return cls(
|
|
external_user_emails={
|
|
prefix_user_email(external_email)
|
|
for external_email in external_user_emails
|
|
},
|
|
external_user_group_ids={
|
|
prefix_external_group(external_group_id)
|
|
for external_group_id in external_user_group_ids
|
|
},
|
|
user_emails={
|
|
prefix_user_email(user_email)
|
|
for user_email in user_emails
|
|
if user_email
|
|
},
|
|
user_groups=set(user_groups),
|
|
is_public=is_public,
|
|
)
|