Skip to content

Commit

Permalink
Merge pull request #5452 from hypothesis/remove-api-render-user-info-…
Browse files Browse the repository at this point in the history
…flag

Remove usage of api_render_user_info feature flag
  • Loading branch information
robertknight committed Dec 6, 2018
2 parents 4eb5e6c + ed0ee8e commit cdc8391
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 31 deletions.
2 changes: 1 addition & 1 deletion h/models/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'filter_highlights': ("Filter highlights in document based on visible"
" annotations in sidebar?"),
'overlay_highlighter': "Use the new overlay highlighter?",
'api_render_user_info': "Return users' extended info in API responses?",
'client_display_names': "Render display names instead of user names in the client",
}

Expand All @@ -39,6 +38,7 @@
# 4. Finally, remove the feature from FEATURES_PENDING_REMOVAL.
#
FEATURES_PENDING_REMOVAL = {
'api_render_user_info': "Return users' extended info in API responses?",
}


Expand Down
10 changes: 3 additions & 7 deletions h/services/annotation_json_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class AnnotationJSONPresentationService(object):
def __init__(self, session, user, group_svc, links_svc, flag_svc, flag_count_svc,
moderation_svc, user_svc, has_permission, render_user_info):
moderation_svc, user_svc, has_permission):
self.session = session
self.group_svc = group_svc
self.links_svc = links_svc
Expand All @@ -26,11 +26,9 @@ def moderator_check(group):
formatters.AnnotationFlagFormatter(flag_svc, user),
formatters.AnnotationHiddenFormatter(moderation_svc, moderator_check, user),
formatters.AnnotationModerationFormatter(flag_count_svc, user, has_permission),
formatters.AnnotationUserInfoFormatter(self.session, user_svc),
]

if render_user_info:
self.formatters.append(formatters.AnnotationUserInfoFormatter(self.session, user_svc))

def present(self, annotation_resource):
presenter = self._get_presenter(annotation_resource)
return presenter.asdict()
Expand Down Expand Up @@ -63,7 +61,6 @@ def annotation_json_presentation_service_factory(context, request):
flag_count_svc = request.find_service(name='flag_count')
moderation_svc = request.find_service(name='annotation_moderation')
user_svc = request.find_service(name='user')
render_user_info = request.feature('api_render_user_info')
return AnnotationJSONPresentationService(session=request.db,
user=request.user,
group_svc=group_svc,
Expand All @@ -72,5 +69,4 @@ def annotation_json_presentation_service_factory(context, request):
flag_count_svc=flag_count_svc,
moderation_svc=moderation_svc,
user_svc=user_svc,
has_permission=request.has_permission,
render_user_info=render_user_info)
has_permission=request.has_permission)
3 changes: 1 addition & 2 deletions h/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def profile(request, authority=None):
profile['features'] = request.feature.all()
profile['preferences'] = _user_preferences(user)

if request.feature('api_render_user_info'):
profile.update(user_info(user))
profile.update(user_info(user))

return profile

Expand Down
17 changes: 1 addition & 16 deletions tests/h/services/annotation_json_presentation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ def test_initializes_user_info_formatter(self, services, formatters, svc):
def test_it_configures_user_info_formatter(self, services, formatters, svc):
assert formatters.AnnotationUserInfoFormatter.return_value in svc.formatters

def test_it_skips_configuring_user_info_formatter_when_told_to(self, services, formatters):
svc = AnnotationJSONPresentationService(session=mock.sentinel.db_session,
user=mock.sentinel.user,
group_svc=services['group'],
links_svc=services['links'],
flag_svc=services['flag'],
flag_count_svc=services['flag_count'],
moderation_svc=services['annotation_moderation'],
user_svc=services['user'],
has_permission=mock.sentinel.has_permission,
render_user_info=False)

assert formatters.AnnotationUserInfoFormatter.return_value not in svc.formatters

def test_present_inits_presenter(self, svc, presenters, annotation_resource):
svc.present(annotation_resource)

Expand Down Expand Up @@ -121,8 +107,7 @@ def svc(self, services):
flag_count_svc=services['flag_count'],
moderation_svc=services['annotation_moderation'],
user_svc=services['user'],
has_permission=mock.sentinel.has_permission,
render_user_info=True)
has_permission=mock.sentinel.has_permission)

@pytest.fixture
def annotation_resource(self):
Expand Down
5 changes: 0 additions & 5 deletions tests/h/session_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ def test_user_info_authenticated(self, authenticated_request, patch):
user_info = profile['user_info']
assert user_info['display_name'] == authenticated_request.user.display_name

def test_user_info_authenticated_when_flag_off(self, authenticated_request):
authenticated_request.feature.flags['api_render_user_info'] = False
profile = session.profile(authenticated_request)
assert 'user_info' not in profile

def test_user_info_unauthenticated(self, unauthenticated_request):
profile = session.profile(unauthenticated_request)
assert 'user_info' not in profile
Expand Down

0 comments on commit cdc8391

Please sign in to comment.