summaryrefslogtreecommitdiff
path: root/app/controllers/v1
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-05-01 10:55:33 -0300
committerAzul <azul@riseup.net>2016-05-18 20:07:41 +0200
commite05a1b0f5ae40a2aa17976b3009cd563b8e4660a (patch)
tree77774fd7e70211febaf3a15c6e3b3e7340843c11 /app/controllers/v1
parenta1b494e334406660a1f49fb7de9b043493809640 (diff)
api: allow version bumping - bump to 2
Diffstat (limited to 'app/controllers/v1')
-rw-r--r--app/controllers/v1/certs_controller.rb31
-rw-r--r--app/controllers/v1/configs_controller.rb37
-rw-r--r--app/controllers/v1/identities_controller.rb16
-rw-r--r--app/controllers/v1/messages_controller.rb119
-rw-r--r--app/controllers/v1/services_controller.rb8
-rw-r--r--app/controllers/v1/sessions_controller.rb44
-rw-r--r--app/controllers/v1/smtp_certs_controller.rb42
-rw-r--r--app/controllers/v1/users_controller.rb83
8 files changed, 0 insertions, 380 deletions
diff --git a/app/controllers/v1/certs_controller.rb b/app/controllers/v1/certs_controller.rb
deleted file mode 100644
index ffa6e35..0000000
--- a/app/controllers/v1/certs_controller.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-class V1::CertsController < ApiController
-
- before_filter :require_login, :unless => :anonymous_access_allowed?
- before_filter :require_enabled
-
- # GET /cert
- # deprecated - we actually create a new cert and that can
- # be reflected in the action. GET /cert will eventually go
- # away and be replaced by POST /cert
- def show
- create
- end
-
- # POST /cert
- def create
- @cert = ClientCertificate.new(:prefix => service_level.cert_prefix)
- render text: @cert.to_s, content_type: 'text/plain'
- end
-
- protected
-
- def require_enabled
- if !current_user.is_anonymous? && !current_user.enabled?
- access_denied
- end
- end
-
- def service_level
- current_user.effective_service_level
- end
-end
diff --git a/app/controllers/v1/configs_controller.rb b/app/controllers/v1/configs_controller.rb
deleted file mode 100644
index f0b284e..0000000
--- a/app/controllers/v1/configs_controller.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-class V1::ConfigsController < ApiController
- include ControllerExtension::JsonFile
-
- before_filter :require_login, :unless => :anonymous_access_allowed?
- before_filter :sanitize_id, only: :show
-
- def index
- render json: {services: service_paths}
- end
-
- def show
- send_file lookup_file
- end
-
- protected
-
- SERVICE_IDS = {
- soledad: "soledad-service",
- eip: "eip-service",
- smtp: "smtp-service"
- }
-
- def service_paths
- Hash[SERVICE_IDS.map{|k,v| [k,"/1/configs/#{v}.json"] } ]
- end
-
- def sanitize_id
- @id = params[:id].downcase
- access_denied unless SERVICE_IDS.values.include? @id
- end
-
- def lookup_file
- path = APP_CONFIG[:config_file_paths][@id]
- not_found if path.blank?
- Rails.root.join path
- end
-end
diff --git a/app/controllers/v1/identities_controller.rb b/app/controllers/v1/identities_controller.rb
deleted file mode 100644
index 4efd1f5..0000000
--- a/app/controllers/v1/identities_controller.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-module V1
- class IdentitiesController < ApiController
- before_filter :token_authenticate
- before_filter :require_monitor
-
- def show
- @identity = Identity.find_by_address(params[:id])
- if @identity
- respond_with @identity
- else
- render_not_found
- end
- end
-
- end
-end
diff --git a/app/controllers/v1/messages_controller.rb b/app/controllers/v1/messages_controller.rb
deleted file mode 100644
index c0ca0c7..0000000
--- a/app/controllers/v1/messages_controller.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-module V1
- class MessagesController < ApiController
-
- before_filter :require_login
-
- def index
- if Dir.exist?(motd_dir)
- if !CommonLanguages::available_code?(params[:locale])
- locale = 'en'
- else
- locale = params[:locale]
- end
- render json: motd_files_for_locale(locale)
- else
- render json: []
- end
- end
-
- # disable per-user messages for now, not supported in the client
- #def update
- # if message = Message.find(params[:id])
- # message.mark_as_read_by(current_user)
- # message.save
- # render json: success(:marked_as_read)
- # else
- # render json: error(:not_found), status: :not_found
- # end
- #end
-
- private
-
- #
- # returns list of messages, for example:
- #
- # [
- # {"id": 1, "locale": "en", "text": "<message text>"},
- # {"id": 2, "locale": "en", "text": "<message text>"}
- # ]
- #
- # Each message is present only once, using the best choice
- # for the locale. The order is determined by the id.
- #
- def motd_files_for_locale(locale)
- files = []
- motd_files.keys.each do |id|
- if motd_files[id].key?(locale)
- msg_locale = locale
- elsif motd_files[id].key?('en')
- msg_locale = 'en'
- else
- msg_locale = motd_files[id].keys.first
- end
- files << {
- "id" => id,
- "locale" => msg_locale,
- "text" => motd_files[id][msg_locale]
- }
- end
- files.sort! {|a,b| a["id"].to_i <=> b["id"].to_i }
- return files
- end
-
- #
- # returns messages of the day as a hash:
- # { "1": {"en": "message"}, "2": {"en": "message"} }
- #
- def motd_files
- if motd_changed? || @motd_files.nil?
- @motd_files = load_motd_files
- else
- @motd_files
- end
- end
-
- def motd_changed?
- newest = Dir.glob(File.join(motd_dir, '*.{html,md}')).collect{|file| File.mtime(file)}.max
- if @timestamp.nil?
- @timestamp = newest
- return true
- elsif @timestamp < newest
- @timestamp = newest
- return true
- else
- return false
- end
- end
-
- def load_motd_files
- files = {}
- Dir.glob(File.join(motd_dir, '*.{html,md}')).each do |file|
- id, locale, msg = parse_motd_file(file)
- next unless id
- files[id] ||= {}
- files[id][locale] = msg
- end
- files
- end
-
- def parse_motd_file(file)
- id, locale, ext = File.basename(file).split('.')
- if id.nil? || locale.nil? || ext.nil? || id.to_i.to_s != id || !['md', 'html'].include?(ext)
- Rails.logger.error "ERROR: Could not parse MOTD file #{file}"
- return nil
- end
- contents = File.read(file)
- if ext == "md"
- msg = RDiscount.new(contents, :autolink).to_html
- elsif ext == "html"
- msg = File.read(file)
- end
- return id, locale, msg
- end
-
- def motd_dir
- File.join(APP_CONFIG['customization_directory'], 'motd')
- end
-
- end
-end
diff --git a/app/controllers/v1/services_controller.rb b/app/controllers/v1/services_controller.rb
deleted file mode 100644
index 523eb44..0000000
--- a/app/controllers/v1/services_controller.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class V1::ServicesController < ApiController
-
- before_filter :require_login, :unless => :anonymous_access_allowed?
-
- def show
- respond_with current_user.effective_service_level
- end
-end
diff --git a/app/controllers/v1/sessions_controller.rb b/app/controllers/v1/sessions_controller.rb
deleted file mode 100644
index a343d9b..0000000
--- a/app/controllers/v1/sessions_controller.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-module V1
- class SessionsController < ApiController
-
- before_filter :require_login, only: :destroy
-
- def new
- @session = Session.new
- if authentication_errors
- @errors = authentication_errors
- render :status => 422
- end
- end
-
- def create
- logout if logged_in?
- if params['A']
- authenticate!
- else
- @user = User.find_by_login(params['login'])
- render :json => {salt: @user.salt}
- end
- end
-
- def update
- authenticate!
- @token = Token.create(:user_id => current_user.id)
- session[:token] = @token.id
- render :json => login_response
- end
-
- def destroy
- logout
- head :no_content
- end
-
- protected
-
- def login_response
- handshake = session.delete(:handshake) || {}
- handshake.to_hash.merge(:id => current_user.id, :token => @token.to_s)
- end
-
- end
-end
diff --git a/app/controllers/v1/smtp_certs_controller.rb b/app/controllers/v1/smtp_certs_controller.rb
deleted file mode 100644
index 5760645..0000000
--- a/app/controllers/v1/smtp_certs_controller.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-class V1::SmtpCertsController < ApiController
-
- before_filter :require_login
- before_filter :require_email_account
- before_filter :fetch_identity
- before_filter :require_enabled
-
- # POST /1/smtp_cert
- def create
- @cert = ClientCertificate.new common_name: current_user.email_address
- @identity.register_cert(@cert)
- @identity.save
- render text: @cert.to_s, content_type: 'text/plain'
- end
-
- protected
-
- #
- # Filters
- #
-
- def require_email_account
- access_denied unless service_level.provides? 'email'
- end
-
- def require_enabled
- access_denied unless current_user.enabled?
- end
-
- def fetch_identity
- @identity = current_user.identity
- end
-
- #
- # Helper methods
- #
-
- def service_level
- current_user.effective_service_level
- end
-
-end
diff --git a/app/controllers/v1/users_controller.rb b/app/controllers/v1/users_controller.rb
deleted file mode 100644
index 6640d10..0000000
--- a/app/controllers/v1/users_controller.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-module V1
- class UsersController < ApiController
- include ControllerExtension::FetchUser
-
- # allow optional access to this controller using API auth tokens:
- before_filter :token_authenticate
-
- before_filter :fetch_user, :only => [:update, :destroy]
- before_filter :require_monitor, :only => [:index, :show]
- before_filter :require_login, :only => [:index, :update, :destroy]
-
- respond_to :json
-
- # used for autocomplete for admins in the web ui
- def index
- if params[:query]
- @users = User.login_starts_with(params[:query])
- respond_with @users.map(&:login).sort
- else
- render :json => {'error' => 'query required', 'status' => :unprocessable_entity}
- end
- end
-
- def show
- if params[:login]
- @user = User.find_by_login(params[:login])
- elsif params[:id]
- @user = User.find(params[:id])
- end
- if @user
- respond_with @user
- else
- not_found
- end
- end
-
- def create
- if current_user.is_monitor?
- create_test_account
- elsif APP_CONFIG[:allow_registration]
- create_account
- else
- head :forbidden
- end
- end
-
- def update
- @user.account.update params[:user]
- respond_with @user
- end
-
- def destroy
- destroy_identity = current_user.is_monitor? || params[:identities] == "destroy"
- @user.account.destroy(destroy_identity)
- if @user == current_user
- logout
- end
- render :json => {'success' => 'user deleted'}
- end
-
- private
-
- # tester auth can only create test users.
- def create_test_account
- if User::is_test?(params[:user][:login])
- @user = Account.create(params[:user], :invite_required => false)
- respond_with @user
- else
- head :forbidden
- end
- end
-
- def create_account
- if APP_CONFIG[:allow_registration]
- @user = Account.create(params[:user])
- respond_with @user # return ID instead?
- else
- head :forbidden
- end
- end
-
- end
-end