Skip to content

Commit d5ea3db

Browse files
author
KirillMysnik
committed
Started enforcing non-None 'flag' attribute on all feature classes
1 parent bb6f589 commit d5ea3db

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

srcds/addons/source-python/plugins/admin/core/features.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,33 @@
77
# =============================================================================
88
# >> CLASSES
99
# =============================================================================
10-
class BaseFeature:
10+
class FeatureMeta(type):
11+
def __init__(cls, name, bases, namespace):
12+
super().__init__(name, bases, namespace)
13+
14+
if namespace.get('feature_abstract', False):
15+
del cls.feature_abstract
16+
return
17+
18+
if not hasattr(cls, 'flag'):
19+
raise ValueError("Class '{}' doesn't have 'flag' "
20+
"attribute".format(cls))
21+
22+
if cls.flag is None:
23+
raise ValueError("Class '{}' has its 'flag' "
24+
"attribute set to None".format(cls))
25+
26+
27+
class BaseFeature(metaclass=FeatureMeta):
28+
feature_abstract = True
29+
1130
# Required permission in Source.Python auth system to execute this feature
1231
flag = None
1332

1433

1534
class Feature(BaseFeature):
35+
feature_abstract = True
36+
1637
def execute(self, client):
1738
"""Execute the feature.
1839
@@ -22,6 +43,8 @@ def execute(self, client):
2243

2344

2445
class PlayerBasedFeature(BaseFeature):
46+
feature_abstract = True
47+
2548
# Allow clients to execute this feature on themselves?
2649
allow_execution_on_self = True
2750

srcds/addons/source-python/plugins/admin/core/frontends/menus.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ def is_visible(self, client):
170170
if not default:
171171
return False
172172

173-
# Do we even need to check the permission?
174-
if self.feature.flag is None:
175-
return True
176-
177173
return client.has_permission(self.feature.flag)
178174

179175
def is_selectable(self, client):
@@ -187,10 +183,6 @@ def is_selectable(self, client):
187183
if not default:
188184
return False
189185

190-
# Do we even need to check the permission?
191-
if self.feature.flag is None:
192-
return True
193-
194186
return client.has_permission(self.feature.flag)
195187

196188
def select(self, client):

srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/left_player.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def iterator():
8989

9090

9191
class LeftPlayerBasedFeature(BaseFeature):
92+
feature_abstract = True
93+
9294
# Allow clients to execute this feature on themselves?
9395
allow_execution_on_self = True
9496

0 commit comments

Comments
 (0)