Skip to content

Commit

Permalink
use hex_dojo_id instead of reference_id to line up with DojoChallenge
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Jan 23, 2024
1 parent 00d9c94 commit 86e881b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions dojo_plugin/api/v1/dojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ class PruneAwards(Resource):
def post(self, dojo):
all_completions = set(user for user,_ in dojo.completions())
num_pruned = 0
for award in Emojis.query.where(Emojis.category==dojo.reference_id):
for award in Emojis.query.where(Emojis.category==dojo.hex_dojo_id):
if award.user not in all_completions:
num_pruned += 1
db.session.delete(award)
db.session.commit()
return {"success": True, "pruned_awards": num_pruned, "all_completions": str(all_completions)}
return {"success": True, "pruned_awards": num_pruned}

@dojo_namespace.route("/<dojo>/promote-admin")
class PromoteAdmin(Resource):
Expand Down
4 changes: 2 additions & 2 deletions dojo_plugin/api/v1/scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_scoreboard_page(model, duration=None, page=1, per_page=20):
pagination = Pagination(None, page, per_page, len(results), results[start_idx:end_idx])
user = get_current_user()

viewable_dojos = { dojo.reference_id for dojo in Dojos.viewable(user=user) }
viewable_dojos = { dojo.hex_dojo_id:dojo for dojo in Dojos.viewable(user=user) }
emojis = { }
for emoji in Emojis.query.order_by(Emojis.date).all():
if emoji.category not in viewable_dojos:
Expand All @@ -101,7 +101,7 @@ def get_scoreboard_page(model, duration=None, page=1, per_page=20):
"text": emoji.description,
"emoji": emoji.name,
"count": 1,
"url": url_for("pwncollege_dojo.listing", dojo=emoji.category)
"url": url_for("pwncollege_dojo.listing", dojo=viewable_dojos[emoji.category])
})

def standing(item):
Expand Down
2 changes: 1 addition & 1 deletion dojo_plugin/utils/awards.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_user_emojis(user):
if not emoji:
continue
if dojo.completed(user):
emojis.append((emoji, dojo.name, dojo.reference_id))
emojis.append((emoji, dojo.name, dojo.hex_dojo_id))
return emojis

def get_belts():
Expand Down
11 changes: 5 additions & 6 deletions test/test_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,12 @@ def test_promote_dojo_member(admin_session, singleton_user):

@pytest.mark.dependency(depends=["test_join_dojo"])
def test_prune_dojo_awards(admin_session, singleton_user, example_dojo_rid):
db_sql(f"INSERT into awards (type,category,user_id,name) values ('emoji', '{example_dojo_rid}', {get_user_id(singleton_user[0])}, 'test')")
assert int(db_sql_one(f"SELECT count(*) from awards where category='{example_dojo_rid}'")) == 1
response = admin_session.post(f"{PROTO}://{HOST}/pwncollege_api/v1/dojo/{example_dojo_rid}/prune-awards", json={})
example_hex_id = example_dojo_rid.split("~")[-1]
db_sql(f"INSERT into awards (type,category,user_id,name) values ('emoji', '{example_hex_id}', {get_user_id(singleton_user[0])}, 'test')")
assert int(db_sql_one(f"SELECT count(*) from awards where category='{example_hex_id}'")) == 1
response = admin_session.post(f"{PROTO}://{HOST}/pwncollege_api/v1/dojo/{example_hex_id}/prune-awards", json={})
assert response.status_code == 200
print(response.json())
print(db_sql("SELECT * from awards"))
assert int(db_sql_one(f"SELECT count(*) from awards where category='{example_dojo_rid}'")) == 0
assert int(db_sql_one(f"SELECT count(*) from awards where category='{example_hex_id}'")) == 0

@pytest.mark.dependency(depends=["test_start_challenge"])
@pytest.mark.parametrize("path", ["/flag", "/challenge/apple"])
Expand Down

0 comments on commit 86e881b

Please sign in to comment.