class MailAdminController < ApplicationController def list_admin_messages @mailinglist = Mailinglist.find_by_id(params[:id]) @adminmessages = AdminMessage.find(@mailinglist.welcome_admin_message_id, @mailinglist.confirmed_admin_message_id, @mailinglist.sayonara_admin_message_id) end def edit_admin_message if request.post? @adminmessage = AdminMessage.find(params[:id]) if @adminmessage.update_attributes(params[:adminmessage]) if @adminmessage.save flash[:notice] = 'The admin message was successfully edited.' session[:user] = User.find session[:user].id redirect_to :controller => 'mailinglist', :action => 'show', :id => params[:id] end end else @adminmessage = AdminMessage.find(params[:id]) end end def new_admin_message end def remove_admin_message end # # private # def get_password # password = ask "Password: " do |q| q.echo = false end # confirmation = ask "Confirm: " do |q| q.echo = false end # # return [ password, confirmation ] # end # # def format_errors errors # errors.map do |facility, text| # " #{facility}: #{text}\n" # end # end # # def error(error_text) # callername = caller[0].gsub(/.*\`(\w+)\'.*/, '\1') # @error = "#{callername}: #{error_text}" # nil # end # # def message(message_text) # callername = caller[0].gsub(/.*\`(\w+)\'.*/, '\1') # @messages ||= [] # @messages << "#{callername}: #{message_text}" # end # # def ask_description(thing) # description = ask "Description for #{thing}: " # if description == "" then description = nil end # description # end # # public # # 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 # hohoho # configvar.save # end # end # end # end # # 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 # # def set_config(var_name, new_value) # @config_var = SysConfig.find_by_name(var_name) # @config_var.value = new_value # @config_var.save # end # # def list_domains # @domains = Domain.find_all # end # # 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 # # 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 # # 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 # # 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.mailadmin = 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.addresses << 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 # # 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 # # def list_mailinglist_classes # @mailinglist_classes = MailinglistClass.find :all, :order => :id # end # # def list_mlclasses # list_mailinglist_classes # render "sugoi_admin/list_mailinglist_classes" # end # # 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 # # 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 # # 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.remove_addresses address # end # # 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 end