From ef449d7f8ab740c21688f8ca20451512ff4c05c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Sat, 6 Apr 2019 14:31:04 +0200
Subject: [PATCH] misc: remove obsolete user search cell (#32039)

---
 MANIFEST.in                                   |  2 -
 combo/apps/usersearch/__init__.py             | 28 -----------
 .../usersearch/migrations/0001_initial.py     | 32 ------------
 .../0002_usersearchcell_extra_css_class.py    | 19 -------
 ...03_usersearchcell_last_update_timestamp.py | 22 --------
 combo/apps/usersearch/migrations/__init__.py  |  0
 combo/apps/usersearch/models.py               | 44 ----------------
 combo/apps/usersearch/static/js/usersearch.js | 21 --------
 .../templates/combo/usersearch.html           | 11 ----
 combo/apps/usersearch/urls.py                 | 24 ---------
 combo/apps/usersearch/views.py                | 50 -------------------
 combo/settings.py                             |  1 -
 12 files changed, 254 deletions(-)
 delete mode 100644 combo/apps/usersearch/__init__.py
 delete mode 100644 combo/apps/usersearch/migrations/0001_initial.py
 delete mode 100644 combo/apps/usersearch/migrations/0002_usersearchcell_extra_css_class.py
 delete mode 100644 combo/apps/usersearch/migrations/0003_usersearchcell_last_update_timestamp.py
 delete mode 100644 combo/apps/usersearch/migrations/__init__.py
 delete mode 100644 combo/apps/usersearch/models.py
 delete mode 100644 combo/apps/usersearch/static/js/usersearch.js
 delete mode 100644 combo/apps/usersearch/templates/combo/usersearch.html
 delete mode 100644 combo/apps/usersearch/urls.py
 delete mode 100644 combo/apps/usersearch/views.py

diff --git a/MANIFEST.in b/MANIFEST.in
index 2479c5e4..18584155 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -2,7 +2,6 @@
 recursive-include combo/locale *.po *.mo
 
 # static
-recursive-include combo/apps/usersearch/static *.css *.js *.ico *.gif *.png *.jpg
 recursive-include combo/apps/lingo/static *.css *.js *.ico *.gif *.png *.jpg
 recursive-include combo/apps/dataviz/static *.css *.js *.ico *.gif *.png *.jpg
 recursive-include combo/apps/dashboard/static *.js
@@ -17,7 +16,6 @@ recursive-include combo/apps/assets/templates *.html
 recursive-include combo/apps/calendar/templates *.html
 recursive-include combo/apps/dashboard/templates *.html
 recursive-include combo/apps/search/templates *.html
-recursive-include combo/apps/usersearch/templates *.html
 recursive-include combo/apps/dataviz/templates *.html
 recursive-include combo/apps/family/templates *.html
 recursive-include combo/apps/fargo/templates *.html
diff --git a/combo/apps/usersearch/__init__.py b/combo/apps/usersearch/__init__.py
deleted file mode 100644
index 50404108..00000000
--- a/combo/apps/usersearch/__init__.py
+++ /dev/null
@@ -1,28 +0,0 @@
-# combo - content management system
-# Copyright (C) 2014-2016  Entr'ouvert
-#
-# This program is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Affero General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-import django.apps
-from django.utils.translation import ugettext_lazy as _
-
-class AppConfig(django.apps.AppConfig):
-    name = 'combo.apps.usersearch'
-    verbose_name = _('Backoffice User Search')
-
-    def get_before_urls(self):
-        from . import urls
-        return urls.urlpatterns
-
-default_app_config = 'combo.apps.usersearch.AppConfig'
diff --git a/combo/apps/usersearch/migrations/0001_initial.py b/combo/apps/usersearch/migrations/0001_initial.py
deleted file mode 100644
index 88732871..00000000
--- a/combo/apps/usersearch/migrations/0001_initial.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import models, migrations
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('auth', '0001_initial'),
-        ('data', '0015_feedcell_title'),
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name='UserSearchCell',
-            fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('placeholder', models.CharField(max_length=20)),
-                ('order', models.PositiveIntegerField()),
-                ('slug', models.SlugField(verbose_name='Slug', blank=True)),
-                ('public', models.BooleanField(default=True, verbose_name='Public')),
-                ('restricted_to_unlogged', models.BooleanField(default=False, verbose_name='Restrict to unlogged users')),
-                ('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
-                ('page', models.ForeignKey(to='data.Page')),
-            ],
-            options={
-                'verbose_name': 'User Search',
-            },
-            bases=(models.Model,),
-        ),
-    ]
diff --git a/combo/apps/usersearch/migrations/0002_usersearchcell_extra_css_class.py b/combo/apps/usersearch/migrations/0002_usersearchcell_extra_css_class.py
deleted file mode 100644
index 63efa70e..00000000
--- a/combo/apps/usersearch/migrations/0002_usersearchcell_extra_css_class.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('usersearch', '0001_initial'),
-    ]
-
-    operations = [
-        migrations.AddField(
-            model_name='usersearchcell',
-            name='extra_css_class',
-            field=models.CharField(max_length=100, verbose_name='Extra classes for CSS styling', blank=True),
-        ),
-    ]
diff --git a/combo/apps/usersearch/migrations/0003_usersearchcell_last_update_timestamp.py b/combo/apps/usersearch/migrations/0003_usersearchcell_last_update_timestamp.py
deleted file mode 100644
index a4e63b79..00000000
--- a/combo/apps/usersearch/migrations/0003_usersearchcell_last_update_timestamp.py
+++ /dev/null
@@ -1,22 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
-import datetime
-from django.utils.timezone import utc
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('usersearch', '0002_usersearchcell_extra_css_class'),
-    ]
-
-    operations = [
-        migrations.AddField(
-            model_name='usersearchcell',
-            name='last_update_timestamp',
-            field=models.DateTimeField(default=datetime.datetime.now(utc), auto_now=True),
-            preserve_default=False,
-        ),
-    ]
diff --git a/combo/apps/usersearch/migrations/__init__.py b/combo/apps/usersearch/migrations/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/combo/apps/usersearch/models.py b/combo/apps/usersearch/models.py
deleted file mode 100644
index f1f38c18..00000000
--- a/combo/apps/usersearch/models.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# combo - content management system
-# Copyright (C) 2014-2016  Entr'ouvert
-#
-# This program is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Affero General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-from django.conf import settings
-from django.utils.translation import ugettext_lazy as _
-from django.contrib.auth.models import User
-
-from combo.data.models import CellBase
-from combo.data.library import register_cell_class
-
-
-@register_cell_class
-class UserSearchCell(CellBase):
-    template_name = 'combo/usersearch.html'
-
-    class Media:
-        js = ('js/usersearch.js',)
-
-    class Meta:
-        verbose_name = _('User Search')
-
-    @classmethod
-    def is_enabled(cls):
-        return settings.USERSEARCH_CELL_ENABLED
-
-    def is_visible(self, user=None):
-        return super(UserSearchCell, self).is_visible(user=user)
-
-    def modify_global_context(self, context, request):
-        if 'selected_user_id' in request.GET:
-            context['selected_user'] = User.objects.get(pk=request.GET['selected_user_id'])
diff --git a/combo/apps/usersearch/static/js/usersearch.js b/combo/apps/usersearch/static/js/usersearch.js
deleted file mode 100644
index 83807204..00000000
--- a/combo/apps/usersearch/static/js/usersearch.js
+++ /dev/null
@@ -1,21 +0,0 @@
-$(function() {
-  $('.usersearch').delegate('input', 'keyup', function() {
-    var q = $(this).val();
-    var search_result_ul = $(this).parent().find('ul.result');
-    search_result_ul.empty();
-    $.getJSON($(this).data('autocomplete-json'),
-            {'q': q},
-            function (response) {
-                    search_result_ul.empty();
-                    $(response).each(function(idx, elem) {
-                       var new_elem = '<li><a href="?selected_user_id=' + encodeURIComponent(elem.pk) + '">';
-                       new_elem = new_elem + elem.fields.first_name + ' ' + elem.fields.last_name;
-                       new_elem = new_elem + ' <span class="email">' + elem.fields.email + '</span>';
-                       new_elem = new_elem + '</a></li>'
-                       $(new_elem).appendTo(search_result_ul);
-                    });
-            }
-    );
-    return false;
-  });
-});
diff --git a/combo/apps/usersearch/templates/combo/usersearch.html b/combo/apps/usersearch/templates/combo/usersearch.html
deleted file mode 100644
index baa958f0..00000000
--- a/combo/apps/usersearch/templates/combo/usersearch.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{% load i18n %}
-<div class="usersearch">
-  <input type="text" autocomplete="off" placeholder="{% trans 'Name, email, etc.' %}" data-autocomplete-json="{% url 'combo-ajax-usersearch' %}" name="q" />
-  <ul class="result"></ul>
-  {% if selected_user %}
-  <div class="selected-user">
-    {% trans "Selected user is:" %} {{ selected_user.first_name }} {{ selected_user.last_name }}
-    <span class="email">{{ selected_user.email }}</span>
-  </div>
-  {% endif %}
-</div>
diff --git a/combo/apps/usersearch/urls.py b/combo/apps/usersearch/urls.py
deleted file mode 100644
index 00e25775..00000000
--- a/combo/apps/usersearch/urls.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# combo - content management system
-# Copyright (C) 2014-2016  Entr'ouvert
-#
-# This program is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Affero General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-from django.conf.urls import url
-
-from .views import ajax_usersearch
-
-urlpatterns = [
-    url(r'^ajax/usersearch/$',
-        ajax_usersearch, name='combo-ajax-usersearch'),
-]
diff --git a/combo/apps/usersearch/views.py b/combo/apps/usersearch/views.py
deleted file mode 100644
index 81d7286c..00000000
--- a/combo/apps/usersearch/views.py
+++ /dev/null
@@ -1,50 +0,0 @@
-# combo - content management system
-# Copyright (C) 2014-2016  Entr'ouvert
-#
-# This program is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Affero General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-import json
-
-from django.http import HttpResponse
-from django.contrib.auth.models import User
-from django.db.models import Q
-from django.core import serializers
-from django.core.exceptions import PermissionDenied
-
-from .models import UserSearchCell
-
-
-def ajax_usersearch(request):
-    # allow access if the user can see at least one UserSearch cell
-    for cell in UserSearchCell.objects.all():
-        if cell.is_visible(request.user) and cell.page.is_visible(request.user):
-            break
-    else:
-        raise PermissionDenied
-    query = request.GET.get('q')
-    if query:
-        users = User.objects.all()
-        # pseudo full-text search
-        for elem in query.split():
-            users = users.filter(Q(username__icontains=elem)
-                                 |Q(first_name__icontains=elem)
-                                 |Q(last_name__icontains=elem)
-                                 |Q(email__icontains=elem))
-        users = json.loads(serializers.serialize(
-            'json', users[:10], fields=('username', 'first_name', 'last_name', 'email')))
-    else:
-        users = []
-    response = HttpResponse(content_type='application/json')
-    json.dump(users, response, indent=2)
-    return response
diff --git a/combo/settings.py b/combo/settings.py
index efd582e6..a621b673 100644
--- a/combo/settings.py
+++ b/combo/settings.py
@@ -73,7 +73,6 @@ INSTALLED_APPS = (
     'combo.apps.fargo',
     'combo.apps.notifications',
     'combo.apps.search',
-    'combo.apps.usersearch',
     'combo.apps.maps',
     'combo.apps.calendar',
     'combo.apps.pwa',
-- 
2.20.1

