diff options
| -rw-r--r-- | api/game/socket.py | 12 | ||||
| -rw-r--r-- | api/hierarchy.py | 70 | 
2 files changed, 41 insertions, 41 deletions
diff --git a/api/game/socket.py b/api/game/socket.py index eded965..09b2151 100644 --- a/api/game/socket.py +++ b/api/game/socket.py @@ -12,17 +12,17 @@ games = {}  def participants_only(func):      ''' -	listener should have two parameters: -	listener(data: socket.io.data, user_id: str, game: game) +    listener should have two parameters: +    listener(data: socket.io.data, user_id: str, game: game) -	listener should only be executed if the request comes from one of -	the game participants (player_1_id | player_2_id) -	''' +    listener should only be executed if the request comes from one of +    the game participants (player_1_id | player_2_id) +    '''      def wrapper(data, user_id):          game_id = data["game_id"]          if not game_id or \ -		   not game_id in games: +           not game_id in games:              return          game = games[game_id] diff --git a/api/hierarchy.py b/api/hierarchy.py index 247ee9e..7b60f8d 100644 --- a/api/hierarchy.py +++ b/api/hierarchy.py @@ -9,13 +9,13 @@ ranks = ["none", "user", "moderator", "admin", "bot"]  def util_two_id(type="user"):      ''' -	type?: "user" | "game" -	! only used internally ! -	func(token_id?: str, explicit_id?: str) +    type?: "user" | "game" +    ! only used internally ! +    func(token_id?: str, explicit_id?: str) -	This decorator doesn't check for hierarchy constraints, but does -	make sure that token_id or explicit_id are valid user_id's -	''' +    This decorator doesn't check for hierarchy constraints, but does +    make sure that token_id or explicit_id are valid user_id's +    '''      def decorator(func):          def wrapper():              token_id = None @@ -29,7 +29,7 @@ def util_two_id(type="user"):              # if there's an explicit_id, validate it using `type`              if explicit_id and \ -			   not valid.validate(explicit_id, type): +               not valid.validate(explicit_id, type):                  explicit_id = None              return func(token_id, explicit_id) @@ -42,12 +42,12 @@ def util_two_id(type="user"):  def two_person(func):      ''' -	endpoint should have two parameters: -	endpoint(user_1_id: str, user_2_id: str) +    endpoint should have two parameters: +    endpoint(user_1_id: str, user_2_id: str) -	no authentication, just runs endpoint() if both token_id and -	explicit_id are present from @util_two_id. -	''' +    no authentication, just runs endpoint() if both token_id and +    explicit_id are present from @util_two_id. +    '''      @util_two_id("user")      def wrapper(token_id, explicit_id):          if not all_def([token_id, explicit_id]): @@ -61,13 +61,13 @@ def two_person(func):  def one_person(func):      ''' -	endpoint should have two parameters: -	endpoint(user_id: str, viewer?: str) +    endpoint should have two parameters: +    endpoint(user_id: str, viewer?: str) -	uses json data id with token_login id as fallback -	doesn't check for authentication -	expects that func takes these arguments: (user_id, viewer?) -	''' +    uses json data id with token_login id as fallback +    doesn't check for authentication +    expects that func takes these arguments: (user_id, viewer?) +    '''      @util_two_id("user")      def wrapper(token_id, explicit_id):          if all_notdef([token_id, explicit_id]): @@ -81,9 +81,9 @@ def one_person(func):  def game_id_with_viewer(func):      ''' -	endpoint should have two parameters: -	endpoint(game_id: str, viewer?: str) -	''' +    endpoint should have two parameters: +    endpoint(game_id: str, viewer?: str) +    '''      @util_two_id("game")      def wrapper(token_id, game_id):          if all_notdef([token_id, game_id]): @@ -97,14 +97,14 @@ def game_id_with_viewer(func):  def auth_required(level):      ''' -	level = "none" | "user" | "moderator" | "admin" | "bot" -	endpoint should have one parameter for the user_id of the request author: -	endpoint(user_id: str) # `user_id` can only be `None` when `level == "none"` - -	@auth_required function decorator (use after @flask.Blueprint.route() decorator) -	This decorator only runs endpoint() if token_id from -	@util_two_id is not None and passes hierarchy constraints -	''' +    level = "none" | "user" | "moderator" | "admin" | "bot" +    endpoint should have one parameter for the user_id of the request author: +    endpoint(user_id: str) # `user_id` can only be `None` when `level == "none"` + +    @auth_required function decorator (use after @flask.Blueprint.route() decorator) +    This decorator only runs endpoint() if token_id from +    @util_two_id is not None and passes hierarchy constraints +    '''      def decorator(func):          @util_two_id("user")          def wrapper(token_id, explicit_id): @@ -132,13 +132,13 @@ def auth_required(level):  def io_auth_required(level):      ''' -	level = "none" | "user" | "moderator" | "admin" | "bot" -	endpoint should have two parameters: -	endpoint(data: socket.io.data, user_id: str) # `user_id` can only be `None` when `level == "none"` +    level = "none" | "user" | "moderator" | "admin" | "bot" +    endpoint should have two parameters: +    endpoint(data: socket.io.data, user_id: str) # `user_id` can only be `None` when `level == "none"` -	uses the @auth_required decorator, but is only for use with -	@io.on decorators -	''' +    uses the @auth_required decorator, but is only for use with +    @io.on decorators +    '''      def decorator(func):          # data is the original @io.on data          def wrapper(data={}):  |