Repository: fossasia/open-event-server

Issue:
Make Users API follow proper json spec
- attribute names must be hyphen separated. should be `is-verified` instead of `is_verified`
- ~default sort should be ascending. (`?sort=name`). Currently it seems to be descending ([spec](http://jsonapi.org/format/#fetching-sorting))~
- Hybrid properties throw error in sorting.

The rest seem to work nice. Haven't tested relationships yet since we don't have any 


Discussion:
@niranjan94 Can you please recheck `default sort should be ascending. (?sort=name). Currently it seems to be descending` once, seems to be ascending for me.
Okay. Ignore my comment. It is in ascending. Me blind 😋 
There's also another bug, Hybrid properties throw error in sorting, looking into it.
`attribute names must be hyphen separated. should be is-verified instead of is_verified`, how much of a blocker is this ? `flask-rest-jsonapi` doesn't play well with hyphens.
Hmm... Okay. This can be compensated for in client side. But just
curious... What issue does the lib have with hyphen separated attribute
names?

On Mon, May 29, 2017, 1:20 PM Shubham Padia <notifications@github.com>
wrote:

> attribute names must be hyphen separated. should be is-verified instead of
> is_verified, how much of a blocker is this ? flask-rest-jsonapi doesn't
> play well with hyphens.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-orga-server/issues/3682#issuecomment-304596466>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ACSwFIZ4FdfPbtAcp2Klpya8d4EpZu8Nks5r-njVgaJpZM4Nos1O>
> .
>

@niranjan94 As variables can't have hyphens, marshmallow provides http://marshmallow.readthedocs.io/en/latest/api_reference.html#module-marshmallow.fields, load_from and dump_to, but weirdly flask-rest-jsonapi doesn't respect them at some places. If I give a query with `?sort=created-at` it interprets the sorting param as `createdat` and throws an error.
Hmm... Okay... Weird. Cool. This shouldn't be a big blocker. Can be
corrected in the client side pretty easily. Will confirm though.

On Mon, May 29, 2017, 1:42 PM Shubham Padia <notifications@github.com>
wrote:

> @niranjan94 <https://github.com/niranjan94> As variables can't have
> hyphens, marshmallow provides
> http://marshmallow.readthedocs.io/en/latest/api_reference.html#module-marshmallow.fields,
> load_from and dump_to, but weirdly flask-rest-jsonapi doesn't respect them
> at some places. If I give a query with ?sort=created-at it interprets the
> sorting param as createdat and throws an error.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-orga-server/issues/3682#issuecomment-304600787>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ACSwFNMVrznvfOnKR6UO3heo54mkV83fks5r-n38gaJpZM4Nos1O>
> .
>


Resolving patch:
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -18,13 +18,13 @@ class Meta:
     email = fields.Email(required=True)
     password = fields.Str(required=True, load_only=True)
     avatar = fields.Str()
-    is_super_admin = fields.Boolean()
-    is_admin = fields.Boolean()
-    is_verified = fields.Boolean()
-    signup_at = fields.DateTime()
-    last_accessed_at = fields.DateTime()
-    created_at = fields.DateTime()
-    deleted_at = fields.DateTime()
+    is_super_admin = fields.Boolean(dump_only=True)
+    is_admin = fields.Boolean(dump_only=True)
+    is_verified = fields.Boolean(dump_only=True)
+    signup_at = fields.DateTime(dump_only=True)
+    last_accessed_at = fields.DateTime(dump_only=True)
+    created_at = fields.DateTime(dump_only=True)
+    deleted_at = fields.DateTime(dump_only=True)
     firstname = fields.Str()
     lastname = fields.Str()
     details = fields.Str()


Test patch: