Commit 28fc85f7 by Kálmán Viktor

dashboard: allow no store

Closes #219
parent 79703087
...@@ -446,14 +446,14 @@ if graphite_host and graphite_port: ...@@ -446,14 +446,14 @@ if graphite_host and graphite_port:
else: else:
GRAPHITE_URL = None GRAPHITE_URL = None
STORE_BASIC_AUTH = get_env_variable("STORE_BASIC_AUTH") == "True" STORE_BASIC_AUTH = get_env_variable("STORE_BASIC_AUTH", "") == "True"
STORE_VERIFY_SSL = get_env_variable("STORE_VERIFY_SSL") == "True" STORE_VERIFY_SSL = get_env_variable("STORE_VERIFY_SSL", "") == "True"
STORE_SSL_AUTH = get_env_variable("STORE_SSL_AUTH") == "True" STORE_SSL_AUTH = get_env_variable("STORE_SSL_AUTH", "") == "True"
STORE_CLIENT_USER = get_env_variable("STORE_CLIENT_USER", "") STORE_CLIENT_USER = get_env_variable("STORE_CLIENT_USER", "")
STORE_CLIENT_PASSWORD = get_env_variable("STORE_CLIENT_PASSWORD", "") STORE_CLIENT_PASSWORD = get_env_variable("STORE_CLIENT_PASSWORD", "")
STORE_CLIENT_KEY = get_env_variable("STORE_CLIENT_KEY", "") STORE_CLIENT_KEY = get_env_variable("STORE_CLIENT_KEY", "")
STORE_CLIENT_CERT = get_env_variable("STORE_CLIENT_CERT", "") STORE_CLIENT_CERT = get_env_variable("STORE_CLIENT_CERT", "")
STORE_URL = get_env_variable("STORE_URL") STORE_URL = get_env_variable("STORE_URL", "")
SESSION_COOKIE_NAME = "csessid%x" % (((getnode() // 139) ^ SESSION_COOKIE_NAME = "csessid%x" % (((getnode() // 139) ^
(getnode() % 983)) & 0xffff) (getnode() % 983)) & 0xffff)
...@@ -22,6 +22,10 @@ class NotOkException(StoreApiException): ...@@ -22,6 +22,10 @@ class NotOkException(StoreApiException):
super(NotOkException, self).__init__(*args, **kwargs) super(NotOkException, self).__init__(*args, **kwargs)
class NoStoreException(StoreApiException):
pass
class Store(object): class Store(object):
def __init__(self, user, default_timeout=0.5): def __init__(self, user, default_timeout=0.5):
...@@ -35,6 +39,8 @@ class Store(object): ...@@ -35,6 +39,8 @@ class Store(object):
self.username = "u-%d" % user.pk self.username = "u-%d" % user.pk
self.default_timeout = default_timeout self.default_timeout = default_timeout
self.store_url = settings.STORE_URL self.store_url = settings.STORE_URL
if not self.store_url:
raise NoStoreException
def _request(self, url, method=get, timeout=None, def _request(self, url, method=get, timeout=None,
raise_status_code=True, **kwargs): raise_status_code=True, **kwargs):
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
</div> </div>
{% endif %} {% endif %}
{% if not no_store %}
<div class="col-lg-4 col-sm-6"> <div class="col-lg-4 col-sm-6">
{% include "dashboard/store/index-files.html" %} {% include "dashboard/store/index-files.html" %}
</div> </div>
{% endif %}
{% if perms.vm.create_template %} {% if perms.vm.create_template %}
<div class="col-lg-4 col-sm-6"> <div class="col-lg-4 col-sm-6">
......
...@@ -84,7 +84,7 @@ from storage.models import Disk ...@@ -84,7 +84,7 @@ from storage.models import Disk
from firewall.models import Vlan, Host, Rule from firewall.models import Vlan, Host, Rule
from .models import Favourite, Profile, GroupProfile, FutureMember from .models import Favourite, Profile, GroupProfile, FutureMember
from .store_api import Store, NotOkException from .store_api import Store, NoStoreException
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
saml_available = hasattr(settings, "SAML_CONFIG") saml_available = hasattr(settings, "SAML_CONFIG")
...@@ -226,19 +226,22 @@ class IndexView(LoginRequiredMixin, TemplateView): ...@@ -226,19 +226,22 @@ class IndexView(LoginRequiredMixin, TemplateView):
'operator', user).all()[:5] 'operator', user).all()[:5]
# toplist # toplist
cache_key = "toplist-%d" % self.request.user.pk if settings.STORE_URL:
cache = get_cache("default") cache_key = "toplist-%d" % self.request.user.pk
toplist = cache.get(cache_key) cache = get_cache("default")
if not toplist: toplist = cache.get(cache_key)
try: if not toplist:
toplist = Store(self.request.user).toplist() try:
except Exception: toplist = Store(self.request.user).toplist()
logger.exception("Unable to get tolist for %s", except Exception:
unicode(self.request.user)) logger.exception("Unable to get tolist for %s",
toplist = [] unicode(self.request.user))
cache.set(cache_key, toplist, 300) toplist = []
cache.set(cache_key, toplist, 300)
context['toplist'] = toplist context['toplist'] = toplist
else:
context['no_store'] = True
return context return context
...@@ -3103,14 +3106,18 @@ class StoreList(LoginRequiredMixin, TemplateView): ...@@ -3103,14 +3106,18 @@ class StoreList(LoginRequiredMixin, TemplateView):
return context return context
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
if self.request.is_ajax(): try:
context = self.get_context_data(**kwargs) if self.request.is_ajax():
return render_to_response( context = self.get_context_data(**kwargs)
"dashboard/store/_list-box.html", return render_to_response(
RequestContext(self.request, context), "dashboard/store/_list-box.html",
) RequestContext(self.request, context),
else: )
return super(StoreList, self).get(*args, **kwargs) else:
return super(StoreList, self).get(*args, **kwargs)
except NoStoreException:
messages.warning(self.request, _("No store."))
return redirect("/")
def create_up_directory(self, directory): def create_up_directory(self, directory):
return normpath(join('/', directory, '..')) return normpath(join('/', directory, '..'))
...@@ -3122,7 +3129,7 @@ def store_download(request): ...@@ -3122,7 +3129,7 @@ def store_download(request):
path = request.GET.get("path") path = request.GET.get("path")
try: try:
url = Store(request.user).request_download(path) url = Store(request.user).request_download(path)
except NotOkException: except Exception:
messages.error(request, _("Something went wrong during download.")) messages.error(request, _("Something went wrong during download."))
logger.exception("Unable to download, " logger.exception("Unable to download, "
"maybe it is already deleted") "maybe it is already deleted")
...@@ -3183,6 +3190,12 @@ class StoreRemove(LoginRequiredMixin, TemplateView): ...@@ -3183,6 +3190,12 @@ class StoreRemove(LoginRequiredMixin, TemplateView):
return context return context
def get(self, *args, **kwargs):
try:
return super(StoreRemove, self).get(*args, **kwargs)
except NoStoreException:
return redirect("/")
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
path = self.request.POST.get("path") path = self.request.POST.get("path")
try: try:
...@@ -3209,6 +3222,7 @@ def store_new_directory(request): ...@@ -3209,6 +3222,7 @@ def store_new_directory(request):
logger.exception("Unable to create folder %s in %s for %s", logger.exception("Unable to create folder %s in %s for %s",
name, path, unicode(request.user)) name, path, unicode(request.user))
messages.error(request, _("Unable to create folder.")) messages.error(request, _("Unable to create folder."))
return redirect("/")
return redirect("%s?directory=%s" % ( return redirect("%s?directory=%s" % (
reverse("dashboard.views.store-list"), path)) reverse("dashboard.views.store-list"), path))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment