diff options
| -rw-r--r-- | pysite/constants.py | 20 | ||||
| -rw-r--r-- | pysite/views/api/bot/clean.py | 3 | ||||
| -rw-r--r-- | pysite/views/main/bot/cleanlog.py | 34 | ||||
| -rw-r--r-- | tests/test_clean_logs.py | 5 | 
4 files changed, 27 insertions, 35 deletions
| diff --git a/pysite/constants.py b/pysite/constants.py index 69c73492..d7453871 100644 --- a/pysite/constants.py +++ b/pysite/constants.py @@ -101,6 +101,26 @@ JAM_QUESTION_TYPES = [      "slider"  ] +# Server role colors +ROLE_COLORS = { +    "owners": "#ffa3a1", +    "admins": "#e76e6c", +    "moderators": "#ce3c42", +    "python": "#6f9fed", +    "bots": "#6f9fed", +    "admin bots": "#6f9fed", +    "devops": "#a1d1ff", +    "helpers": "#e0b000", +    "subreddit moderators": "#d897ed", +    "partners": "#b66fed", +    "streamers": "#833cba", +    "developers": "#fcfcfc", +    "muted": "#fcfcfc", +    "code jam champions": "#b108b4", +    "jammers": "#258639", +    "contributors": "#55cc6c" +} +  # CSRF  CSRF = CSRFProtect() diff --git a/pysite/views/api/bot/clean.py b/pysite/views/api/bot/clean.py index 216261ce..f914c03c 100644 --- a/pysite/views/api/bot/clean.py +++ b/pysite/views/api/bot/clean.py @@ -11,7 +11,8 @@ POST_SCHEMA = Schema({          {              "author": str,              "content": str, -            "timestamp": str +            "timestamp": str, +            "role": str          }      ]  }) diff --git a/pysite/views/main/bot/cleanlog.py b/pysite/views/main/bot/cleanlog.py index abd1ee2e..1c90dc0b 100644 --- a/pysite/views/main/bot/cleanlog.py +++ b/pysite/views/main/bot/cleanlog.py @@ -1,8 +1,7 @@  import logging -import random  from pysite.base_route import RouteView -from pysite.constants import ALL_STAFF_ROLES +from pysite.constants import ALL_STAFF_ROLES, ROLE_COLORS  from pysite.decorators import require_roles  from pysite.mixins import DBMixin, OAuthMixin @@ -16,35 +15,6 @@ class CleanLogView(RouteView, DBMixin, OAuthMixin):      table_name = "clean_logs"      template = "main/bot/clean_logs.html" -    # Colors -    author_colors = {} -    all_colors = [ -        "#afcfff", -        "#93ff91", -        "#ffe559", -        "#ff9036", -        "#ff6c5e", -        "#ff65be", -        "#9298ff", -    ] -    color_pool = all_colors - -    def _assign_color(self, author): -        """ -        Assign a color to a specific author. -        """ - -        if not self.color_pool: -            self.color_pool = self.all_colors - -        if author not in self.author_colors: -            random_index = random.randint(0, len(self.color_pool)) -            color = self.color_pool.pop(random_index) -            self.author_colors[author] = color -            return color -        else: -            return self.author_colors[author] -      @require_roles(ALL_STAFF_ROLES)      def get(self, log_id):          """ @@ -60,6 +30,6 @@ class CleanLogView(RouteView, DBMixin, OAuthMixin):          messages = data["log_data"]          for message in messages: -            message['color'] = self._assign_color(message['author']) +            message['color'] = ROLE_COLORS.get(message['role'], ROLE_COLORS['developers'])          return self.render(self.template, messages=messages) diff --git a/tests/test_clean_logs.py b/tests/test_clean_logs.py index 210306c0..4932b4b6 100644 --- a/tests/test_clean_logs.py +++ b/tests/test_clean_logs.py @@ -29,8 +29,9 @@ class TestCleanLogAPI(SiteTest):          good_data = json.dumps({              "log_data": [                  { -                    "author":    "something", -                    "content":   "testy", +                    "author": "something", +                    "role": "awful", +                    "content": "testy",                      "timestamp": "this way comes"                  }              ] | 
