Repository: fossasia/open-event-server

Issue:
Unable to update the user info via patch request.
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
I am trying to update the user info of 'email', 'phone' by sending a patch request at 'https://open-event-api.herokuapp.com/users/<user_id>' but it's giving me 'Unknown error'. I also tried to send it by postman with the same access token so that I can override the info, still I am getting the same error. Following are the screenshots:
![patch](https://user-images.githubusercontent.com/17925669/28453862-972563a4-6e16-11e7-889d-236cb472be84.png)
![patch2](https://user-images.githubusercontent.com/17925669/28453867-9976d994-6e16-11e7-9f82-b17d8c3f7aec.png)
![patch3](https://user-images.githubusercontent.com/17925669/28453912-d21cc7cc-6e16-11e7-83ae-e3040c7c898d.png)

URL: https://open-event-api.herokuapp.com/v1/users/110
Request headers: 
```
Content-Type: application/vnd.api+json
Authorization: JWT <Auth Key>
```
Response:
```
{
    "errors": [
        {
            "detail": "Unknown error",
            "source": {
                "pointer": ""
            },
            "status": 500,
            "title": "Unknown error"
        }
    ],
    "jsonapi": {
        "version": "1.0"
    }
}
```
Status code: 500


Discussion:
Don't include email in the patch body.
@enigmaeth email is editable. 
@niranjan94 Currently, editing email through PATCH requests throws an error. ( [user model](https://github.com/fossasia/open-event-orga-server/blob/nextgen/app/models/user.py#L112) ). Should this be changed to make email editable?

@enigmaeth Removing email from the request body gives correct response.
Yes, that is because email is not editable currently. @niranjan94 Should it be allowed to be editable?
@shubham-padia @niranjan94 ^^?
Yes. It should be allowed. We had the feature in vintage. 
@enigmaeth Let me know once you do the changes.
@niranjan94 Actually in user model the attribute "email" is defined as getter & setter while setter only sets the value if it null so only works on creating new user. This method is there from vintage.
@poush actually, this was done when the API was first implemented (I even remember reviewing the PR that had the change. I forgot at the time that we need to have the ability to change email address.). [Not from vintage](https://github.com/fossasia/open-event-orga-server/blob/development/app/models/user.py). We had the ability to change email address before. And we should have the ability now too.

Resolving patch:
diff --git a/app/models/user.py b/app/models/user.py
--- a/app/models/user.py
+++ b/app/models/user.py
@@ -106,10 +106,8 @@ def email(self, email):
         :param email:
         :return:
         """
-        if self._email is None:
-            self._email = email
-        else:
-            raise AttributeError("Email cannot be modified")
+        self._email = email
+        self.is_verified = False
 
     # User Permissions
     def can_publish_event(self):


Test patch: