Skip to content

Commit

Permalink
[ENG-4618] User Search metadata (#10428)
Browse files Browse the repository at this point in the history
* Add property to user
* Add allow_indexing field
  • Loading branch information
mfraezz committed Aug 16, 2023
1 parent 5b691c7 commit 73bf117
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class UserSerializer(JSONAPISerializer):
social = SocialField(required=False, min_version='2.10')
employment = JSONAPIListField(required=False, source='jobs')
education = JSONAPIListField(required=False, source='schools')
allow_indexing = ShowIfCurrentUser(ser.BooleanField(required=False, allow_null=True))
can_view_reviews = ShowIfCurrentUser(ser.SerializerMethodField(help_text='Whether the current user has the `view_submissions` permission to ANY reviews provider.'))
accepted_terms_of_service = ShowIfCurrentUser(ser.SerializerMethodField())

Expand Down
37 changes: 37 additions & 0 deletions api_tests/users/views/test_user_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,43 @@ def test_update_accepted_tos_false(
assert res.status_code == 200
assert user_one.accepted_terms_of_service is None

def test_update_allow_indexing_sets_field(
self, app, user_one, url_user_one):
assert user_one.allow_indexing is None
res = app.patch_json_api(
url_user_one,
{
'data': {
'id': user_one._id,
'type': 'users',
'attributes': {
'allow_indexing': True,
}
}
},
auth=user_one.auth
)
user_one.reload()
assert res.status_code == 200
assert user_one.allow_indexing is True
res = app.patch_json_api(
url_user_one,
{
'data': {
'id': user_one._id,
'type': 'users',
'attributes': {
'allow_indexing': False,
}
}
},
auth=user_one.auth
)
user_one.reload()
assert res.status_code == 200
assert user_one.allow_indexing is False


@pytest.mark.django_db
class TestDeactivatedUser:

Expand Down
18 changes: 18 additions & 0 deletions osf/migrations/0015_osfuser_allow_indexing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.17 on 2023-08-11 14:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('osf', '0014_institution_storage_regions'),
]

operations = [
migrations.AddField(
model_name='osfuser',
name='allow_indexing',
field=models.BooleanField(blank=True, default=None, null=True),
),
]
7 changes: 7 additions & 0 deletions osf/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class OSFUser(DirtyFieldsMixin, GuidMixin, BaseModel, AbstractBaseUser, Permissi
'jobs',
'schools',
'social',
'allow_indexing',
}

# Overrides DirtyFieldsMixin, Foreign Keys checked by '<attribute_name>_id' rather than typical name.
Expand Down Expand Up @@ -398,6 +399,8 @@ class OSFUser(DirtyFieldsMixin, GuidMixin, BaseModel, AbstractBaseUser, Permissi

chronos_user_id = models.TextField(null=True, blank=True, db_index=True)

allow_indexing = models.BooleanField(null=True, blank=True, default=None)

objects = OSFUserManager()

is_active = models.BooleanField(default=False)
Expand Down Expand Up @@ -454,6 +457,10 @@ def is_merged(self):
"""
return self.merged_by is not None

@property
def is_public(self):
return self.is_active and self.allow_indexing is not False

@property
def unconfirmed_emails(self):
# Handle when email_verifications field is None
Expand Down

0 comments on commit 73bf117

Please sign in to comment.