Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed update_entity to update_token #117

Merged
merged 5 commits into from Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,4 +4,8 @@

### Changed

- Replaced the the `entity_type` kwarg to `table_name` in the public method `register_entity` [Issue #111](https://github.com/joegasewicz/Flask-JWT-Router/issues/111)
- Replaced the the `entity_type` kwarg to `table_name` in the public method `register_entity` [Issue #111](https://github.com/joegasewicz/Flask-JWT-Router/issues/111)

- Renamed the `update_entity` public method to be called `update_token` [Issue #114](https://github.com/joegasewicz/Flask-JWT-Router/issues/114)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove spaces after list items

- Renamed the `register_entity` public method to be called `create_token` [Issue #113](https://github.com/joegasewicz/Flask-JWT-Router/issues/113)
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -110,7 +110,7 @@ def register():
def login():
"""I'm authorized & updating my token!"""
return jsonify({
"token": jwt_routes.update_entity(entity_id=1)
"token": jwt_routes.update_token(entity_id=1)
})
```

Expand Down Expand Up @@ -157,13 +157,13 @@ Access entity on Flask's global context
}, 401
return {
"data": user_dumped,
"token": jwt_routes.update_entity(entity_id=user_data.id),
"token": jwt_routes.update_token(entity_id=user_data.id),
}, 200

```
If you are handling a request with a token in the headers you can call::
```python
jwt_routes.update_entity(entity_id=user_data.id)
jwt_routes.update_token(entity_id=user_data.id)
```

If you are handling a request without a token in the headers you can call::
Expand Down
16 changes: 8 additions & 8 deletions flask_jwt_router/_authentication.py
Expand Up @@ -12,7 +12,7 @@ def encode_token(self, extensions: Config, **kwargs):
def register_entity(self):
pass

def update_entity(self):
def update_token(self):
pass

"""
Expand All @@ -34,7 +34,7 @@ def register_entity(self, extensions: Config, exp: int, **kwargs):
pass

@abstractmethod
def update_entity(self, extensions: Config, exp: int, table_name, **kwarg):
def update_token(self, extensions: Config, exp: int, table_name, **kwarg):
# pylint:disable=missing-function-docstring
pass

Expand Down Expand Up @@ -95,12 +95,12 @@ def register_entity(self, extensions: Config, exp: int, **kwargs) -> str:
table_name = kwargs.get("table_name", None)
return self.encode_token(extensions, self.entity_id, exp, table_name)

def update_entity(self,
extensions: Config,
exp: int,
table_name: str,
**kwargs,
) -> str:
def update_token(self,
extensions: Config,
exp: int,
table_name: str,
**kwargs,
) -> str:
"""
:param extensions:
:param exp:
Expand Down
2 changes: 1 addition & 1 deletion flask_jwt_router/_entity.py
Expand Up @@ -80,7 +80,7 @@ def get_entity_from_ext(self, table_name: str = None) -> _ORMType:
:return: {_ORMType}
"""
if not table_name:
# In case `update_entity()` is called, `table_name` is in the token
# In case `update_token()` is called, `table_name` is in the token
table_name = self.decoded_token.get("table_name")
auth_model = None

Expand Down
4 changes: 2 additions & 2 deletions flask_jwt_router/_jwt_router.py
Expand Up @@ -114,14 +114,14 @@ def register_entity(self, **kwargs) -> str:
self.extensions.entity_key = self.entity.get_attr_name(table_name)
return self.auth.register_entity(self.extensions, self.exp, **kwargs)

def update_entity(self, **kwargs) -> str:
def update_token(self, **kwargs) -> str:
"""
:param kwargs:
:return: str
"""
self.extensions.entity_key = self.entity.get_attr_name()
table_name = self.entity.get_entity_from_ext().__tablename__
return self.auth.update_entity(self.extensions, self.exp, table_name, **kwargs)
return self.auth.update_token(self.extensions, self.exp, table_name, **kwargs)

def encode_token(self, entity_id) -> str:
"""
Expand Down
4 changes: 2 additions & 2 deletions flask_jwt_router/_jwt_routes.py
Expand Up @@ -99,7 +99,7 @@ def register():
def login():
# I'm authorized & updating my token!
return jsonify({
"token": jwt_routes.update_entity(entity_id=1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can install Sphinx & run the following:

make html

I will update the Pipfile to add Sphinx as a dev dep in my Pr either today or tomorrow, thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I'll try and give it a go!

"token": jwt_routes.update_token(entity_id=1)
})

Create a new entity & return a new token::
Expand Down Expand Up @@ -142,7 +142,7 @@ def login():

If you are handling a request with a token in the headers you can call::

jwt_routes.update_entity(entity_id=user_data.id)
jwt_routes.update_token(entity_id=user_data.id)

If you are handling a request without a token in the headers you can call::

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/main_fixture.py
Expand Up @@ -51,7 +51,7 @@ def test_entity():

@flask_app.route("/api/v1/test_entity", methods=["GET"])
def test_entity_two():
token = jwt_routes.update_entity(entity_id=1)
token = jwt_routes.update_token(entity_id=1)
return jsonify({
"token": token,
"data": {
Expand Down