Skip to content

Commit

Permalink
Merge pull request #1931 from tracim/fix/1930_remove_search_enabled_p…
Browse files Browse the repository at this point in the history
…arameter

Fix/1930 remove search enabled parameter
  • Loading branch information
buxx committed Jun 17, 2019
2 parents e917fef + 3e60aba commit ff6e819
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 121 deletions.
1 change: 0 additions & 1 deletion backend/cypress_test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ caldav.radicale.headers.Access-Control-Expose-Headers = Etag
####
# SEARCH (ElasticSearch)
####
search.enabled = True
# choose search engine to use, available value are: simple, elasticsearch.
# simple need nothing more than tracim but features are limited,
# elasticsearch is more effective but need an elasticsearch server.
Expand Down
1 change: 0 additions & 1 deletion backend/development.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ caldav.radicale.headers.Access-Control-Expose-Headers = Etag
####
# SEARCH (ElasticSearch)
####
search.enabled = False
# choose search engine to use, available value are: simple, elasticsearch.
# simple need nothing more than tracim but features are limited,
# elasticsearch is more effective but need an elasticsearch server.
Expand Down
1 change: 0 additions & 1 deletion backend/doc/setting.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ First, you need an elastic_search server. An easy way to have one with docker ca

You then need to setup config file:

search.enabled = True
search.elasticsearch.host = localhost
search.elasticsearch.port = 9200

Expand Down
18 changes: 0 additions & 18 deletions backend/tests_configs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ email.notification.enabled_on_invitation = False
webdav.ui.enabled = False
webdav.base_url = https://localhost:3030
webdav.root_path = /
search.enabled = True
search.engine = simple

[functional_test_elasticsearch_search]
Expand All @@ -168,7 +167,6 @@ email.notification.enabled_on_invitation = False
webdav.ui.enabled = False
webdav.base_url = https://localhost:3030
webdav.root_path = /
search.enabled = True
search.engine = elasticsearch
search.elasticsearch.use_ingest = False
search.elasticsearch.host = localhost
Expand All @@ -186,27 +184,11 @@ email.notification.enabled_on_invitation = False
webdav.ui.enabled = False
webdav.base_url = https://localhost:3030
webdav.root_path = /
search.enabled = True
search.engine = elasticsearch
search.elasticsearch.use_ingest = True
search.elasticsearch.host = localhost
search.elasticsearch.port = 9200


[functional_test_no_search]
app.enabled = contents/thread,contents/file,contents/html-document,contents/folder
api.key = mysuperapikey
preview.jpg.restricted_dims = True
email.notification.activated = false
website.base_url = http://localhost:6543
user.reset_password.token_lifetime = 5
frontend.serve = False
email.notification.enabled_on_invitation = False
webdav.ui.enabled = False
webdav.base_url = https://localhost:3030
webdav.root_path = /
search.enabled = False

[functional_test_remote_auth]
app.enabled = contents/thread,contents/file,contents/html-document,contents/folder
api.key = mysuperapikey
Expand Down
16 changes: 8 additions & 8 deletions backend/tracim_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ def web(global_config, **local_settings):
configurator.include(agenda_controller.bind, route_prefix=BASE_API_V2)
configurator.include(radicale_proxy_controller.bind)

if app_config.SEARCH__ENABLED:
# TODO - G.M - 2019-05-17 - check if possible to avoid this import here,
# import is here because import SearchController without adding it to
# pyramid make trouble in hapic which try to get view related
# to controller but failed.
from tracim_backend.lib.search.search_factory import SearchFactory
# TODO - G.M - 2019-05-17 - check if possible to avoid this import here,
# import is here because import SearchController without adding it to
# pyramid make trouble in hapic which try to get view related
# to controller but failed.
from tracim_backend.lib.search.search_factory import SearchFactory

search_controller = SearchFactory.get_search_controller(app_config)

search_controller = SearchFactory.get_search_controller(app_config)
configurator.include(search_controller.bind, route_prefix=BASE_API_V2)
configurator.include(search_controller.bind, route_prefix=BASE_API_V2)
if app_config.FRONTEND__SERVE:
configurator.include("pyramid_mako")
frontend_controller = FrontendController(app_config.FRONTEND__DIST_FOLDER_PATH)
Expand Down
34 changes: 16 additions & 18 deletions backend/tracim_backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ def _load_ldap_config(self) -> None:
self.LDAP_GET_INFO = None

def _load_search_config(self):
self.SEARCH__ENABLED = asbool(self.get_raw_config("search.enabled", "False"))
self.SEARCH__ENGINE = self.get_raw_config("search.engine", "simple")

DEFAULT_INDEX_DOCUMENTS_PATTERN_TEMPLATE = "{index_alias}-{date}"
Expand Down Expand Up @@ -809,24 +808,23 @@ def _set_default_app(self, enabled_app_list: typing.List[str]) -> None:
update_validators()

def _check_search_config_validity(self):
if self.SEARCH__ENABLED:
search_engine_valid = ["elasticsearch", "simple"]
if self.SEARCH__ENGINE not in search_engine_valid:
search_engine_valid = ["elasticsearch", "simple"]
if self.SEARCH__ENGINE not in search_engine_valid:

search_engine_list_str = ", ".join(
'"{}"'.format(engine) for engine in search_engine_valid
)
raise ConfigurationError(
"ERROR: SEARCH__ENGINE valid values are {}.".format(search_engine_list_str)
)
# FIXME - G.M - 2019-06-07 - hack to force index document alias check validity
# see https://github.com/tracim/tracim/issues/1835
if self.SEARCH__ENGINE == "elasticsearch":
self.check_mandatory_param(
"SEARCH__ELASTICSEARCH__INDEX_ALIAS",
self.SEARCH__ELASTICSEARCH__INDEX_ALIAS,
when_str="if elasticsearch search feature is enabled",
)
search_engine_list_str = ", ".join(
'"{}"'.format(engine) for engine in search_engine_valid
)
raise ConfigurationError(
"ERROR: SEARCH__ENGINE valid values are {}.".format(search_engine_list_str)
)
# FIXME - G.M - 2019-06-07 - hack to force index document alias check validity
# see https://github.com/tracim/tracim/issues/1835
if self.SEARCH__ENGINE == "elasticsearch":
self.check_mandatory_param(
"SEARCH__ELASTICSEARCH__INDEX_ALIAS",
self.SEARCH__ELASTICSEARCH__INDEX_ALIAS,
when_str="if elasticsearch search feature is enabled",
)

# INFO - G.M - 2019-04-05 - Others methods
def _check_consistency(self):
Expand Down
68 changes: 33 additions & 35 deletions backend/tracim_backend/lib/core/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,17 +590,16 @@ def execute_created_content_actions(self, content: Content) -> None:
This method do post-create user actions
"""
if self._config.SEARCH__ENABLED:
try:
content_in_context = ContentInContext(
content, config=self._config, dbsession=self._session
)
search_api = SearchFactory.get_search_lib(
current_user=self._user, config=self._config, session=self._session
)
search_api.index_content(content_in_context)
except Exception:
logger.exception(self, "Something goes wrong during indexing of new content")
try:
content_in_context = ContentInContext(
content, config=self._config, dbsession=self._session
)
search_api = SearchFactory.get_search_lib(
current_user=self._user, config=self._config, session=self._session
)
search_api.index_content(content_in_context)
except Exception:
logger.exception(self, "Something goes wrong during indexing of new content")

def execute_update_content_actions(self, content: Content) -> None:
"""
Expand All @@ -610,32 +609,31 @@ def execute_update_content_actions(self, content: Content) -> None:
This method do post-create user actions
"""
if self._config.SEARCH__ENABLED:

try:
content_in_context = ContentInContext(
content, config=self._config, dbsession=self._session
)
search_api = SearchFactory.get_search_lib(
current_user=self._user, config=self._config, session=self._session
)
search_api.index_content(content_in_context)
# FIXME - G.M - 2019-06-03 - reindex children to avoid trouble when deleting, archiving
# see https://github.com/tracim/tracim/issues/1833
if content.last_revision.revision_type in (
ActionDescription.DELETION,
ActionDescription.ARCHIVING,
ActionDescription.UNARCHIVING,
ActionDescription.UNDELETION,
):
for child_content in content.get_children(recursively=True):
child_in_context = ContentInContext(
child_content, config=self._config, dbsession=self._session
)
search_api.index_content(child_in_context)
try:
content_in_context = ContentInContext(
content, config=self._config, dbsession=self._session
)
search_api = SearchFactory.get_search_lib(
current_user=self._user, config=self._config, session=self._session
)
search_api.index_content(content_in_context)
# FIXME - G.M - 2019-06-03 - reindex children to avoid trouble when deleting, archiving
# see https://github.com/tracim/tracim/issues/1833
if content.last_revision.revision_type in (
ActionDescription.DELETION,
ActionDescription.ARCHIVING,
ActionDescription.UNARCHIVING,
ActionDescription.UNDELETION,
):
for child_content in content.get_children(recursively=True):
child_in_context = ContentInContext(
child_content, config=self._config, dbsession=self._session
)
search_api.index_content(child_in_context)

except Exception:
logger.exception(self, "Something goes wrong during indexing of content")
except Exception:
logger.exception(self, "Something goes wrong during indexing of content")

def get_one_from_revision(
self, content_id: int, content_type: str, workspace: Workspace = None, revision_id=None
Expand Down
1 change: 0 additions & 1 deletion backend/tracim_backend/lib/core/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def get_config(self) -> ConfigModel:
new_user_invitation_do_notify=self._config.NEW_USER__INVITATION__DO_NOTIFY,
webdav_enabled=self._config.WEBDAV__UI__ENABLED,
webdav_url=urljoin(self._config.WEBDAV__BASE_URL, self._config.WEBDAV__ROOT_PATH),
search_enabled=self._config.SEARCH__ENABLED,
)

def get_error_codes(self) -> typing.List[ErrorCodeModel]:
Expand Down
1 change: 0 additions & 1 deletion backend/tracim_backend/lib/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class ESSearchApi(SearchApi):

def __init__(self, session: Session, current_user: typing.Optional[User], config: CFG) -> None:
super().__init__(session, current_user, config)
assert config.SEARCH__ENABLED
assert config.SEARCH__ENGINE == ELASTICSEARCH__SEARCH_ENGINE_SLUG
# TODO - G.M - 2019-05-31 - we do support only "one elasticsearch server case here in config,
# check how to support more complex case.
Expand Down
2 changes: 0 additions & 2 deletions backend/tracim_backend/models/context_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ def __init__(
new_user_invitation_do_notify: bool,
webdav_enabled: bool,
webdav_url: str,
search_enabled: bool,
) -> None:
self.email_notification_activated = email_notification_activated
self.new_user_invitation_do_notify = new_user_invitation_do_notify
self.webdav_enabled = webdav_enabled
self.webdav_url = webdav_url
self.search_enabled = search_enabled


class ErrorCodeModel(object):
Expand Down
33 changes: 0 additions & 33 deletions backend/tracim_backend/tests/functional/test_simple_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,6 @@
from tracim_backend.tests import FunctionalTest


class NoSearchEnabled(FunctionalTest):
config_section = "functional_test_no_search"

def test_api___no_search__err_404__by_filename(self) -> None:
dbsession = get_tm_session(self.session_factory, transaction.manager)
admin = dbsession.query(User).filter(User.email == "admin@admin.admin").one()
uapi = UserApi(current_user=admin, session=dbsession, config=self.app_config)
gapi = GroupApi(current_user=admin, session=dbsession, config=self.app_config)
groups = [gapi.get_one_with_name("trusted-users")]
user = uapi.create_user(
"test@test.test",
password="test@test.test",
do_save=True,
do_notify=False,
groups=groups,
)
workspace_api = WorkspaceApi(
current_user=admin, session=dbsession, config=self.app_config, show_deleted=True
)
workspace = workspace_api.create_workspace("test", save_now=True)
rapi = RoleApi(current_user=admin, session=dbsession, config=self.app_config)
rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False)
api = ContentApi(session=dbsession, current_user=user, config=self.app_config)
api.create(
content_type_slug="html-document", workspace=workspace, label="test", do_save=True
)
transaction.commit()

self.testapp.authorization = ("Basic", ("test@test.test", "test@test.test"))
params = {"search_string": "test"}
self.testapp.get("/api/v2/search/content".format(), status=404, params=params)


class TestSimpleSearch(FunctionalTest):
config_section = "functional_test_simple_search"

Expand Down
1 change: 0 additions & 1 deletion backend/tracim_backend/tests/functional/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def test_api__get_config__ok_200__nominal_case(self):
assert res.json_body["new_user_invitation_do_notify"] is True
assert res.json_body["webdav_enabled"] is False
assert res.json_body["webdav_url"] == "https://localhost:3030/webdav"
assert res.json_body["search_enabled"] is False

@pytest.mark.xfail(reason="[config_unauthenticated] issue #1270 ")
def test_api__get_config__err_401__unregistered_user(self):
Expand Down
1 change: 0 additions & 1 deletion backend/tracim_backend/views/core_api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ class ConfigSchema(marshmallow.Schema):
new_user_invitation_do_notify = marshmallow.fields.Bool()
webdav_enabled = marshmallow.fields.Bool()
webdav_url = marshmallow.fields.String()
search_enabled = marshmallow.fields.Bool()


class ErrorCodeSchema(marshmallow.Schema):
Expand Down

0 comments on commit ff6e819

Please sign in to comment.