Skip to content

Commit

Permalink
feat: add waffle flag for enterprise groups feature (#2039)
Browse files Browse the repository at this point in the history
feat: add waffle flag for enterprise groups feature

feat: add waffle flag for enterprise groups feature

fix: version

fix: lint error

chore: rebase
  • Loading branch information
katrinan029 committed Mar 1, 2024
1 parent a23e042 commit f383a8c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Change Log
Unreleased
----------
[4.13.2]
---------
* feat: add a waffle flag for enterprise groups feature

[4.13.1]
---------
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.13.1"
__version__ = "4.13.2"
20 changes: 20 additions & 0 deletions enterprise/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
ENTERPRISE_LOG_PREFIX,
)

# .. toggle_name: enterprise.enterprise_groups_v1
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Enables enterprise groups feature
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2024-02-29
ENTERPRISE_GROUPS_V1 = WaffleFlag(
f'{ENTERPRISE_NAMESPACE}.enterprise_groups_v1',
__name__,
ENTERPRISE_LOG_PREFIX,
)


def top_down_assignment_real_time_lcm():
"""
Expand All @@ -46,11 +58,19 @@ def feature_prequery_search_suggestions():
return FEATURE_PREQUERY_SEARCH_SUGGESTIONS.is_enabled()


def enterprise_groups_v1():
"""
Returns whether the enterprise groups feature flag is enabled.
"""
return ENTERPRISE_GROUPS_V1.is_enabled()


def enterprise_features():
"""
Returns a dict of enterprise Waffle-based feature flags.
"""
return {
'top_down_assignment_real_time_lcm': top_down_assignment_real_time_lcm(),
'feature_prequery_search_suggestions': feature_prequery_search_suggestions(),
'enterprise_groups_v1': enterprise_groups_v1(),
}
3 changes: 2 additions & 1 deletion tests/test_enterprise/api/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def test_filter(self, is_staff, is_linked_to_enterprise, has_access):
'results': [],
'enterprise_features': {
'top_down_assignment_real_time_lcm': False,
'feature_prequery_search_suggestions': False
'feature_prequery_search_suggestions': False,
'enterprise_groups_v1': False
}
}
assert response == mock_empty_200_success_response
Expand Down
53 changes: 34 additions & 19 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
PendingEnrollment,
PendingEnterpriseCustomerUser,
)
from enterprise.toggles import FEATURE_PREQUERY_SEARCH_SUGGESTIONS, TOP_DOWN_ASSIGNMENT_REAL_TIME_LCM
from enterprise.toggles import (
ENTERPRISE_GROUPS_V1,
FEATURE_PREQUERY_SEARCH_SUGGESTIONS,
TOP_DOWN_ASSIGNMENT_REAL_TIME_LCM,
)
from enterprise.utils import (
NotConnectedToOpenEdX,
get_sso_orchestrator_api_base_url,
Expand Down Expand Up @@ -1519,59 +1523,61 @@ def test_enterprise_customer_basic_list(self):

@ddt.data(
# Request missing required permissions query param.
(True, False, [], {}, False, {'detail': 'User is not allowed to access the view.'}, False, False),
(True, False, [], {}, False, {'detail': 'User is not allowed to access the view.'}, False, False, False),
# Staff user that does not have the specified group permission.
(True, False, [], {'permissions': ['enterprise_enrollment_api_access']}, False,
{'detail': 'User is not allowed to access the view.'}, False, False),
{'detail': 'User is not allowed to access the view.'}, False, False, False),
# Staff user that does have the specified group permission.
(True, False, ['enterprise_enrollment_api_access'], {'permissions': ['enterprise_enrollment_api_access']},
True, None, False, False),
True, None, False, False, False),
# Non staff user that is not linked to the enterprise, nor do they have the group permission.
(False, False, [], {'permissions': ['enterprise_enrollment_api_access']}, False,
{'detail': 'User is not allowed to access the view.'}, False, False),
{'detail': 'User is not allowed to access the view.'}, False, False, False),
# Non staff user that is not linked to the enterprise, but does have the group permission.
(False, False, ['enterprise_enrollment_api_access'], {'permissions': ['enterprise_enrollment_api_access']},
False, None, False, False),
False, None, False, False, False),
# Non staff user that is linked to the enterprise, but does not have the group permission.
(False, True, [], {'permissions': ['enterprise_enrollment_api_access']}, False,
{'detail': 'User is not allowed to access the view.'}, False, False),
{'detail': 'User is not allowed to access the view.'}, False, False, False),
# Non staff user that is linked to the enterprise and does have the group permission
(False, True, ['enterprise_enrollment_api_access'], {'permissions': ['enterprise_enrollment_api_access']},
True, None, False, False),
True, None, False, False, False),
# Non staff user that is linked to the enterprise and has group permission and the request has passed
# multiple groups to check.
(False, True, ['enterprise_enrollment_api_access'],
{'permissions': ['enterprise_enrollment_api_access', 'enterprise_data_api_access']}, True, None, False, False),
{'permissions': ['enterprise_enrollment_api_access', 'enterprise_data_api_access']}, True, None, False,
False, False),
# Staff user with group permission filtering on non existent enterprise id.
(True, False, ['enterprise_enrollment_api_access'],
{'permissions': ['enterprise_enrollment_api_access'], 'enterprise_id': FAKE_UUIDS[1]}, False,
None, False, False),
None, False, False, False),
# Staff user with group permission filtering on enterprise id successfully.
(True, False, ['enterprise_enrollment_api_access'],
{'permissions': ['enterprise_enrollment_api_access'], 'enterprise_id': FAKE_UUIDS[0]}, True,
None, False, False),
None, False, False, False),
# Staff user with group permission filtering on search param with no results.
(True, False, ['enterprise_enrollment_api_access'],
{'permissions': ['enterprise_enrollment_api_access'], 'search': 'blah'}, False,
None, False, False),
None, False, False, False),
# Staff user with group permission filtering on search param with results.
(True, False, ['enterprise_enrollment_api_access'],
{'permissions': ['enterprise_enrollment_api_access'], 'search': 'test'}, True,
None, False, False),
None, False, False, False),
# Staff user with group permission filtering on slug with results.
(True, False, ['enterprise_enrollment_api_access'],
{'permissions': ['enterprise_enrollment_api_access'], 'slug': TEST_SLUG}, True,
None, False, False),
None, False, False, False),
# Staff user with group permissions filtering on slug with no results.
(True, False, ['enterprise_enrollment_api_access'],
{'permissions': ['enterprise_enrollment_api_access'], 'slug': 'blah'}, False,
None, False, False),
None, False, False, False),
# Staff user with group permission filtering on slug with results, with
# top down assignment & real-time LCM feature enabled and
# prequery search results enabled
# top down assignment & real-time LCM feature enabled,
# prequery search results enabled and
# enterprise groups v1 feature enabled
(True, False, ['enterprise_enrollment_api_access'],
{'permissions': ['enterprise_enrollment_api_access'], 'slug': TEST_SLUG}, True,
None, True, True),
None, True, True, True),
)
@ddt.unpack
@mock.patch('enterprise.utils.get_logo_url')
Expand All @@ -1585,6 +1591,7 @@ def test_enterprise_customer_with_access_to(
expected_error,
is_top_down_assignment_real_time_lcm_enabled,
feature_prequery_search_suggestions_enabled,
enterprise_groups_v1_enabled,
mock_get_logo_url,
):
"""
Expand Down Expand Up @@ -1643,6 +1650,14 @@ def test_enterprise_customer_with_access_to(
active=feature_prequery_search_suggestions_enabled
):

response = client.get(
f"{settings.TEST_SERVER}{ENTERPRISE_CUSTOMER_WITH_ACCESS_TO_ENDPOINT}?{urlencode(query_params, True)}"
)
with override_waffle_flag(
ENTERPRISE_GROUPS_V1,
active=enterprise_groups_v1_enabled
):

response = client.get(
f"{settings.TEST_SERVER}{ENTERPRISE_CUSTOMER_WITH_ACCESS_TO_ENDPOINT}?{urlencode(query_params, True)}"
)
Expand Down Expand Up @@ -1706,7 +1721,7 @@ def test_enterprise_customer_with_access_to(
'enterprise_features': {
'top_down_assignment_real_time_lcm': is_top_down_assignment_real_time_lcm_enabled,
'feature_prequery_search_suggestions': feature_prequery_search_suggestions_enabled,

'enterprise_groups_v1': enterprise_groups_v1_enabled,
}
}
assert response in (expected_error, mock_empty_200_success_response)
Expand Down

0 comments on commit f383a8c

Please sign in to comment.