Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #11 from RaenonX/dev
Browse files Browse the repository at this point in the history
Pre-webhook release
- Added beta/stable release time in About page.
  • Loading branch information
RaenonX authored Sep 7, 2019
2 parents 57f0a65 + b49e135 commit 15c5429
Show file tree
Hide file tree
Showing 78 changed files with 1,135 additions and 13,635 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
.idea/
__pycache__/
lib/
node_modules/
staticfiles/
*.bat
17 changes: 17 additions & 0 deletions JellyBotAPI/api/id/perm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from JellyBotAPI.api.static import param
from JellyBotAPI.api.responses import (
PermissionQueryResponse
)
from JellyBotAPI.components.mixin import CsrfExemptMixin, CheckParameterMixin, APIStatisticsCollectMixin
from JellyBotAPI.components.views import APIJsonResponseView
from flags import APICommand


class PermissionQueryView(CsrfExemptMixin, APIStatisticsCollectMixin, CheckParameterMixin, APIJsonResponseView):
get_response_class = PermissionQueryResponse

def get_api_action(self):
return APICommand.DATA_PERMISSION

def mandatory_keys(self) -> set:
return {param.Manage.Channel.CHANNEL_OID}
4 changes: 3 additions & 1 deletion JellyBotAPI/api/id/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.urls import path

from .channel import ChannelDataQueryView, ChannelIssueRegistrationTokenView, ChannelNameChangeView
from .perm import PermissionQueryView

urlpatterns = [
path('ch/data', ChannelDataQueryView.as_view(), name='api.id.channel.data'),
path('ch/reg/issue', ChannelIssueRegistrationTokenView.as_view(), name='api.id.channel.register_token'),
path('ch/name-change', ChannelNameChangeView.as_view(), name='api.id.channel.name_change')
path('ch/name-change', ChannelNameChangeView.as_view(), name='api.id.channel.name_change'),
path('perm', PermissionQueryView.as_view(), name='api.id.perm')
]
4 changes: 3 additions & 1 deletion JellyBotAPI/api/responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
AutoReplyAddResponse, AutoReplyAddTokenActionResponse, ContentValidationResponse,
AutoReplyTagPopularityResponse
)
from .id import ChannelDataQueryResponse, ChannelIssueRegisterTokenResponse, ChannelNameChangeResponse
from .id import (
ChannelDataQueryResponse, ChannelIssueRegisterTokenResponse, ChannelNameChangeResponse, PermissionQueryResponse
)
from .tkact import TokenActionCompleteApiResponse, TokenActionListApiResponse
8 changes: 4 additions & 4 deletions JellyBotAPI/api/responses/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def __init__(self, param_dict: QueryDict, sender_oid: ObjectId):
self._result = None

def is_success(self) -> bool:
return len(self._err) == 0 and self.success_conditions()
return len(self._err) == 0 and self.pass_condition()

@abc.abstractmethod
def success_conditions(self) -> bool:
def pass_condition(self) -> bool:
return True

# noinspection PyMethodMayBeStatic
Expand All @@ -37,13 +37,13 @@ def pre_process(self):
pass

@abc.abstractmethod
def process_ifnoerror(self):
def process_pass(self):
pass

def to_dict(self) -> dict:
self.pre_process()
if len(self._err) == 0:
self.process_ifnoerror()
self.process_pass()

d = self._serialize_()
is_success = self.is_success()
Expand Down
8 changes: 4 additions & 4 deletions JellyBotAPI/api/responses/ar/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def serialize_extra(self) -> dict:
d.update(**{result.FLAGS: self._flag, result.INFO: self._info})
return d

def success_conditions(self) -> bool:
def is_success(self) -> bool:
try:
return self._result.success
return super().is_success() and self._result.success
except AttributeError:
return False

Expand All @@ -153,14 +153,14 @@ def __init__(self, param_dict, sender_oid):
def pre_process(self):
super().pre_process()

def process_ifnoerror(self):
def process_pass(self):
self._result = AutoReplyManager.add_conn(
self._keyword, self._responses, self._sender_oid, self.get_channel_oid(),
self._pinned, self._private, self._tags, self._cooldown)


class AutoReplyAddTokenActionResponse(AutoReplyAddBaseResponse):
def process_ifnoerror(self):
def process_pass(self):
self._result = TokenActionManager.enqueue_action(
self._sender_oid, TokenAction.AR_ADD, AutoReplyModuleTokenActionModel,
KeywordOid=self._keyword, ResponsesOids=self._responses, CreatorOid=self._sender_oid,
Expand Down
6 changes: 3 additions & 3 deletions JellyBotAPI/api/responses/ar/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def __init__(self, param_dict, creator_oid):
def pre_process(self):
super().pre_process()

def success_conditions(self) -> bool:
return super().success_conditions()
def pass_condition(self) -> bool:
return super().pass_condition()

def serialize_failed(self) -> dict:
return dict()

def serialize_extra(self) -> dict:
return {result.FLAGS: self._flag}

def process_ifnoerror(self):
def process_pass(self):
self._result = AutoReplyManager.get_popularity_scores(self._keyword, self._count)
4 changes: 2 additions & 2 deletions JellyBotAPI/api/responses/ar/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _handle_content_(self):
k = param.Validation.CONTENT
self._data[k] = self._content

def success_conditions(self) -> bool:
def pass_condition(self) -> bool:
return not is_empty_string(self._content) and \
not is_empty_string(self._content_type) and \
self._result
Expand All @@ -45,7 +45,7 @@ def pre_process(self):
self._handle_content_type_()
self._handle_content_()

def process_ifnoerror(self):
def process_pass(self):
self._result = AutoReplyValidators.is_valid_content(self._data[param.Validation.CONTENT_TYPE],
self._data[param.Validation.CONTENT])

Expand Down
1 change: 1 addition & 0 deletions JellyBotAPI/api/responses/id/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .channel import ChannelDataQueryResponse, ChannelIssueRegisterTokenResponse, ChannelNameChangeResponse
from .perm import PermissionQueryResponse
11 changes: 5 additions & 6 deletions JellyBotAPI/api/responses/id/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class ChannelDataQueryResponse(HandleChannelMixin, HandlePlatformMixin, Serializ
def __init__(self, param_dict, creator_oid):
super().__init__(param_dict, creator_oid)

def success_conditions(self) -> bool:
return super().success_conditions() and self._result.success
def pass_condition(self) -> bool:
return super().pass_condition() and self._result.success

def process_ifnoerror(self):
def process_pass(self):
self._result = ChannelManager.get_channel_packed(self._platform, self._channel_token)

def serialize_success(self) -> dict:
Expand All @@ -38,15 +38,14 @@ def __init__(self, param_dict, creator_oid):
def pre_process(self):
super().pre_process()

def process_ifnoerror(self):
def process_pass(self):
self._result = TokenActionManager.enqueue_action(
self._sender_oid, TokenAction.CONNECT_CHANNEL,
ChannelRegisterMembershipModel, RootOid=self._sender_oid)


class ChannelNameChangeResponse(
RequireSenderMixin, SerializeErrorMixin, SerializeResultOnSuccessMixin, BaseApiResponse):

def __init__(self, param_dict, creator_oid):
super().__init__(param_dict, creator_oid)

Expand All @@ -63,5 +62,5 @@ def __init__(self, param_dict, creator_oid):
def pre_process(self):
super().pre_process()

def process_ifnoerror(self):
def process_pass(self):
self._result = ChannelManager.change_channel_name(self._channel_oid, self._root_oid, self._new_name)
44 changes: 44 additions & 0 deletions JellyBotAPI/api/responses/id/perm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from JellyBotAPI.api.responses import BaseApiResponse
from JellyBotAPI.api.static import param
from JellyBotAPI.api.responses.mixin import (
RequireSenderMixin,
SerializeErrorMixin, SerializeResultOnSuccessMixin, SerializeResultExtraMixin
)
from mongodb.factory import ProfileManager


class PermissionQueryResponse(
RequireSenderMixin,
SerializeErrorMixin, SerializeResultOnSuccessMixin, SerializeResultExtraMixin, BaseApiResponse):
def __init__(self, param_dict, sender_oid):
super().__init__(param_dict, sender_oid)

self._param_dict.update(**{
param.Manage.USER_OID: sender_oid,
param.Manage.Channel.CHANNEL_OID: param_dict.get(param.Manage.Channel.CHANNEL_OID),
})

self._root_oid = sender_oid
self._channel_oid = self._param_dict[param.Manage.Channel.CHANNEL_OID]
self._profiles = None

def _handle_channel_(self):
if not self._channel_oid:
self._err[param.Manage.Channel.CHANNEL_OID] = self._channel_oid

def pre_process(self):
super().pre_process()

self._handle_channel_()

def pass_condition(self) -> bool:
return super().pass_condition() and self._channel_oid is not None and self._root_oid is not None

def is_success(self) -> bool:
return super().is_success() and self._profiles is not None

def process_pass(self):
self._profiles = ProfileManager.get_user_profiles(self._channel_oid, self._root_oid)

if self._profiles:
self._result = ProfileManager.get_permissions(self._profiles)
18 changes: 9 additions & 9 deletions JellyBotAPI/api/responses/mixin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def _handle_(self):
else:
self._flag[k] = self._channel_token

def success_conditions(self) -> bool:
return super().success_conditions() and \
def pass_condition(self) -> bool:
return super().pass_condition() and \
self._channel_token is not None and \
not is_empty_string(self._channel_token)

Expand All @@ -46,13 +46,13 @@ def pre_process(self):
# noinspection PyArgumentList
def _handle_(self):
k = result.AutoReplyResponse.PLATFORM
if self._platform is None:
if not self._platform:
self._err[k] = None
else:
self._platform = self._flag[k] = Platform(int(self._platform))

def success_conditions(self) -> bool:
return super().success_conditions() and \
def pass_condition(self) -> bool:
return super().pass_condition() and \
self._platform is not None


Expand All @@ -75,8 +75,8 @@ def __init__(self, param_dict, sender_oid):
if sender_oid is None:
self._err[result.SenderIdentity.SENDER] = sender_oid

def success_conditions(self) -> bool:
return super().success_conditions() and self._sender_oid is not None
def pass_condition(self) -> bool:
return super().pass_condition() and self._sender_oid is not None


class RequireSenderAutoRegisterMixin(RequireSenderMixin, ABC):
Expand Down Expand Up @@ -108,5 +108,5 @@ def _handle_user_token_(self, param_dict):
if rt_result.success:
self._sender_oid = rt_result.model.id

def success_conditions(self) -> bool:
return super().success_conditions() and self._sender_oid is not None
def pass_condition(self) -> bool:
return super().pass_condition() and self._sender_oid is not None
6 changes: 3 additions & 3 deletions JellyBotAPI/api/responses/tkact.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, param_dict, sender_oid):
self._token = param_dict.get(param.TokenAction.TOKEN)
self._param_dict.update(**param_dict)

def success_conditions(self) -> bool:
def pass_condition(self) -> bool:
return not is_empty_string(self._token) and self._result.success

def _handle_token_(self):
Expand All @@ -25,7 +25,7 @@ def _handle_token_(self):
def pre_process(self):
self._handle_token_()

def process_ifnoerror(self):
def process_pass(self):
self._result = TokenActionManager.complete_action(self._token, self.param_dict)

def serialize_success(self) -> dict:
Expand All @@ -37,7 +37,7 @@ class TokenActionListApiResponse(
def __init__(self, param_dict, sender_oid):
super().__init__(param_dict, sender_oid)

def process_ifnoerror(self):
def process_pass(self):
self._result = list(TokenActionManager.get_queued_actions(self._sender_oid))

def pre_process(self):
Expand Down
2 changes: 2 additions & 0 deletions JellyBotAPI/api/static/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class AutoReply:
class DataQuery:
COUNT = Common.COUNT
KEYWORD = Common.KEYWORD
USER_OID = Common.USER_OID

class Channel:
PLATFORM = Common.PLATFORM
CHANNEL_TOKEN = Common.CHANNEL_TOKEN
CHANNEL_OID = Common.CHANNEL_OID


class Manage:
Expand Down
2 changes: 0 additions & 2 deletions JellyBotAPI/components/navbar/holder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import warnings
from typing import Union, List

from extutils.gmail import MailSender

from .entry import NavEntry, NavFirstLevelItem
from .dropdown import NavDropdown, NavBaseItem

Expand Down
8 changes: 4 additions & 4 deletions JellyBotAPI/components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from bson import ObjectId

from JellyBotAPI.keys import Session, ParamDictFilter
from JellyBotAPI.keys import Session, ParamDictPrefix


def get_root_oid(request) -> Optional[ObjectId]:
Expand All @@ -11,6 +11,6 @@ def get_root_oid(request) -> Optional[ObjectId]:
return None if oid_str is None else ObjectId(oid_str)


def get_x_post_keys(qd):
return {k.replace(ParamDictFilter.Filter1, ""): v for k, v in qd.items()
if k.startswith(ParamDictFilter.Filter1)}
def get_post_keys(qd):
return {k.replace(ParamDictPrefix.PostKey, ""): v for k, v in qd.items()
if k.startswith(ParamDictPrefix.PostKey)}
6 changes: 3 additions & 3 deletions JellyBotAPI/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class Css:
LOGGED_IN_ENABLE = "enable-login"


# Param Dict Filter
class ParamDictFilter:
Filter1 = "x-"
# Param Dict Prefix
class ParamDictPrefix:
PostKey = "x-" # Used in http POST params from HTML forms
2 changes: 1 addition & 1 deletion JellyBotAPI/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Run "py manage.py check --deploy" config to ensure no compiling bugs #
# Disregard: security.W004, security.W008, security.W012, security.W016
# Run "py manage.py makemessages -a" to create translation files (compilemessages for *.mo) #
# Run tests with code coverage #
# Run tests #
###############################################################################################

# MAIN
Expand Down
20 changes: 19 additions & 1 deletion JellyBotAPI/views/about.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
from dateutil import parser

from django.utils.timezone import localtime
from django.views.generic.base import View
from django.utils.translation import gettext as _

from JellyBotAPI.views.render import render_template
from extutils import HerokuWrapper, GithubWrapper


class AboutView(View):
# noinspection PyUnusedLocal, PyMethodMayBeStatic
def get(self, request, *args, **kwargs):
return render_template(request, _("About"), "about.html")
beta_app = "jellybotapi-staging"
stable_app = "jellybotapi"

return render_template(request, _("About"), "about.html", {
"beta_update_about": localtime(
HerokuWrapper.latest_succeeded_release(beta_app).updated_at).strftime("%m/%d %H:%M:%S (UTC%z)"),
"stable_update_about": localtime(
HerokuWrapper.latest_succeeded_release(stable_app).updated_at).strftime("%m/%d %H:%M:%S (UTC%z)"),
"beta_deploy": localtime(
parser.parse(
GithubWrapper.get_latest_deployment(beta_app).updated_at)).strftime("%m/%d %H:%M:%S (UTC%z)"),
"stable_deploy": localtime(
parser.parse(
GithubWrapper.get_latest_deployment(stable_app).updated_at)).strftime("%m/%d %H:%M:%S (UTC%z)")
})
Loading

0 comments on commit 15c5429

Please sign in to comment.