Skip to content

Commit

Permalink
[AdminTL#93] Editor: fix generator editor button when error occur and…
Browse files Browse the repository at this point in the history
… refresh page

- add debug for javascript controler when receive data from http
  • Loading branch information
mathben committed Dec 2, 2018
1 parent b71c5fb commit 014cc1f
Show file tree
Hide file tree
Showing 29 changed files with 2,820 additions and 4,598 deletions.
310 changes: 0 additions & 310 deletions database/tl_lore.json

This file was deleted.

2,779 changes: 0 additions & 2,779 deletions database/tl_manual.json

This file was deleted.

5 changes: 2 additions & 3 deletions src/web/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
DB_DEFAULT_PATH = os.path.join(WEB_ROOT_DIR, "..", "..", "database", "tl_user.json")
DB_DEMO_PATH = os.path.join(WEB_ROOT_DIR, "..", "..", "database", "demo_user.json")
DB_MANUAL_PATH = os.path.join(WEB_ROOT_DIR, "..", "..", "database", "tl_manual.json")
DB_LORE_PATH = os.path.join(WEB_ROOT_DIR, "..", "..", "database", "tl_lore.json")
DB_AUTH_PATH = os.path.join(WEB_ROOT_DIR, "..", "..", "database", "auth.json")
GOOGLE_API_SECRET_PATH = os.path.join(WEB_ROOT_DIR, "..", "..", "database", "client_secret.json")
CONFIG_PATH = os.path.join(WEB_ROOT_DIR, "..", "..", "database", "config.json")
Expand Down Expand Up @@ -78,15 +77,15 @@ def parse_args():
help='Active to disable login module.')
group.add_argument('--disable_admin', default=False, action='store_true',
help='Active to disable admin module.')
group.add_argument('--disable_custom_css', default=False, action='store_true',
# TODO Force to disable this feature until it's improve
group.add_argument('--disable_custom_css', default=True, action='store_true',
help='Active to disable custom css module.')
group.add_argument('--hide_menu_login', default=False, action='store_true',
help='Active to hide login module from menu.')

_parser = parser.parse_args()
_parser.db_demo_path = DB_DEMO_PATH
_parser.db_manual_path = DB_MANUAL_PATH
_parser.db_lore_path = DB_LORE_PATH
_parser.db_auth_keys_path = DB_AUTH_PATH
_parser.db_google_API_path = GOOGLE_API_SECRET_PATH
_parser.db_config_path = CONFIG_PATH
Expand Down
2 changes: 0 additions & 2 deletions src/web/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
class BaseHandler(tornado.web.RequestHandler):
_debug = None
_manual = None
_lore = None
_db = None
_invalid_login = None
_redirect_http_to_https = None
Expand All @@ -22,7 +21,6 @@ def initialize(self, **kwargs):
self._debug = kwargs.get("debug")
self._db = kwargs.get("db")
self._manual = kwargs.get("manual")
self._lore = kwargs.get("lore")
self._invalid_login = self.get_argument("invalid",
default="disable_login" if kwargs.get("disable_login") else None)
self._redirect_http_to_https = kwargs.get("redirect_http_to_https")
Expand Down
3 changes: 2 additions & 1 deletion src/web/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"ngPrint": "master",
"components-font-awesome": "master",
"angular-qrcode": "master",
"jsSHA": "master"
"jsSHA": "master",
"angular-moment": "master"
}
}
96 changes: 84 additions & 12 deletions src/web/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,21 +578,35 @@ def post(self):
if not user and delete_user_by_id:
user = {"user_id": delete_user_by_id}

# admin when has admin permission, but not consider admin when updated by himself
updated_by_admin = self.is_permission_admin() and user.get("user_id") != self.current_user.get("user_id")

self._db.update_user(user, character, delete_user_by_id=delete_user_by_id,
delete_character_by_id=delete_character_by_id)
delete_character_by_id=delete_character_by_id, updated_by_admin=updated_by_admin)

self.write({"status": "success"})
self.finish()


class ManualHandler(jsonhandler.JsonHandler):
@tornado.web.asynchronous
def get(self):
self.write(self._manual.get_str_all())
str_value = self._manual.get_str_all(is_admin=False)
self.write(str_value)
self.finish()


class LoreHandler(jsonhandler.JsonHandler):
class ManualAdminHandler(jsonhandler.JsonHandler):
@tornado.web.asynchronous
def get(self):
self.write(self._lore.get_str_all())
if not self.is_permission_admin():
print("Insufficient permissions from %s" % self.request.remote_ip, file=sys.stderr)
# Forbidden
self.set_status(403)
self.send_error(403)
raise tornado.web.Finish()
str_value = self._manual.get_str_all(is_admin=True)
self.write(str_value)
self.finish()


Expand Down Expand Up @@ -754,19 +768,19 @@ def get(self):
file_url = self._doc_generator_gspread.get_url()
email_google_service = self._doc_generator_gspread.get_email_service()
is_auth = self._doc_generator_gspread.is_auth()
can_generate = bool(doc_generator and
not self._doc_generator_gspread.has_error() and
not doc_generator.has_error() and
has_access_perm and is_auth
)
can_generate = bool(doc_generator and has_access_perm and is_auth)

last_updated_date = self._manual.get_last_date_updated()
last_updated_date_for_js = last_updated_date * 1000

info = {
"file_url": file_url,
"is_auth": is_auth,
"user_has_writer_perm": has_user_writer_perm,
"has_access_perm": has_access_perm,
"email_google_service": email_google_service,
"can_generate": can_generate
"can_generate": can_generate,
"last_local_doc_update": last_updated_date_for_js
}

if self._doc_generator_gspread.has_error():
Expand Down Expand Up @@ -876,12 +890,47 @@ def post(self):
status = doc_generator.generate_doc()
if status:
document = doc_generator.get_generated_doc()
info = {}
if "manual" in document:
doc_part = document.get("manual")
self._manual.update({"manual": doc_part}, save=True)
info["manual"] = doc_part
# self._manual.update({"manual": doc_part}, save=True)
if "lore" in document:
doc_part = document.get("lore")
self._lore.update({"lore": doc_part}, save=True)
info["lore"] = doc_part
# self._manual.update({"lore": doc_part}, save=True)
if "schema_user" in document or "schema_char" in document or "form_user" in document \
or "form_char" in document or "admin_form_user" in document or "admin_form_char" in document:
dct_char_rule = {}
if "schema_user" in document:
doc_part = document.get("schema_user")
dct_char_rule["schema_user"] = doc_part
if "schema_char" in document:
doc_part = document.get("schema_char")
dct_char_rule["schema_char"] = doc_part
if "form_user" in document:
doc_part = document.get("form_user")
dct_char_rule["form_user"] = doc_part
if "form_char" in document:
doc_part = document.get("form_char")
dct_char_rule["form_char"] = doc_part
if "admin_form_user" in document:
doc_part = document.get("admin_form_user")
dct_char_rule["admin_form_user"] = doc_part
if "admin_form_char" in document:
doc_part = document.get("admin_form_char")
dct_char_rule["admin_form_char"] = doc_part

info["char_rule"] = dct_char_rule

info["point"] = document["point"]
info["skill_manual"] = document["skill_manual"]

# Link manual and form
info = self._manual.generate_link(info)

# Write to database
self._manual.update(info, save=True)
status = {"status": "Generated with success. Database updated."}
else:
status = doc_generator.get_error(force_error=True)
Expand All @@ -890,6 +939,29 @@ def post(self):
self.finish()


class CharacterApprobationHandler(jsonhandler.JsonHandler):
@tornado.web.asynchronous
@tornado.web.authenticated
def post(self):
if not self.is_permission_admin():
print("Insufficient permissions from %s" % self.request.remote_ip, file=sys.stderr)
# Forbidden
self.set_status(403)
self.send_error(403)
raise tornado.web.Finish()

self.prepare_json()

user_id = self.get_argument("user_id")
character_name = self.get_argument("character_name")
approbation_status = self.get_argument("approbation_status")

status = self._db.set_approbation(user_id, character_name, approbation_status)

self.write(status)
self.finish()


class StatSeasonPass(jsonhandler.JsonHandler):
@tornado.web.asynchronous
def get(self):
Expand Down
8 changes: 4 additions & 4 deletions src/web/partials/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{% end %}

{% if not disable_login and not disable_admin and current_user and current_user.get("permission") == "Admin" %}
<li ng-class="{ active: isActive('/admin') }"><a href="admin" style="color:red;"><span class="glyphicon glyphicon-king"></span> Admin</a></li>
<li ng-class="{ active: isActive('/admin') }"><a href="/admin" style="color:red;"><span class="glyphicon glyphicon-king"></span> Admin</a></li>
{% end %}

{% if not disable_login and (not hide_menu_login or current_user) %}
Expand Down Expand Up @@ -166,12 +166,12 @@ <h1 class="detect_javascript_enable">
<script src="{{ static_url('bower_components/jsSHA/src/sha256.js') }}"></script>
{% end %}

<script src="{{ static_url('bower_components/moment/moment.js') }}"></script>
<script src="{{ static_url('bower_components/angular-moment/angular-moment.js') }}"></script>

<script src="{{ static_url('resources/js/tool.js') }}"></script>
<script src="{{ static_url('resources/js/tl_module/tl_module.js') }}"></script>

<!-- add TL schema -->
<script src="{{ static_url('resources/js/tl_module/character_ctrl/tl_character_schema.js') }}"></script>

<!-- add controller -->
<script src="{{ static_url('bower_components/ngPrint/ngPrint.js') }}"></script>
<script src="{{ static_url('resources/js/tl_module/character_ctrl/character_ctrl.js') }}"></script>
Expand Down
6 changes: 3 additions & 3 deletions src/web/partials/admin/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ <h1 class="detect_javascript_enable">
<script src="{{ static_url('bower_components/jsSHA/src/sha256.js') }}"></script>
{% end %}

<script src="{{ static_url('bower_components/moment/moment.js') }}"></script>
<script src="{{ static_url('bower_components/angular-moment/angular-moment.js') }}"></script>

<script src="{{ static_url('resources/js/tool.js') }}"></script>
<script src="{{ static_url('resources/js/tl_module/tl_module.js') }}"></script>

<!-- add TL schema -->
<script src="{{ static_url('resources/js/tl_module/character_ctrl/tl_character_schema.js') }}"></script>

<!-- add controller -->
<script src="{{ static_url('bower_components/ngPrint/ngPrint.js') }}"></script>
<script src="{{ static_url('resources/js/tl_module/character_ctrl/character_ctrl.js') }}"></script>
Expand Down
Loading

0 comments on commit 014cc1f

Please sign in to comment.