| Class | CreateEnterprise |
| In: |
app/models/create_enterprise.rb
|
| Parent: | Task |
| DATA_FIELDS | = | %w[ name identifier address contact_phone contact_person acronym foundation_year legal_form economic_activity management_information region_id reject_explanation ] |
Approves the enterprise registration request.
# File app/models/create_enterprise.rb, line 97
97: def approve
98: finish
99: end
tells if this request was appoved
# File app/models/create_enterprise.rb, line 102
102: def approved?
103: self.status == Task::Status::FINISHED
104: end
# File app/models/create_enterprise.rb, line 127
127: def description
128: _('Enterprise registration: "%s"') % self.name
129: end
# File app/models/create_enterprise.rb, line 83
83: def environment
84: region ? region.environment : nil
85: end
actually creates the enterprise after the request is approved.
# File app/models/create_enterprise.rb, line 107
107: def perform
108: enterprise = Enterprise.new
109:
110: profile_fields = %w[ name identifier contact_phone address region_id ]
111: profile_fields.each do |field|
112: enterprise.send("#{field}=", self.send(field))
113: end
114:
115: organization_data = self.data.reject do |key,value|
116: profile_fields.include?(key.to_s)
117: end
118:
119: enterprise.environment = environment
120:
121: enterprise.user = self.requestor.user
122:
123: enterprise.update_attributes(organization_data)
124: enterprise.save!
125: end
# File app/models/create_enterprise.rb, line 169
169: def permission
170: :validate_enterprise
171: end
Rejects the enterprise registration request.
# File app/models/create_enterprise.rb, line 88
88: def reject
89: cancel
90: end
# File app/models/create_enterprise.rb, line 92
92: def rejected?
93: self.status == Task::Status::CANCELLED
94: end
# File app/models/create_enterprise.rb, line 145
145: def target_notification_message
146: msg = ""
147: msg << _("Enterprise \"%{enterprise}\" just requested to enter %{environment}. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :enterprise => self.name, :environment => self.environment }
148: msg << "\n"
149: msg << _("The data provided by the enterprise was the following:\n") << "\n"
150:
151:
152: msg << (_("Name: %s") % self.name) << "\n"
153: msg << (_("Acronym: %s") % self.acronym) << "\n"
154: msg << (_("Address: %s") % self.address) << "\n"
155: msg << (_("Legal form: %s") % self.legal_form) << "\n"
156: msg << (_("Foundation Year: %d") % self.foundation_year) << "\n" unless self.foundation_year.blank?
157: msg << (_("Economic activity: %s") % self.economic_activity) << "\n"
158:
159: msg << _("Information about enterprise's management:\n") << self.management_information.to_s << "\n"
160:
161: msg << (_("Contact phone: %s") % self.contact_phone) << "\n"
162: msg << (_("Contact person: %s") % self.contact_person) << "\n"
163:
164: msg << _('CreateEnterprise|Identifier')
165:
166: msg
167: end
# File app/models/create_enterprise.rb, line 141
141: def task_cancelled_message
142: _("Your request for registering the enterprise %{enterprise} at %{environment} was NOT approved by the validator organization. The following explanation was given: \n\n%{explanation}") % { :enterprise => self.name, :environment => self.environment, :explanation => self.reject_explanation }
143: end
# File app/models/create_enterprise.rb, line 131
131: def task_created_message
132: _('Your request for registering enterprise "%{enterprise}" at %{environment} was just received. It will be reviewed by the chosen validator organization you chose, according to its methods and creteria.
133:
134: You will be notified as soon as the validator organization has a position about your request.') % { :enterprise => self.name, :environment => self.environment }
135: end
# File app/models/create_enterprise.rb, line 137
137: def task_finished_message
138: _('Your request for registering the enterprise "%{enterprise}" was approved. You can access %{environment} now and start using it for your new enterprise.') % { :enterprise => self.name, :environment => self.environment }
139: end
# File app/models/create_enterprise.rb, line 57
57: def valid_before_selecting_target?
58: if valid?
59: true
60: else
61: self.errors.size == 1 and self.errors[:target_id]
62: end
63: end
# File app/models/create_enterprise.rb, line 45
45: def validate
46: if self.region && self.target
47: unless self.region.validators.include?(self.target)
48: self.errors.add(:target, '%{fn} is not a validator for the chosen region')
49: end
50: end
51:
52: if self.identifier && Profile.exists?(:identifier => self.identifier)
53: self.errors.add(:identifier, '%{fn} is already being as identifier by another enterprise, organization or person.')
54: end
55: end