Skip to content

Commit

Permalink
Fix user PUTs and make emails+passwords fully optional.
Browse files Browse the repository at this point in the history
No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner committed Aug 16, 2024
1 parent 6cd6512 commit daf5be3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
7 changes: 1 addition & 6 deletions galaxy_ng/app/api/ui_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Meta:
]

extra_kwargs = {
'password': {'write_only': True, 'required': True},
'password': {'write_only': True, 'required': False},
'email': {'required': False}
}

Expand All @@ -42,11 +42,6 @@ def get_teams(self, obj):
teams_serializer = TeamSerializer(teams, many=True)
return teams_serializer.data

def validate_email(self, value):
if not value:
raise serializers.ValidationError("Email is required")
return value

def create(self, validated_data):
user, _ = User.objects.get_or_create(
username=validated_data['username'],
Expand Down
42 changes: 42 additions & 0 deletions galaxy_ng/tests/integration/dab/test_ui_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,45 @@ def test_ui_v2_user_create(
ugc = GalaxyClient(gc.galaxy_root, auth=auth)
me_ds = ugc.get('_ui/v1/me/')
assert me_ds["username"] == random_username


@pytest.mark.deployment_standalone
def test_ui_v2_user_edit(
settings,
galaxy_client,
random_username,
):
"""Test user edit in ui/v2/users/."""

if settings.get('ALLOW_LOCAL_RESOURCE_MANAGEMENT') is False:
pytest.skip(reason="this only works local resource management enabled")

gc = galaxy_client("admin", ignore_cache=True)

user_payload = {
"username": random_username,
"first_name": "jim",
"last_name": "bob",
"password": "redhat1234"
}

# create the user in ui/v2 ...
user_data = gc.post(
"_ui/v2/users/",
body=json.dumps(user_payload)
)
uid = user_data['id']

# validate PUT/edit ...
user_data['last_name'] = 'newname'
changed_data = gc.put(
f"_ui/v2/users/{uid}/",
body=json.dumps(user_data)
)
assert changed_data == user_data

# validate login ...
auth = {'username': random_username, 'password': 'redhat1234'}
ugc = GalaxyClient(gc.galaxy_root, auth=auth)
me_ds = ugc.get('_ui/v1/me/')
assert me_ds["username"] == random_username

0 comments on commit daf5be3

Please sign in to comment.