Class: Readiness::SupportSuperFormProcessor::NamespaceAvailability
- Defined in:
- lib/support_readiness/support_super_form_processor/namespace_availability.rb
Overview
Defines the class NamespaceAvailability within the module Zendesk.
Class Method Summary collapse
-
.group_checks ⇒ Object
Perform the group checks for a Namesquatting Availability check request.
-
.namespace ⇒ Object
Sets the global variable namespace.
-
.namespace_does_not_exist ⇒ Object
Handles the case where the namespace does not exist.
-
.namespace_does_not_exist_message ⇒ Object
Returns the issue description for a case where the namespace does not exist.
-
.namespace_may_be_available ⇒ Object
Handles the case where the namespace may be available.
-
.namespace_may_be_available_message ⇒ Object
Returns the issue description for a case where the namespace may be available.
-
.namespace_not_available ⇒ Object
Handles the case where the namespace is not available.
-
.namespace_not_available_message ⇒ Object
Returns the issue description for a case where the namespace is not available.
-
.namespace_to_check ⇒ Object
Sets the global variable namespace_to_check.
-
.process!(client, admin_client) ⇒ Object
Process a Namesquatting Availability check request.
-
.project ⇒ Object
Sets the global variable project.
-
.requester ⇒ Object
Sets the global variable requester.
-
.requester_email ⇒ Object
Sets the global variable requester_email.
-
.user_checks ⇒ Object
Perform the user checks for a Namesquatting Availability check request.
-
.user_created_recently?(user) ⇒ Boolean
Determines if a user was created recently.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Class Method Details
.group_checks ⇒ Object
Perform the group checks for a Namesquatting Availability check request
57 58 59 60 61 62 63 64 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 57 def self.group_checks group = Readiness::GitLab::Groups.new group.id = namespace.id projects = Readiness::GitLab::Groups.projects(@gitlab_admin_client, group, ["archived=false", "include_subgroups=true"]) detection = projects.detect { |p| (Date.today - 2.years) < Date.parse(p.last_activity_at) } namespace_may_be_available if detection.nil? namespace_not_available end |
.namespace ⇒ Object
Sets the global variable namespace
107 108 109 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 107 def self.namespace @namespace ||= Readiness::GitLab::Namespaces.find!(@gitlab_admin_client, namespace_to_check) end |
.namespace_does_not_exist ⇒ Object
Handles the case where the namespace does not exist
116 117 118 119 120 121 122 123 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 116 def self.namespace_does_not_exist issue = Readiness::GitLab::Issues.new issue.title = "Namespace Availability Check - #{CGI.escape(namespace_to_check)}" issue.description = create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue) puts "Issue created: #{create.web_url}" exit 0 end |
.namespace_does_not_exist_message ⇒ Object
Returns the issue description for a case where the namespace does not exist
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 179 def self. <<~STRING ## Namespace Availability Check for #{CGI.escape(namespace_to_check)} Greetings @#{requester.username} ! We have looked into the availability of the namespace #{CGI.escape(namespace_to_check)} and have been unable to locate the namespace on gitlab.com. This would mean it is not currently in use at all and should be available at this exact moment in time. /label ~"AutomatedRequests::Namespace Availability Check" ~p4 ~administrative ~"Stage::Completed" /iteration [cadence:"Customer Support Operations"] --current /assign @#{requester.username} STRING end |
.namespace_may_be_available ⇒ Object
Handles the case where the namespace may be available
144 145 146 147 148 149 150 151 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 144 def self.namespace_may_be_available issue = Readiness::GitLab::Issues.new issue.title = "Namespace Availability Check - #{CGI.escape(namespace_to_check)}" issue.description = create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue) puts "Issue created: #{create.web_url}" exit 0 end |
.namespace_may_be_available_message ⇒ Object
Returns the issue description for a case where the namespace may be available
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 200 def self. <<~STRING ## Namespace Availability Check for #{CGI.escape(namespace_to_check)} Greetings @#{requester.username} ! We have looked into the availability of the namespace #{CGI.escape(namespace_to_check)} and have determined it _may_ be available for release at this time. Please note this only reflects the _possibility_ of release _at this exact time_. Any number of factors or events could change in the future to change this determination. /label ~"AutomatedRequests::Namespace Availability Check" ~p4 ~administrative ~"Stage::Completed" /iteration [cadence:"Customer Support Operations"] --current /assign @#{requester.username} STRING end |
.namespace_not_available ⇒ Object
Handles the case where the namespace is not available
130 131 132 133 134 135 136 137 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 130 def self.namespace_not_available issue = Readiness::GitLab::Issues.new issue.title = "Namespace Availability Check - #{CGI.escape(namespace_to_check)}" issue.description = create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue) puts "Issue created: #{create.web_url}" exit 0 end |
.namespace_not_available_message ⇒ Object
Returns the issue description for a case where the namespace is not available
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 158 def self. <<~STRING ## Namespace Availability Check for #{CGI.escape(namespace_to_check)} Greetings @#{requester.username} ! We have looked into the availability of the namespace #{CGI.escape(namespace_to_check)} and have determined it will not be available for release at this time. /label ~"AutomatedRequests::Namespace Availability Check" ~p4 ~administrative ~"Stage::Completed" /iteration [cadence:"Customer Support Operations"] --current /assign @#{requester.username} STRING end |
.namespace_to_check ⇒ Object
Sets the global variable namespace_to_check
80 81 82 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 80 def self.namespace_to_check @namespace_to_check ||= ENV.fetch('NAMESPACE') end |
.process!(client, admin_client) ⇒ Object
Process a Namesquatting Availability check request
18 19 20 21 22 23 24 25 26 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 18 def self.process!(client, admin_client) @gitlab_client = client @gitlab_admin_client = admin_client requester namespace_does_not_exist unless Readiness::GitLab::Namespaces.exists?(@gitlab_admin_client, namespace_to_check) namespace_not_available if Readiness::GitLab::Namespaces.is_paid?(@gitlab_admin_client, namespace) user_checks if namespace.kind. == 'user' group_checks if namespace.kind == 'group' end |
.project ⇒ Object
Sets the global variable project
98 99 100 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 98 def self.project @project ||= Readiness::GitLab::Projects.find!(@gitlab_client, 68534119) end |
.requester ⇒ Object
Sets the global variable requester
71 72 73 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 71 def self.requester @requester ||= Readiness::SupportSuperFormProcessor::Shared.gitlab_user_check(@gitlab_admin_client, requester_email) end |
.requester_email ⇒ Object
Sets the global variable requester_email
89 90 91 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 89 def self.requester_email @requester_email ||= ENV.fetch('REQUESTER_EMAIL') end |
.user_checks ⇒ Object
Perform the user checks for a Namesquatting Availability check request
33 34 35 36 37 38 39 40 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 33 def self.user_checks search = Readiness::GitLab::Users.search_by_username(@gitlab_admin_client, namespace_to_check) user = search.detect { |s| s.username.downcase == namespace_to_check.downcase } namespace_may_be_available if user.confirmed_at.nil? && user_created_recently?(user) namespace_not_available if (Date.today - 2.years) < Date.parse(user.current_sign_in_at) namespace_not_available if Readiness::GitLab::Users.only_maintainer?(@gitlab_admin_client, user) namespace_may_be_available end |
.user_created_recently?(user) ⇒ Boolean
Determines if a user was created recently
48 49 50 |
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 48 def self.user_created_recently?(user) (Date.today - 90.days) < Date.parse(user.created_at) end |