-
Notifications
You must be signed in to change notification settings - Fork 52
Features Icons in features panel #284
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
LiranCaduri
wants to merge
172
commits into
PythonFreeCourse:develop
Choose a base branch
from
LiranCaduri:feature/feature-icon
base: develop
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 32 commits
Commits
Show all changes
172 commits
Select commit
Hold shift + click to select a range
f6c619b
Hello Wrold
aviadamar 1ee94e4
Creating Html Template
aviadamar 96b80de
First Calendar Monthly View - HTML\CSS only
aviadamar 4614585
Merge branch 'main' of https://github.com/PythonFreeCourse/calendar i…
aviadamar 82249b5
Calendar dates calculation intigrating with html, HTML\CSS improvments.
aviadamar d2208d6
Merge branch 'main' of https://github.com/PythonFreeCourse/calendar i…
aviadamar 178e904
Tests for calender_grid.py, changing function according to currection…
aviadamar f385c56
linting bug fixing
aviadamar c2aa519
before merge with develop
aviadamar 3a563cc
after merge with develop
aviadamar 6f9a2ba
Creating a Day object and days subclasses, changing all function and …
aviadamar a17e89b
Fixing Conflicts
aviadamar 75abb99
fix lintings
aviadamar d2577aa
fix lintings
aviadamar e76ed53
tests next week scroll
aviadamar 19768ca
js updates
aviadamar b288c49
Calendar Scrolling with javascript
aviadamar 5621485
Calendar infinit scrolling and functions changes, bus fixing
aviadamar 10b836c
Fix lintings
aviadamar 43dd46e
Fix lintings
aviadamar 248a0ba
Calendar infinit scrolling ducplicates weeks bug fixed
aviadamar 59b7fe3
seetings global parameters for calendar.py
aviadamar efa6b2d
Js - changing to fetch, removing jquery, fixing hint tpying, adding W…
aviadamar 1df4cd5
Front end bug fixing
aviadamar 2e02b65
Fix linting
aviadamar e02bd14
Fix lintings
aviadamar 2271a3c
Fix lintings
aviadamar 126c92e
gixing js bugs
aviadamar 8af556c
fixing syntax
aviadamar bc3322f
Get user local date and time when enter calendar.
aviadamar a60c7c8
Fix lintings
aviadamar 60849ab
bug fixging and pull develop update
aviadamar b8e6044
Fix lintings
aviadamar 0b601e2
Fix lintings
aviadamar 9ca2183
Bugs fixing
aviadamar 79b2f5c
Bugs fixing
aviadamar e4c662d
Js fixing bugs and syntext.
aviadamar 03e4349
Bugs fixing
aviadamar 982daea
Bugs fixing
aviadamar 19de078
JS alerts removal
aviadamar b97279f
Fix Lintings
aviadamar 6516f7c
Js syntext fixing
aviadamar d496b07
Bugs fixing
aviadamar 41b7bd4
Bugs fixing
aviadamar 66d8972
Js fixing varibales and adding div element to request.
aviadamar d09b5fd
add models to db
LiranCaduri 4f54e25
Js global parameters fixing
aviadamar 013c6d5
figure out delete.
LiranCaduri f0bd6ac
Develop update
aviadamar b9a0c0b
Develop Update
aviadamar 894f234
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 5cbf776
Js - eliminate global parameters
aviadamar 901f88f
Linting fixing
aviadamar 445a962
Fix Lintings
aviadamar dd0f480
Js fixings
aviadamar 1e8e206
Fix flake8
aviadamar 85d904f
syntac fixing
aviadamar cb7947c
first structure of route with middlewere
LiranCaduri 30df427
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
aviadamar d39d7e7
Js html\body duplication bug fix
aviadamar b44c386
Js extra div bug fix
aviadamar 3ee9bd3
Js scrolling duplication days fixed
aviadamar f214d22
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
aviadamar 3334824
month scrolling navigation
aviadamar 523c01e
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 158ecb0
CSS vars
aviadamar 572036e
try middleware
LiranCaduri 9be7f08
backup before pull
aviadamar 397cee3
add middleware filtering requests
LiranCaduri 1da1dda
add: get_user_disabled_features and get_user_enabled_features
LiranCaduri d160605
modify middleware
LiranCaduri b51cd21
replace testclient, add on startup event, feature folder, is_feature_…
LiranCaduri 9df777b
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri e4a817a
improved is_feature_enabled and middleware code.
LiranCaduri 0514121
add_feature_to_user function
LiranCaduri 645e586
month navigation WIP
aviadamar 70aea36
update develop
aviadamar b961da4
JS: Month navigation bar
aviadamar 809b727
css fix
aviadamar 03930c9
Month Navigations and CSS changes
aviadamar e54b172
Fix lintings
aviadamar 0f71c68
Scroll back bug fixed
aviadamar c715299
add checking for duplicates in association table
LiranCaduri 6380a8c
renaming some files, and adding on and off routes
LiranCaduri 7f50cc0
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 2ea61cb
.example
LiranCaduri a11e846
style/features init settings
aviadamar d629496
features wip 14/02
aviadamar b2b839f
split to internal
LiranCaduri 36af9b7
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 8c4929c
add config
LiranCaduri b999bc6
add tests
LiranCaduri 7d0cbc0
feature icon backend first
LiranCaduri 647af4b
Features wip 15.02.21
aviadamar 685b30e
feature search
aviadamar e97f29b
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 6220ad0
access decorator, back to fastapi testclient, fix tests, new document…
LiranCaduri f6a6630
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 0b27713
fix flake8 issue
LiranCaduri 416211a
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 9cb181a
fix tests, after apdate
LiranCaduri 2572153
requested changes
LiranCaduri 10c7d88
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 7f0ab27
.example
LiranCaduri d097501
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 62a0295
before pull 18.02.21
aviadamar e2eeecc
after pull 18.02.21
aviadamar 1c1bbe7
requested changes
LiranCaduri a8e8725
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 0109771
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 4eeaeea
Before changit to fetch
aviadamar dfe02c7
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 2081329
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 107d246
changes
LiranCaduri 11c1727
after pull 21.02.21
aviadamar ea84de5
Before Passing to Liran
aviadamar bf7fae9
Before passing to Liran
aviadamar 182b6be
before cache
LiranCaduri 5738b16
Merge branch 'style/features' of https://github.com/LiranCaduri/calen…
LiranCaduri 652c155
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri f9145c8
adjusted to front
LiranCaduri 21bbe87
add followers, add tests, add front
LiranCaduri f74690a
fix flake8 issue
LiranCaduri d6b26a8
remove redundant things
LiranCaduri 4618b06
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 83668d3
Information on click fixed, Followers managment added
aviadamar 750d8fa
fix feature followers front update
LiranCaduri c4f6cbe
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 3c88d35
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 096d6fa
remove redundant things
LiranCaduri 322b96a
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 4696df2
pre-commit change some stuff
LiranCaduri 105d253
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri dc9fcce
remove blank lines
LiranCaduri 6bd5e03
First scrolling bug fixed
aviadamar 58664fb
after pull and bug fix
aviadamar 32cb480
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 05ea3be
Merge branch 'style/features' of https://github.com/LiranCaduri/calen…
LiranCaduri 1ce0099
fix error
LiranCaduri d677ccd
requested changes
LiranCaduri 7712b07
update .gitignore
LiranCaduri ecd5cb8
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri a9f9001
fix semantics
LiranCaduri 0cd1f49
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 172a1da
fix tests
LiranCaduri 04c48a5
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 5b92634
fix logic
LiranCaduri 572e992
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 571fe1a
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 2349b2b
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 36f841b
requested changes
LiranCaduri c181946
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 93b0b02
use pre-commit on google-connect
LiranCaduri 28a4558
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 144ff0e
fix features back
LiranCaduri 3bd43b2
requested changes
LiranCaduri 69ed31b
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri e0b121b
Merge branch 'feature/feature-panel' of https://github.com/LiranCadur…
LiranCaduri 9fde7a3
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 37ad833
remove redundant things
LiranCaduri bb3b52f
fix flake8
LiranCaduri 7f1e119
fixes
LiranCaduri f6d3ce0
more fixes
LiranCaduri fd89e01
more fixes
LiranCaduri e94cf66
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri eec1b94
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 4777fab
get this
LiranCaduri fee36d2
fix front
LiranCaduri b77f5e7
fix notifcation test error
LiranCaduri 7d9b949
template column and fixes
LiranCaduri b9d0f44
fix flake8
LiranCaduri 5b78d16
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
LiranCaduri 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
Empty file.
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,86 @@ | ||
''' | ||
This file purpose is for developers to add their features to the database | ||
in one convenient place, every time the system loads up it's adding and | ||
updating the features in the features table in the database. | ||
|
||
To update a feature, The developer needs to change the name or the route | ||
and let the system load, but not change both at the same time otherwise | ||
it will create junk and unnecessary duplicates. | ||
|
||
* IMPORTANT - To enable features panel functionlity the developer must * | ||
* add the feature_access_filter decorator to ALL the feature routes * | ||
* Please see the example below. * | ||
|
||
Enjoy and good luck :) | ||
''' | ||
|
||
''' | ||
All icons come from https://ionicons.com/. | ||
|
||
If you want your feature to have an icon Go To: https://ionicons.com/ | ||
and follow the next steps: | ||
|
||
1. pick an icon and press on it, copy the name. | ||
2. create dict in the icons list below. | ||
3. copy and paste your feature name and your | ||
icon name you copied earlier (follow the example). | ||
|
||
4. And You Are Done. the icon will show automaticly. | ||
|
||
If you dont pick an icon your feature will have a default icon. | ||
|
||
Example to feature icon stracture: | ||
|
||
{ | ||
. | ||
. | ||
. | ||
"<feature name>": "<icon name>", | ||
. | ||
. | ||
. | ||
} | ||
''' | ||
|
||
# Add to last! | ||
icons = { | ||
"feature-panel": "albums-outline", | ||
"Google Sync": "sync-outline" | ||
} | ||
|
||
|
||
''' | ||
Example to feature stracture: | ||
|
||
{ | ||
"name": "<feature name - str>", | ||
"route": "/<the route like: /features - str>", | ||
"description": "<description - str>", | ||
"creator": "<creator name or nickname - str>" | ||
} | ||
''' | ||
|
||
''' | ||
* IMPORTANT * | ||
|
||
Example to decorator placement: | ||
|
||
@router.get("/<my-route>") | ||
@feature_access_filter <---- just above def keyword! | ||
def my_cool_feature_route(): | ||
.... | ||
... | ||
some code. | ||
.. | ||
. | ||
|
||
''' | ||
|
||
features = [ | ||
{ | ||
"name": "Google Sync", | ||
"route": "/google/sync", | ||
"description": "Sync Google Calendar events with Pylender", | ||
"creator": "Liran Caduri" | ||
}, | ||
] |
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,34 @@ | ||
from functools import wraps | ||
from starlette.responses import RedirectResponse | ||
|
||
from app.internal.features import is_feature_enabled | ||
|
||
|
||
def feature_access_filter(call_next): | ||
|
||
@wraps(call_next) | ||
async def wrapper(*args, **kwargs): | ||
request = kwargs['request'] | ||
|
||
if request.headers['user-agent'] == 'testclient': | ||
# in case it's a unit test. | ||
return await call_next(*args, **kwargs) | ||
|
||
# getting the url route path for matching with the database. | ||
route = '/' + str(request.url).replace(str(request.base_url), '') | ||
|
||
# getting access status. | ||
is_enabled = is_feature_enabled(route=route) | ||
|
||
if is_enabled: | ||
# in case the feature is enabled or access is allowed. | ||
return await call_next(*args, **kwargs) | ||
|
||
elif 'referer' not in request.headers: | ||
# in case request come straight from address bar in browser. | ||
return RedirectResponse(url='/') | ||
|
||
# in case the feature is disabled or access isn't allowed. | ||
return RedirectResponse(url=request.headers['referer']) | ||
|
||
return wrapper |
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,167 @@ | ||
from fastapi import Depends | ||
|
||
from app.database.models import UserFeature, Feature | ||
from app.dependencies import get_db, SessionLocal | ||
from app.features.index import features, icons | ||
from app.internal.utils import create_model, get_current_user | ||
|
||
|
||
def create_features_at_startup(session: SessionLocal) -> bool: | ||
for feat in features: | ||
if not is_feature_exists_in_db(feature=feat, session=session): | ||
icon = icons.get(feat['name']) | ||
create_feature(**feat, icon=icon, db=session) | ||
|
||
return True | ||
|
||
|
||
def is_association_exists_in_db(form: dict, session: SessionLocal) -> bool: | ||
db_association = session.query(UserFeature).filter_by( | ||
feature_id=form['feature_id'], | ||
user_id=form['user_id'] | ||
).first() | ||
|
||
return db_association is not None | ||
|
||
|
||
def delete_feature( | ||
feature: Feature, session: SessionLocal = Depends(get_db) | ||
) -> None: | ||
session.query(UserFeature).filter_by(feature_id=feature.id).delete() | ||
session.query(Feature).filter_by(id=feature.id).delete() | ||
session.commit() | ||
|
||
|
||
def is_feature_exists_in_db(feature: dict, session: SessionLocal) -> bool: | ||
db_feature = session.query(Feature).filter( | ||
(Feature.name == feature['name']) | | ||
(Feature.route == feature['route'])).first() | ||
|
||
if db_feature is None: | ||
return False | ||
|
||
# Update if found | ||
update_feature( | ||
feature=db_feature, new_feature_obj=feature, session=session) | ||
return True | ||
|
||
|
||
def update_feature(feature: Feature, new_feature_obj: dict, | ||
LiranCaduri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
session: SessionLocal = Depends(get_db)) -> Feature: | ||
feature.name = new_feature_obj['name'] | ||
feature.route = new_feature_obj['route'] | ||
feature.description = new_feature_obj['description'] | ||
feature.creator = new_feature_obj['creator'] | ||
|
||
icon = icons.get(feature.name) | ||
if icon is None: | ||
icon = "extension-puzzle" | ||
|
||
feature.icon = icon | ||
session.commit() | ||
|
||
return feature | ||
|
||
|
||
def is_feature_exists_in_enabled( | ||
feature: Feature, session: SessionLocal = Depends(get_db) | ||
) -> bool: | ||
enabled_features = get_user_enabled_features(session=session) | ||
return any(ef['feature'].id == feature.id for ef in enabled_features) | ||
|
||
|
||
def is_feature_exists_in_disabled( | ||
feature: Feature, session: SessionLocal = Depends(get_db) | ||
) -> bool: | ||
disable_features = get_user_disabled_features(session=session) | ||
return any(ef['feature'].id == feature.id for ef in disable_features) | ||
|
||
|
||
def is_feature_enabled(route: str) -> bool: | ||
session = SessionLocal() | ||
|
||
user = get_current_user(session=session) | ||
|
||
feature = session.query(Feature).filter_by(route=route).first() | ||
|
||
# *This condition must be before line 168 to avoid AttributeError!* | ||
LiranCaduri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if feature is None: | ||
# in case there is no feature exists in the database that match the | ||
# route that gived by to the request. | ||
return True | ||
|
||
user_pref = session.query(UserFeature).filter_by( | ||
feature_id=feature.id, | ||
user_id=user.id | ||
).first() | ||
|
||
return user_pref is not None and user_pref.is_enable | ||
|
||
|
||
def create_feature(name: str, route: str, | ||
description: str, | ||
creator: str = None, | ||
icon: str = None, | ||
db: SessionLocal = Depends()) -> Feature: | ||
"""Creates a feature.""" | ||
|
||
db = SessionLocal() | ||
|
||
if icon is None: | ||
icon = "extension-puzzle" | ||
|
||
feature = create_model( | ||
db, Feature, | ||
name=name, | ||
route=route, | ||
creator=creator, | ||
description=description, | ||
icon=icon | ||
) | ||
return feature | ||
|
||
|
||
def create_association( | ||
db: SessionLocal, feature_id: int, user_id: int, is_enable: bool | ||
) -> UserFeature: | ||
"""Creates an association.""" | ||
|
||
association = create_model( | ||
db, UserFeature, | ||
user_id=user_id, | ||
feature_id=feature_id, | ||
is_enable=is_enable | ||
) | ||
|
||
return association | ||
|
||
|
||
def get_user_enabled_features(session: SessionLocal = Depends(get_db)) -> list: | ||
user = get_current_user(session=session) | ||
|
||
data = [] | ||
|
||
user_prefs = session.query(UserFeature).filter_by(user_id=user.id).all() | ||
for pref in user_prefs: | ||
if pref.is_enable: | ||
feature = session.query(Feature).filter_by( | ||
id=pref.feature_id).first() | ||
data.append({'feature': feature, 'is_enabled': pref.is_enable}) | ||
|
||
return data | ||
|
||
|
||
def get_user_disabled_features( | ||
session: SessionLocal = Depends(get_db) | ||
) -> list: | ||
user = get_current_user(session=session) | ||
|
||
data = [] | ||
user_prefs = session.query(UserFeature).filter_by(user_id=user.id).all() | ||
for pref in user_prefs: | ||
if not pref.is_enable: | ||
feature = session.query(Feature).filter_by( | ||
id=pref.feature_id).first() | ||
data.append({'feature': feature, 'is_enabled': pref.is_enable}) | ||
|
||
return data |
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
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.