Spaces:
Running
Running
thadillo
commited on
Commit
·
47ac3f3
1
Parent(s):
f181d9e
Add support for multiple admin tokens
Browse files- Add 'Administrator' option to Create Token dropdown
- Allow creating admin type tokens via API
- Only ADMIN123 is protected from deletion (other admin tokens can be deleted)
- Admin tokens format: ADM-XXXXXX1234
Now you can create multiple admin users for your team!
- app/routes/admin.py +8 -2
- app/templates/admin/tokens.html +7 -1
app/routes/admin.py
CHANGED
|
@@ -176,7 +176,9 @@ def create_token():
|
|
| 176 |
contributor_type = data.get('type')
|
| 177 |
name = data.get('name', '').strip()
|
| 178 |
|
| 179 |
-
|
|
|
|
|
|
|
| 180 |
return jsonify({'success': False, 'error': 'Invalid contributor type'}), 400
|
| 181 |
|
| 182 |
import random
|
|
@@ -187,7 +189,11 @@ def create_token():
|
|
| 187 |
timestamp_part = str(int(datetime.now().timestamp()))[-4:]
|
| 188 |
token_str = f"{prefix}-{random_part}{timestamp_part}"
|
| 189 |
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
new_token = Token(
|
| 193 |
token=token_str,
|
|
|
|
| 176 |
contributor_type = data.get('type')
|
| 177 |
name = data.get('name', '').strip()
|
| 178 |
|
| 179 |
+
# Allow 'admin' type in addition to contributor types
|
| 180 |
+
valid_types = [t['value'] for t in CONTRIBUTOR_TYPES] + ['admin']
|
| 181 |
+
if not contributor_type or contributor_type not in valid_types:
|
| 182 |
return jsonify({'success': False, 'error': 'Invalid contributor type'}), 400
|
| 183 |
|
| 184 |
import random
|
|
|
|
| 189 |
timestamp_part = str(int(datetime.now().timestamp()))[-4:]
|
| 190 |
token_str = f"{prefix}-{random_part}{timestamp_part}"
|
| 191 |
|
| 192 |
+
# Default name based on type
|
| 193 |
+
if contributor_type == 'admin':
|
| 194 |
+
final_name = name if name else "Administrator"
|
| 195 |
+
else:
|
| 196 |
+
final_name = name if name else f"{contributor_type.capitalize()} User"
|
| 197 |
|
| 198 |
new_token = Token(
|
| 199 |
token=token_str,
|
app/templates/admin/tokens.html
CHANGED
|
@@ -10,8 +10,12 @@
|
|
| 10 |
<i class="bi bi-plus-circle"></i> Create Token Manually
|
| 11 |
</button>
|
| 12 |
<ul class="dropdown-menu">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
{% for type in contributor_types %}
|
| 14 |
-
<li><a class="dropdown-
|
| 15 |
{{ type.label }}
|
| 16 |
</a></li>
|
| 17 |
{% endfor %}
|
|
@@ -44,6 +48,8 @@
|
|
| 44 |
<button class="btn btn-sm btn-outline-danger" onclick="deleteToken({{ token.id }})">
|
| 45 |
<i class="bi bi-trash"></i>
|
| 46 |
</button>
|
|
|
|
|
|
|
| 47 |
{% endif %}
|
| 48 |
</td>
|
| 49 |
</tr>
|
|
|
|
| 10 |
<i class="bi bi-plus-circle"></i> Create Token Manually
|
| 11 |
</button>
|
| 12 |
<ul class="dropdown-menu">
|
| 13 |
+
<li><a class="dropdown-item" href="#" onclick="createToken('admin', 'Administrator'); return false;">
|
| 14 |
+
<i class="bi bi-shield-fill text-danger"></i> <strong>Administrator</strong>
|
| 15 |
+
</a></li>
|
| 16 |
+
<li><hr class="dropdown-divider"></li>
|
| 17 |
{% for type in contributor_types %}
|
| 18 |
+
<li><a class="dropdown-item" href="#" onclick="createToken('{{ type.value }}', '{{ type.label }}'); return false;">
|
| 19 |
{{ type.label }}
|
| 20 |
</a></li>
|
| 21 |
{% endfor %}
|
|
|
|
| 48 |
<button class="btn btn-sm btn-outline-danger" onclick="deleteToken({{ token.id }})">
|
| 49 |
<i class="bi bi-trash"></i>
|
| 50 |
</button>
|
| 51 |
+
{% else %}
|
| 52 |
+
<span class="badge bg-secondary">Default Admin</span>
|
| 53 |
{% endif %}
|
| 54 |
</td>
|
| 55 |
</tr>
|