-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New: expose menu data as serializable objects #1116
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1116 +/- ##
==========================================
+ Coverage 68.71% 68.83% +0.12%
==========================================
Files 45 45
Lines 6223 6248 +25
==========================================
+ Hits 4276 4301 +25
Misses 1947 1947
Continue to review full report at Codecov.
|
8566d2e to
a97e6ca
Compare
flask_appbuilder/tests/test_menu.py
Outdated
| sess = PSSession() | ||
|
|
||
| class PSView(ModelView): | ||
| datamodel = GenericInterface(PSModel, sess) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed
flask_appbuilder/tests/test_menu.py
Outdated
| rv = client.get(uri) | ||
| eq_(rv.status_code, 200) | ||
| data = rv.data.decode('utf-8') | ||
| eq_(data, '{"data":[]}\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use assertEqual I'm changing everything on another PR
955537b to
53bee68
Compare
flask_appbuilder/menu.py
Outdated
| class MenuApi(BaseApi): | ||
| resource_name = "menu" | ||
|
|
||
| @expose('/data', methods=["GET"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer just GET /api/v1/menu
flask_appbuilder/menu.py
Outdated
| - label | ||
| - icon | ||
| """ | ||
| return self.response(200, data=current_app.appbuilder.menu.get_data()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently FAB uses result key instead of data
| $ref: \ | ||
| '#/paths/menu/data/get/reponses/200/content/application/json/schema/properties/result' | ||
| required: | ||
| - name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name and url are required. label, icon are optional
| class MenuApi(BaseApi): | ||
| resource_name = "menu" | ||
|
|
||
| @expose('/', methods=["GET"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public endpoint, is this intentional? it really does not return any data when no user is authenticated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it returns an empty array, currently. However if a user decides to expose a menu for the public role we'd still want to serve that [limited] menu, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, yet we do have a public role for this. It's actually a decision between exposing an unauthenticated EP that anonymously return an empty list, or exposing an authenticated EP that returns 401
flask_appbuilder/menu.py
Outdated
|
|
||
| class MenuApiManager(BaseManager): | ||
| def register_views(self): | ||
| self.appbuilder.add_api(MenuApi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create a new option key for this, take a look at: https://github.com/dpgaspar/Flask-AppBuilder/blob/master/flask_appbuilder/security/manager.py#L581
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean expose a config to enable/disable this endpoint? something like FAB_EXPOSE_MENU_API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
2eb41a2 to
baf06c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, sorry Tai just merged a big change on tests that created some conflicts here, I've created a branch named preset-io-tai/expose-menu on FAB that resolves them, take a look a that
baf06c8 to
e6e103e
Compare
a67f551 to
606c2c9
Compare
exposes a method on the menu class to output the menu as list of dictionaries that can be converted to json.