Class: SugoiAdminController
Instance Method Summary
collapse
-
#create_domain(domain_name) ⇒ Object
-
#create_list(mailinglist_name, domain_name, user_name, description = nil, mailinglist_class_id = 2) ⇒ Object
-
#create_user(domain_name, username, email_address = nil, description = nil) ⇒ Object
-
#help(command = nil) ⇒ Object
-
#init ⇒ Object
-
#list_addresses(mailinglist_address) ⇒ Object
-
#list_domains ⇒ Object
-
#list_mailinglist_classes ⇒ Object
-
#list_mailinglists(domain_name) ⇒ Object
-
#list_mlclasses ⇒ Object
-
#list_users(domain_name) ⇒ Object
-
#set_config(var_name, new_value) ⇒ Object
-
#show_config(var_name = nil) ⇒ Object
-
#subscribe(mailinglist_address, new_address) ⇒ Object
-
#unsubscribe(mailinglist_address, address_to_remove) ⇒ Object
#method_missing, #perform_action
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class CommandlineController
Instance Method Details
#create_domain(domain_name) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'app/controllers/sugoi_admin_controller.rb', line 99
def create_domain(domain_name)
@messages = []
domain = Domain.find_by_name domain_name
if domain == nil then
password, confirmation = get_password
domain = Domain.new
domain.name = domain_name
domain.password = password
domain.password_confirmation = confirmation
if domain.save then
message "Domain \"#{domain_name}\" created successfully."
else
error "Could not create domain \"#{domain_name}\":\n" +
format_errors(domain.errors).join
end
else
error "Domain \"#{domain_name}\" already exists."
end
end
|
#create_list(mailinglist_name, domain_name, user_name, description = nil, mailinglist_class_id = 2) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'app/controllers/sugoi_admin_controller.rb', line 176
def create_list mailinglist_name,
domain_name, user_name, description = nil, mailinglist_class_id = 2
mlclass = begin
MailinglistClass.find mailinglist_class_id.to_i
rescue ActiveRecord::RecordNotFound
nil
end
unless mlclass
return error("Invalid mailing list class: #{mailinglist_class_id}")
end
domain = Domain.find_by_name domain_name
unless domain
return error("Domain \"#{domain_name}\" not found.")
end
user = User.find_by_login_and_domain_id user_name, domain.id
unless user
return error("User \"#{user_name}\" not found "+
"in domain \"#{domain_name}\".")
end
ml=Mailinglist.new
ml.user = user
ml.description = description
ml.mailinglist_class = mlclass
ml.name = mailinglist_name
if ml.save then
message "Mailing list \"#{ml.address}\" created successfully."
end
end
|
#create_user(domain_name, username, email_address = nil, description = nil) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'app/controllers/sugoi_admin_controller.rb', line 120
def create_user domain_name, username,
email_address = nil,
description = nil
domain = Domain.find_by_name domain_name
if domain then
password, password_confirmation = get_password
if email_address == nil then
email_address = ask "Address to forward #{username}'s email to: "
if email_address == "" then email_address = nil end
end
description ||= ask_description(username)
user = User.new
user.domain = domain
user.login = username
user.password = password
user.password_confirmation = password_confirmation
user.description = description
user.domainadmin = false
user.mailinglistadmin = false
if user.save then
message "User \"#{username}@#{domain_name}\" created successfully"
if email_address then
addr=Address.find_or_create_by_address(email_address)
user.mailinglist.subscribe(addr)
end
else
error "User \"#{username}@#{domain_name}\" was not created:\n" +
format_errors(user.errors).join("\n")
end
else
error "Domain \"#{domain_name}\" does not exist."
end
end
|
#help(command = nil) ⇒ Object
242
243
244
245
246
247
248
|
# File 'app/controllers/sugoi_admin_controller.rb', line 242
def help(command=nil)
if command
@help = Help.find_by_facility_and_command self.class.name, command
else
@help = Help.find_all_by_facility self.class.name
end
end
|
#init ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/sugoi_admin_controller.rb', line 36
def init
@alreadythere = []
[ MailinglistClass, AdminMessage, SysConfig, Help ].each do |table|
fixture = YAML.load(File.read(File.join(RAILS_ROOT,
"test",
"fixtures",
table.name.tableize +
".yml")))
fixture.values.sort_by do |values| values["id"].to_i end .
each do |values|
begin
table.find values["id"]
@alreadythere << "%s[%s]" % [ table.name, values["id"] ]
rescue ActiveRecord::RecordNotFound
configvar = table.new values
configvar.id = values["id"].to_i configvar.save
end
end
end
end
|
#list_addresses(mailinglist_address) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'app/controllers/sugoi_admin_controller.rb', line 89
def list_addresses(mailinglist_address)
@mailinglist = Mailinglist.find_by_address(mailinglist_address)
if @mailinglist then
@mailinglist=@mailinglist[0]
@addresses = @mailinglist.addresses
else
error "#{mailinglist_address}: not found"
end
end
|
#list_domains ⇒ Object
76
77
78
|
# File 'app/controllers/sugoi_admin_controller.rb', line 76
def list_domains
@domains = Domain.find(:all)
end
|
#list_mailinglist_classes ⇒ Object
167
168
169
|
# File 'app/controllers/sugoi_admin_controller.rb', line 167
def list_mailinglist_classes
@mailinglist_classes = MailinglistClass.find :all, :order => :id
end
|
#list_mailinglists(domain_name) ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'app/controllers/sugoi_admin_controller.rb', line 80
def list_mailinglists(domain_name)
domain = Domain.find_by_name(domain_name)
if domain then
@mailinglists = domain.mailinglists
else
error "#{domain_name}: not found"
end
end
|
#list_mlclasses ⇒ Object
171
172
173
174
|
# File 'app/controllers/sugoi_admin_controller.rb', line 171
def list_mlclasses
list_mailinglist_classes
render :action => :list_mailinglist_classes
end
|
#list_users(domain_name) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'app/controllers/sugoi_admin_controller.rb', line 158
def list_users domain_name
domain = Domain.find_by_name domain_name
if domain then
@users = User.find_all_by_domain_id domain.id
else
error "Domain \"#{domain_name}\" does not exist."
end
end
|
#set_config(var_name, new_value) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/sugoi_admin_controller.rb', line 66
def set_config(var_name, new_value)
@config_var = SysConfig.find_by_name(var_name)
if @config_var then
@config_var.value = new_value
@config_var.save
else
@missing_config_name = var_name
end
end
|
#show_config(var_name = nil) ⇒ Object
58
59
60
61
62
63
64
|
# File 'app/controllers/sugoi_admin_controller.rb', line 58
def show_config(var_name=nil)
unless var_name
@config_vars = SysConfig.find(:all)
else
@config_vars = SysConfig.find_all_by_name(var_name)
end
end
|
#subscribe(mailinglist_address, new_address) ⇒ Object
210
211
212
213
214
215
216
217
218
219
|
# File 'app/controllers/sugoi_admin_controller.rb', line 210
def subscribe(mailinglist_address, new_address)
address=Address.find_or_create_by_address new_address
ml=Mailinglist.find_by_address(mailinglist_address)
unless ml
return error("Mailing list \"#{mailinglist_address}\" not found.")
end
ml=ml[0]
ml.addresses << address
message "Subscribed \"#{new_address}\" to \"#{mailinglist_address}\""
end
|
#unsubscribe(mailinglist_address, address_to_remove) ⇒ Object
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
# File 'app/controllers/sugoi_admin_controller.rb', line 221
def unsubscribe(mailinglist_address, address_to_remove)
address = Address.find_by_address address_to_remove
unless address
return error("Address \"#{address_to_remove}\" unknown.")
end
mailinglist = Mailinglist.find_by_address mailinglist_address
unless mailinglist
return error("Mailing list \"#{mailinglist_address}\" unknown.")
end
@mailinglist = mailinglist[0]
unless @mailinglist.addresses.member? address
return error("Address \"#{address}\" not in " +
"mailing list \"#{mailinglist_address}\"")
end
@removed_addresses=@mailinglist.addresses.delete address
end
|