mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
Avatar supports non-slack users
This commit is contained in:
parent
af4f697d13
commit
40717fbc0c
3 changed files with 14 additions and 3 deletions
|
|
@ -147,7 +147,7 @@ class User < ApplicationRecord
|
|||
user = find_or_initialize_by(slack_uid: data.dig("authed_user", "id"))
|
||||
user.username = user_data.dig("user", "profile", "username")
|
||||
user.username ||= user_data.dig("user", "profile", "display_name_normalized")
|
||||
user.avatar_url = user_data.dig("user", "profile", "image_192") || user_data.dig("user", "profile", "image_72")
|
||||
user.slack_avatar_url = user_data.dig("user", "profile", "image_192") || user_data.dig("user", "profile", "image_72")
|
||||
# Store the OAuth data
|
||||
user.slack_access_token = data["authed_user"]["access_token"]
|
||||
user.slack_scopes = data["authed_user"]["scope"]&.split(/,\s*/)
|
||||
|
|
@ -165,6 +165,12 @@ class User < ApplicationRecord
|
|||
nil
|
||||
end
|
||||
|
||||
def avatar_url
|
||||
return self.slack_avatar_url if self.slack_avatar_url.present?
|
||||
return "https://initials.me/#{self.username}=50" if self.username.present?
|
||||
"https://initials.me/#{self.email_addresses.first.email[0..1]}=50" if self.email_addresses.any?
|
||||
end
|
||||
|
||||
def project_names
|
||||
heartbeats.select(:project).distinct.pluck(:project)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class RenameAvatarUrlToSlackAvatarUrlOnUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
rename_column :users, :avatar_url, :slack_avatar_url
|
||||
end
|
||||
end
|
||||
4
db/schema.rb
generated
4
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_07_225347) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_03_10_165010) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_catalog.plpgsql"
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_07_225347) do
|
|||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "username"
|
||||
t.string "avatar_url"
|
||||
t.string "slack_avatar_url"
|
||||
t.boolean "is_admin", default: false, null: false
|
||||
t.boolean "uses_slack_status", default: false, null: false
|
||||
t.string "slack_scopes", default: [], array: true
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue