summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorazul <azul@leap.se>2014-07-09 13:25:31 +0200
committerazul <azul@leap.se>2014-07-09 13:25:31 +0200
commitdc740e4311101bf7297996788b25a99edafbe759 (patch)
treed989456179551fb167f6c41ba4b54bbd4a77a7ac /app/controllers
parent19da5429308412c19176733d2b32ccbf2c08df1c (diff)
parent0cc11ebb609de225fbeacbf80788b992b88b6ce6 (diff)
Merge pull request #173 from azul/feature/unblock-handles
Allow admins to unblock handles
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/identities_controller.rb34
-rw-r--r--app/controllers/users_controller.rb4
-rw-r--r--app/controllers/v1/users_controller.rb2
3 files changed, 37 insertions, 3 deletions
diff --git a/app/controllers/identities_controller.rb b/app/controllers/identities_controller.rb
new file mode 100644
index 0000000..8bd3b28
--- /dev/null
+++ b/app/controllers/identities_controller.rb
@@ -0,0 +1,34 @@
+class IdentitiesController < ApplicationController
+
+ respond_to :html, :json
+ before_filter :require_login
+ before_filter :require_admin
+ before_filter :fetch_identity, only: :destroy
+ before_filter :protect_main_email, only: :destroy
+
+ def index
+ if params[:query].present?
+ @identities = Identity.address_starts_with(params[:query]).limit(100)
+ else
+ @identities = []
+ end
+ respond_with @identities.map(&:login).sort
+ end
+
+ def destroy
+ @identity.destroy
+ redirect_to identities_path
+ end
+
+ protected
+ def fetch_identity
+ @identity = Identity.find(params[:id])
+ end
+
+ def protect_main_email
+ if @identity.status == :main_email
+ flash[:error] = "You cannot destroy the main email. Remove or Rename the user instead."
+ redirect_to identities_path
+ end
+ end
+end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c8e09b6..5951413 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -12,12 +12,12 @@ class UsersController < UsersBaseController
respond_to :html
def index
- if params[:query]
+ if params[:query].present?
if @user = User.find_by_login(params[:query])
redirect_to @user
return
else
- @users = User.by_login.startkey(params[:query]).endkey(params[:query].succ)
+ @users = User.login_starts_with(params[:query])
end
else
@users = User.by_created_at.descending
diff --git a/app/controllers/v1/users_controller.rb b/app/controllers/v1/users_controller.rb
index 8897d01..006e6d8 100644
--- a/app/controllers/v1/users_controller.rb
+++ b/app/controllers/v1/users_controller.rb
@@ -11,7 +11,7 @@ module V1
# used for autocomplete for admins in the web ui
def index
if params[:query]
- @users = User.by_login.startkey(params[:query]).endkey(params[:query].succ)
+ @users = User.login_starts_with(params[:query])
respond_with @users.map(&:login).sort
else
render :json => {'error' => 'query required', 'status' => :unprocessable_entity}