mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
Add list of email addresses on settings page (#197)
This commit is contained in:
parent
7277cd9bae
commit
aa15bba79e
7 changed files with 30 additions and 2 deletions
|
|
@ -37,6 +37,7 @@ module Api
|
|||
return render json: { error: "Email not found" }, status: :bad_request unless email.present?
|
||||
|
||||
email_address = EmailAddress.find_or_initialize_by(email: email)
|
||||
email_address.source ||= :slack
|
||||
user.email_addresses << email_address unless user.email_addresses.include?(email_address)
|
||||
|
||||
user.update_from_slack
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class HandleEmailSigninJob < ApplicationJob
|
|||
email_address = ActiveRecord::Base.transaction do
|
||||
EmailAddress.find_by(email: email) || begin
|
||||
user = User.create!
|
||||
user.email_addresses.create!(email: email)
|
||||
user.email_addresses.create!(email: email, source: :direct)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,12 @@ class EmailAddress < ApplicationRecord
|
|||
uniqueness: true,
|
||||
format: { with: URI::MailTo::EMAIL_REGEXP }
|
||||
|
||||
enum :source, {
|
||||
direct: 0,
|
||||
github: 1,
|
||||
slack: 2
|
||||
}, prefix: true
|
||||
|
||||
before_validation :downcase_email
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -233,6 +233,7 @@ class User < ApplicationRecord
|
|||
|
||||
email = user_data.dig("user", "profile", "email")&.downcase
|
||||
email_address = EmailAddress.find_or_initialize_by(email: email)
|
||||
email_address.source ||= :slack
|
||||
user = email_address.user
|
||||
user ||= begin
|
||||
u = User.find_or_initialize_by(slack_uid: data.dig("authed_user", "id"))
|
||||
|
|
|
|||
|
|
@ -85,6 +85,20 @@
|
|||
<% end %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="user_email_addresses">Email Addresses</h2>
|
||||
<p>These are the email addresses associated with your account.</p>
|
||||
<% if @user.email_addresses.any? %>
|
||||
<ul>
|
||||
<% @user.email_addresses.each do |email_address| %>
|
||||
<li><%= email_address.email %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<p>No email addresses found.</p>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="user_hackatime_extension">Hackatime extension</h2>
|
||||
<%= form_with model: @user,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class AddSourceToEmailAddresses < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :email_addresses, :source, :integer, null: true
|
||||
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_04_25_211619) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_05_03_215404) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_catalog.plpgsql"
|
||||
|
||||
|
|
@ -31,6 +31,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_04_25_211619) do
|
|||
t.bigint "user_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "source"
|
||||
t.index ["email"], name: "index_email_addresses_on_email", unique: true
|
||||
t.index ["user_id"], name: "index_email_addresses_on_user_id"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue