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

feat: theme config tenant creation api implementation #234

Merged

Conversation

tehreem-sadat
Copy link
Collaborator

@tehreem-sadat tehreem-sadat commented Feb 24, 2025

Description:

New tenant creation API

Related Issue:

#225

@tehreem-sadat tehreem-sadat force-pushed the tehreem/theme_config_tenant_creation_api_implementation branch from 4345c74 to 7ffef17 Compare February 24, 2025 11:40
Copy link
Collaborator

@shadinaif shadinaif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @tehreem-sadat , please check my notes

"""
Generate a tenant configuration by copying the default config and replacing placeholder PARAM.

:param name: Name to replace 'PARAM' in the default configuration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use platform_name instead of name. The more descriptive is the better

Suggested change
:param name: Name to replace 'PARAM' in the default configuration
:param platform_name: Name to replace `{{platform_name}}` in the default configuration

we also need sub_domain and course_org_filter as parameters

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed we don't need course_org_filter separately as param. In default config to copy we can have somethings as follows which can be handled by sub_domain replacement.

"course_org_filter": [
    "{sub_domain}"
]

:param sub_domain: The subdomain to be used for the tenant
:return: The created TenantConfig object
"""
config_data = generate_tenant_config(sub_domain)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
config_data = generate_tenant_config(sub_domain)
# .... Verify that the site domain is not already in `Route` ....
config_data = generate_tenant_config(sub_domain)

@tehreem-sadat tehreem-sadat force-pushed the tehreem/theme_config_tenant_creation_api_implementation branch 5 times, most recently from 958e098 to 8263304 Compare February 26, 2025 01:20
@tehreem-sadat tehreem-sadat force-pushed the tehreem/theme_config_tenant_creation_api_implementation branch from 8263304 to 3353162 Compare February 26, 2025 08:12
Copy link
Collaborator

@shadinaif shadinaif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @tehreem-sadat . Please address the change requests and merge

Comment on lines 1788 to 1789
'description': 'Create new tenant along with default theme config. The caller must have staff or fx '
'api global access.\n',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this to be mentioned since it's configurable through View Roles admin page

Suggested change
'description': 'Create new tenant along with default theme config. The caller must have staff or fx '
'api global access.\n',
'description': 'Create new tenant along with default theme config.\n',

caller=self.fx_permission_info['user'],
tenant_ids=[tenant_config.id],
user_keys=[data['owner_user_id']],
role='staff',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
role='staff',
role=cs.COURSE_ACCESS_ROLES_STAFF_EDITOR,

Comment on lines 93 to 98
if cs.CACHE_NAMES.get(name) is None:
raise FXCodedException(
code=FXExceptionCodes.INVALID_INPUT,
message=f'Cache with {name} does not exist.'
)
cache.set(name, None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to raise an error

Suggested change
if cs.CACHE_NAMES.get(name) is None:
raise FXCodedException(
code=FXExceptionCodes.INVALID_INPUT,
message=f'Cache with {name} does not exist.'
)
cache.set(name, None)
cache.delete(name)

Comment on lines 357 to 361
if TenantConfig.objects.filter(external_key=sub_domain).exists():
raise FXCodedException(
code=FXExceptionCodes.TENANT_ALREADY_EXIST,
message=f'Tenant already exists for given sub_domain: ({sub_domain}).',
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need. The external key is a random number sometimes. We'll trust Route and that's it

Suggested change
if TenantConfig.objects.filter(external_key=sub_domain).exists():
raise FXCodedException(
code=FXExceptionCodes.TENANT_ALREADY_EXIST,
message=f'Tenant already exists for given sub_domain: ({sub_domain}).',
)

@@ -71,3 +74,36 @@ def wrapped(*args: Any, **kwargs: Any) -> Dict[str, Any]:

return wrapped
return decorator


def invalidate_cache(cache_name: str) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we use None instead of __all__. Because it's less error prune. So, invalidate_cache() will invalidate everything, looks very clear to me. What do you think?

Suggested change
def invalidate_cache(cache_name: str) -> None:
def invalidate_cache(cache_name: str = None) -> None:

@tehreem-sadat tehreem-sadat force-pushed the tehreem/theme_config_tenant_creation_api_implementation branch from 3353162 to 7e7ea0e Compare February 26, 2025 10:26
@tehreem-sadat tehreem-sadat merged commit 045380f into main Feb 26, 2025
3 checks passed
@tehreem-sadat tehreem-sadat deleted the tehreem/theme_config_tenant_creation_api_implementation branch February 26, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants