Validate URLs of social handles in accounts
- Dominant language
- Python
- Stars
- 2k
- Forks
- 984
- Avg merge
- 2h 54m
- Merged PRs (30d)
- 14
Description
**Description**
The [Profile](https://github.com/Cloud-CV/EvalAI/blob/master/apps/accounts/models.py) model in the `accounts` app has the following attributes to store the profile of a user: user, contact_number, affiliation, receive_participated_challenge_updates, receive_newsletter, github_url, google_scholar_url, linked_url. It would be nice to have validated GitHub, Google Scholar, and LinkedIn URLs to avoid any kind of discrepancies.
**Problem**
The current behavior of `github_url`, `google_scholar_url`, and `linked_url` might take into account any random URL which should not be the case ideally. Here's the reference to the [field](https://github.com/Cloud-CV/EvalAI/blob/master/apps/accounts/models.py#L47).
**Fix**
To have a foolproof path, I propose adding proper validation in the required model attribute. A simple solution might be to modify the `github_url` in the following way:
```
github_url = models.URLField(max_length=200, null=True, blank=True, validators=[validate_github_url])
```
```
def validate_github_url(value):
if not value:
return
obj = urlparse(value)
if not obj.hostname in ("github.com"):
raise ValidationError(f"Only URLs from GitHub are allowed")
```
P.S. The same can be extended to `web` app as well. [Link](https://github.com/Cloud-CV/EvalAI/blob/master/apps/web/models.py#L58)
Contributor guide
Assessment
This issue has not been assessed yet.