redmine_remotes 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b9a64e1477b3e084cb4d065af0ec66ac260ad54297e687f6561592cfb4052c7
4
- data.tar.gz: ebbbc2b95438d7607df5ce0f3b55dbdf2f96a22217cb50a4c1cd1ced6486904f
3
+ metadata.gz: 2a0671e339c9e225c9413feb402fed23e0ac5e930a3e72027aa2b183749441d5
4
+ data.tar.gz: eb1245a9f15262922b95bec5574bdbb3dbc84f286d7fed371970b759657f6e2d
5
5
  SHA512:
6
- metadata.gz: 480b67c9ea42377485df5690606b138f22f3c4763c21631230be44247e1c2e90f95579dc6ce871a4c9361938430dc7c7fd4bbc1a01db3e518d72b79e8e5ac560
7
- data.tar.gz: b5aeb056db0c2386a1020116415708602db7105fa3fdabddc2db97e6e734225383961ede83283a645cfd753eaa1a0109222233ca279ad32781014319f7a3aa8f
6
+ metadata.gz: 0af87885a31cc69c7ec0cc8f1bbd7201b189b8c5f260382d990189affb7ab642b5eba050231e3e7c0a78f5d65a134c21490148d5461858c61af9ad92c813e578
7
+ data.tar.gz: 322120abe8ba4dde501c3d6cccc3a3315933d18f585d4c7eb9a86b8c147ec797c0dcb2bff8b08ac29001466eb12e2824cb29a1ef7394b5db1d8f21cbe4c31778
@@ -48,7 +48,8 @@ module RedmineRemotes
48
48
 
49
49
  ::RemoteUser.find_local_user(
50
50
  provider_issue.author_login,
51
- remote_tracker
51
+ remote_tracker,
52
+ true
52
53
  )
53
54
  end
54
55
 
@@ -11,18 +11,7 @@ class RemoteUser < ActiveRecord::Base
11
11
  validates :remote_login, presence: true, uniqueness: { scope: [:remote_tracker] }
12
12
  validates :local_user, presence: true
13
13
 
14
- class << self
15
- def find_local_user(remote_login, remote_tracker = nil)
16
- [remote_tracker, nil].each do |tracker|
17
- remote_user = ::RemoteUser.where(
18
- remote_tracker: tracker,
19
- remote_login: remote_login_sanitize(remote_login)
20
- ).first
21
- return remote_user.local_user if remote_user
22
- end
23
- return remote_tracker.default_local_user if remote_tracker.present?
24
-
25
- nil
26
- end
14
+ def self.find_local_user(remote_login, remote_tracker = nil, register_not_found = false)
15
+ ::RemoteUser::FindLocalUser.new(remote_login, remote_tracker, register_not_found).result
27
16
  end
28
17
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ class RemoteUser < ActiveRecord::Base
6
+ class FindLocalUser
7
+ common_constructor :remote_login, :remote_tracker, :register_not_found do
8
+ self.remote_login = ::RemoteUser.remote_login_sanitize(remote_login)
9
+ end
10
+
11
+ def result
12
+ result_by_local_user || result_by_remote_user || result_by_register_not_found ||
13
+ result_by_remote_tracker_default
14
+ end
15
+
16
+ private
17
+
18
+ def result_by_local_user
19
+ result_by_local_user_login || result_by_local_user_mail_address
20
+ end
21
+
22
+ def result_by_local_user_login
23
+ ::User.find_by(login: remote_login)
24
+ end
25
+
26
+ def result_by_local_user_mail_address
27
+ condition = ::EmailAddress.arel_table[:address].matches("#{remote_login}@%")
28
+ ::EmailAddress.where(condition).first.try(:user)
29
+ end
30
+
31
+ def result_by_register_not_found
32
+ return nil unless register_not_found
33
+ return nil if remote_tracker.blank?
34
+
35
+ ::RemoteUser.create!(remote_login: remote_login, remote_tracker: remote_tracker,
36
+ local_user: remote_tracker.default_local_user).local_user
37
+ end
38
+
39
+ def result_by_remote_user
40
+ remote_trackers_to_search
41
+ .map { |tracker| remote_tracker_result(tracker) }
42
+ .find(&:present?)
43
+ end
44
+
45
+ def result_by_remote_tracker_default
46
+ remote_tracker.try(:default_local_user)
47
+ end
48
+
49
+ def remote_tracker_result(remote_tracker)
50
+ ::RemoteUser.where(
51
+ remote_tracker: remote_tracker,
52
+ remote_login: remote_login
53
+ ).first.try(:local_user)
54
+ end
55
+
56
+ def remote_trackers_to_search
57
+ remote_tracker.if_present([]) { |v| [v] } + [nil]
58
+ end
59
+ end
60
+ end
@@ -3,7 +3,7 @@
3
3
  module RedmineRemotes
4
4
  SLUG = 'redmine_remotes'
5
5
  NAME = 'Redmine Remotes'
6
- VERSION = '0.9.2'
6
+ VERSION = '0.10.0'
7
7
  AUTHOR = 'Eduardo Henrique Bogoni'
8
8
  SUMMARY = 'Integração do Redmine com trackers diversos.'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_remotes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Henrique Bogoni
@@ -142,6 +142,7 @@ files:
142
142
  - app/models/remote_tracker/remote.rb
143
143
  - app/models/remote_tracker_setting.rb
144
144
  - app/models/remote_user.rb
145
+ - app/models/remote_user/find_local_user.rb
145
146
  - app/views/project_remote_issues/_issues.html.erb
146
147
  - app/views/project_remote_issues/_trackers.html.erb
147
148
  - app/views/project_remote_issues/index.html.erb