Prevent Badge IDs of less than 100?

(cpradio) #1

Continuing the discussion from Unable to edit type or delete badges created programatically:

Is this already being done and it wasn’t initially? Or is there room for improvement here to prevent user created badges from having an ID under 100?

(Sam Saffron) #2

This is already the case, no changes needed. Only way to get less than 100 is hardcode directly using the object model

(Michael Congiusta) #3

I’ve since fixed the problem, but when I created the badges initially I used the following code for iterating over a hash

badgesHash.each do |bName, bDesc|
  unless badge = Badge.find_by(name: bName)
    badge = Badge.create!(name: bName,
                         description: bDesc[0],
                         enabled: bDesc[1],
                         badge_type_id: bDesc[2])

No ID was hardcoded, so I’m not sure if I missed something.

Either way, probably pretty niche as I’m pretty certain badges created in the admin CP have their IDs set to over 100.

(James Milligan) #4

@sam - I’ve just started with a fresh Discourse install (still non-Docker, hopefully for not much longer). Creating a new badge in the standard way gives it an ID of 19, and it appears as though I can’t delete it. Is this related to your statement above, or something else? I’m pretty sure I could delete badges in a previous version.

(Sam Saffron) #5

What version are you on, I just tested here on meta and the constraint is in place.

In particular see:

This issue could be postgres version related … I dunno.

(James Milligan) #6

Just updated from the repo, still appears to be the same.

Clicking “new” and filling out the details as below, I still see the ‘Delete’ link. Once hitting ‘Save’, that goes.

Name: "Associate Member"
Icon: "fa-user"
Badge Type: "Bronze"
Group: “Membership” (custom badge group)
Description: NULL
Badge Query: NULL
Allow badge to be used as title: 1
Can be granted multiple times: 0
Show badge on public badges page: 1
Show post granting badge on badge page: 0
Enable badge: 1

(Minor note - perhaps that second from last one should match the label above - badge page vs badges page)

I can’t edit the badge type either (i.e. bronze/silver/gold) nor the SQL.

This is on PGSQL 9.1.13, Ubuntu 13.10, brand new installation as of last night, updated a few minutes ago.

Just tried another badge in the “Other” group, type = silver, added a description, same checkboxes. Same behaviour in that I can’t edit some fields, and I can’t delete it.

(Sam Saffron) #7

anything in logs?

what is in the database?

(James Milligan) #8

CSV output of DB (left a ‘normal’ badge in there for comparison)

"20","IT & Forum Administrator","  ","2","1","2014-07-31 20:33:03.474936","2014-07-31 20:33:03.474936","t","f","fa-terminal","t","f","  ","t","f","8","  ","f"
"17","Reader","  ","3","0","2014-07-31 19:23:45.911073","2014-08-01 07:05:21.889238","f","f","fa-certificate","t","f","t","f","1","  ","f"
"22","Associate Member","  ","3","0","2014-08-01 07:12:55.393697","2014-08-01 07:12:55.393697","t","f","fa-user","t","f","  ","t","f","7","  ","f"
"23","Test Badge","Test badge","2","0","2014-08-01 07:17:41.448009","2014-08-01 07:17:41.448009","t","f","fa-certificate","t","f","  ","t","f","5","  ","f"

Log entry:

Started POST "/admin/badges" for at 2014-08-01 08:12:55 +0100
Processing by Admin::BadgesController#create as */*
  Parameters: {"allow_title"=>"true", "multiple_grant"=>"false", "listable"=>"true", "auto_revoke"=>"false", "enabled"=>"true", "show_posts"=>"false", "target_posts"=>"false", "name"=>"Associate Member", "icon"=>"fa-user", "badge_grouping_id"=>"7", "badge_type_id"=>"3"}
Completed 200 OK in 190ms (Views: 0.3ms | ActiveRecord: 136.5ms)
Started POST "/admin/badges" for at 2014-08-01 08:17:41 +0100
Processing by Admin::BadgesController#create as */*
  Parameters: {"allow_title"=>"true", "multiple_grant"=>"false", "listable"=>"true", "auto_revoke"=>"false", "enabled"=>"true", "show_posts"=>"false", "target_posts"=>"false", "name"=>"Test Badge", "description"=>"Test badge", "badge_grouping_id"=>"5", "badge_type_id"=>"2"}
Completed 200 OK in 77ms (Views: 0.3ms | ActiveRecord: 59.8ms)

(Sam Saffron) #9

have a look at the the sequence on the table, does it start at 100 ?

(James Milligan) #10

Not totally familiar with PGSQL, is this what you’re after?

Current: 24
Min: 1
Max: 9223372036854775807

(Sam Saffron) #11

Yes, which raises the question, why did this migration run or work discourse/20140504174212_increment_reserved_trust_level_badge_ids.rb at master · discourse/discourse · GitHub

:wink: so hard supporting our non-docker installs

(James Milligan) #12

:blush: I certainly appreciate any help at all as I know it’s not officially supported.

I’d find it odd if something like this acts differently between this and a Docker install though?

(Sam Saffron) #13

Pg 9.1 vs 9.3 in docker setups

(James Milligan) #14

Ah… that’s probably a likely candidate then.

(James Milligan) #15

Thanks @sam - your commit earlier fixed the issue and has bumped the badges up as needed, they’re now editable.

(Sam Saffron) #16