-
-
Notifications
You must be signed in to change notification settings - Fork 62
Feature/implement flask admin #403
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
Open
fumblehool
wants to merge
10
commits into
OperationCode:main
Choose a base branch
from
fumblehool:feature/implement-flask-admin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b9a11d2
implemented admin route using flask-admin
fumblehool 3e5e7ce
added authentication to admin route using flask-security
fumblehool 8b18885
added migrations for authentication
fumblehool c225b58
lint fixes
fumblehool 1be3dcb
create admin user before first request
fumblehool 6f1de51
fixed admin user generation
fumblehool 5536dc6
Merge branch 'main' of https://github.com/OperationCode/resources_api…
fumblehool aa80e29
added default values for secret_key and security_hash
fumblehool 61724f6
moved default secret_key and security_password to .env
fumblehool 4e05be8
Merge branch 'main' into feature/implement-flask-admin
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from flask_admin import Admin, AdminIndexView | ||
from flask_admin.contrib.sqla import ModelView | ||
from flask import url_for, redirect, request | ||
from app import db | ||
from .models import Resource, Category, Language, User, Role | ||
from flask_security import current_user | ||
|
||
|
||
class AdminView(ModelView): | ||
def is_accessible(self): | ||
return current_user.has_role("admin") | ||
|
||
def inaccessible_callback(self): | ||
return redirect(url_for("security.login", next=request.url)) | ||
|
||
|
||
class HomeAdminView(AdminIndexView): | ||
def is_accessible(self): | ||
return current_user.has_role("admin") | ||
|
||
def inaccessible_callback(self, name): | ||
return redirect(url_for("security.login", next=request.url)) | ||
|
||
|
||
def run_flask_admin(app): | ||
admin = Admin(app, name="Resources_api", url='/', | ||
index_view=HomeAdminView(name="Home")) | ||
admin.add_view(AdminView(Role, db.session)) | ||
admin.add_view(AdminView(User, db.session)) | ||
admin.add_view(AdminView(Resource, db.session)) | ||
admin.add_view(AdminView(Category, db.session)) | ||
admin.add_view(AdminView(Language, db.session)) | ||
return admin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends 'admin/master.html' %} | ||
|
||
{% block body %} | ||
<p>Admin Home Page</p> | ||
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""empty message | ||
|
||
Revision ID: 824f1576e904 | ||
Revises: 205742d3b3f5 | ||
Create Date: 2020-10-20 10:36:16.978231 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlalchemy_utils | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '824f1576e904' | ||
down_revision = 'fc34137ad3ba' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('role', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('name', sa.String(length=80), nullable=True), | ||
sa.Column('description', sa.String(length=255), nullable=True), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('user', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('email', sa.String(length=255), nullable=True), | ||
sa.Column('password', sa.String(length=255), nullable=True), | ||
sa.Column('active', sa.Boolean(), nullable=True), | ||
sa.Column('confirmed_at', sa.DateTime(), nullable=True), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('email') | ||
) | ||
op.create_table('roles_users', | ||
sa.Column('user_id', sa.Integer(), nullable=True), | ||
sa.Column('role_id', sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint(['role_id'], ['role.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ) | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('roles_users') | ||
op.drop_table('user') | ||
op.drop_table('role') | ||
# ### end Alembic commands ### |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.