lesli 5.0.20 → 5.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,122 +0,0 @@
1
- =begin
2
-
3
- Lesli
4
-
5
- Copyright (c) 2023, Lesli Technologies, S. A.
6
-
7
- This program is free software: you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License as published by
9
- the Free Software Foundation, either version 3 of the License, or
10
- (at your option) any later version.
11
-
12
- This program is distributed in the hope that it will be useful,
13
- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- GNU General Public License for more details.
16
-
17
- You should have received a copy of the GNU General Public License
18
- along with this program. If not, see http://www.gnu.org/licenses/.
19
-
20
- Lesli · Ruby on Rails Development Platform.
21
-
22
- Made with ♥ by https://www.lesli.tech
23
- Building a better future, one line of code at a time.
24
-
25
- @contact hello@lesli.tech
26
- @website https://www.lesli.tech
27
- @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
-
29
- // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
- // ·
31
-
32
- =end
33
-
34
- module Lesli
35
- class UserRegistrationOperator < Lesli::ApplicationLesliService
36
-
37
- def initialize(current_user)
38
- @resource = current_user
39
- @current_user = current_user
40
- end
41
-
42
- def confirm
43
-
44
- if current_user.blank?
45
- failures.push(I18n.t("core.shared.messages_warning_user_not_found"))
46
- return self
47
- end
48
-
49
- # confirm the user
50
- current_user.confirm
51
-
52
- # force token deletion so we are sure nobody will be able to use the token again
53
- resource.update(confirmation_token: nil)
54
-
55
- # send a welcome email to user as is confirmed
56
- #UserMailer.with(user: resource).welcome.deliver_later
57
-
58
- # initialize user dependencies
59
- current_user.after_confirmation_user
60
-
61
- end
62
-
63
- def create_account
64
-
65
- if resource.blank?
66
- failures.push(I18n.t("core.shared.messages_warning_user_not_found"))
67
- return self
68
- end
69
-
70
- if resource.account
71
- failures.push(I18n.t("core.users.messages_info_user_already_belongs_to_account"))
72
- return self
73
- end
74
-
75
- # check if instance is for multi-account
76
- allow_multiaccount = Lesli.config.security.dig(:allow_multiaccount)
77
-
78
- # create new account for the new user only if multi-account is allowed
79
- if allow_multiaccount === true
80
- account = Account.create!({
81
- user: resource, # set user as owner of his just created account
82
- name: "Lesli", # temporary company name
83
- email: resource.email,
84
- status: :active # account is active due user already confirmed his email
85
- })
86
- end
87
-
88
- # if multi-account is not allowed user belongs to the first account in instance
89
- if allow_multiaccount === false
90
- account = Account.first
91
- end
92
-
93
- # add user to his own account
94
- resource.account = account
95
-
96
- # add owner role to user only if multi-account is allowed
97
- if allow_multiaccount == true
98
- #resource.powers.create({ role: account.roles.find_by(name: "owner") })
99
- end
100
-
101
- # add profile role to user only if multi-account is allowed
102
- if allow_multiaccount == false
103
- # Assigning default role if defined in account settings
104
- # Otherwise, the default role is "limited"
105
- #default_role_id = account.settings.find_by(:name => "default_role_id")&.value
106
-
107
- if default_role_id.present?
108
- resource.user_roles.create({ role: account.roles.find_by(:id => default_role_id)})
109
- else
110
- resource.user_roles.create({ role: account.roles.find_by(name: "limited") })
111
- end
112
- end
113
-
114
- # update user :)
115
- resource.save
116
-
117
- # initialize user dependencies
118
- resource.after_account_assignation
119
-
120
- end
121
- end
122
- end