mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 21:05:15 +00:00
Set slack_username field separate from usernames
This commit is contained in:
parent
bf46cea690
commit
319e5b732f
4 changed files with 10 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ class SlackUsernameUpdateJob < ApplicationJob
|
|||
|
||||
user.username = user_data.dig("user", "profile", "username")
|
||||
user.username ||= user_data.dig("user", "profile", "display_name_normalized")
|
||||
user.slack_username = user_data.dig("user", "profile", "username")
|
||||
user.slack_avatar_url = user_data.dig("user", "profile", "image_192") || user_data.dig("user", "profile", "image_72")
|
||||
user.save!
|
||||
rescue => e
|
||||
|
|
|
|||
|
|
@ -206,6 +206,7 @@ class User < ApplicationRecord
|
|||
|
||||
user.username ||= user_data.dig("user", "profile", "username")
|
||||
user.username ||= user_data.dig("user", "profile", "display_name_normalized")
|
||||
user.slack_username = user_data.dig("user", "profile", "username")
|
||||
user.slack_avatar_url = user_data.dig("user", "profile", "image_192") || user_data.dig("user", "profile", "image_72")
|
||||
|
||||
user.parse_and_set_timezone(user_data.dig("user", "tz"))
|
||||
|
|
@ -299,6 +300,7 @@ class User < ApplicationRecord
|
|||
|
||||
def display_name
|
||||
return username if username.present?
|
||||
return github_username if github_username.present?
|
||||
|
||||
# "zach@hackclub.com" -> "zach (email sign-up)"
|
||||
email = email_addresses&.first&.email
|
||||
|
|
|
|||
5
db/migrate/20250319193636_add_slack_username_to_users.rb
Normal file
5
db/migrate/20250319193636_add_slack_username_to_users.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddSlackUsernameToUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :users, :slack_username, :string
|
||||
end
|
||||
end
|
||||
3
db/schema.rb
generated
3
db/schema.rb
generated
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_03_19_165910) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_03_19_193636) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_catalog.plpgsql"
|
||||
|
||||
|
|
@ -248,6 +248,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_19_165910) do
|
|||
t.string "github_avatar_url"
|
||||
t.text "github_access_token"
|
||||
t.string "github_username"
|
||||
t.string "slack_username"
|
||||
t.index ["slack_uid"], name: "index_users_on_slack_uid", unique: true
|
||||
t.index ["timezone"], name: "index_users_on_timezone"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue