mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
@@ -73,9 +73,9 @@
|
||||
<template v-slot:activator="{ attrs, on }">
|
||||
<div class="d-flex user-box justify-center align-center white--text py-2" v-bind="attrs" v-on="on">
|
||||
<v-avatar size="40" color="primary">
|
||||
<span class="white--text headline">AN</span>
|
||||
<span class="white--text headline">{{ userInitials }}</span>
|
||||
</v-avatar>
|
||||
<span class="mx-2">{{ authUser.first_name }} {{ authUser.last_name }}</span>
|
||||
<span class="mx-2">{{ displayName }}</span>
|
||||
<v-icon class="float-right">mdi-chevron-up</v-icon>
|
||||
</div>
|
||||
</template>
|
||||
@@ -107,7 +107,25 @@ export default {
|
||||
computed: {
|
||||
...mapGetters({
|
||||
authUser: 'auth/authUser'
|
||||
})
|
||||
}),
|
||||
userInitials () {
|
||||
let initials = null
|
||||
if (this.authUser.first_name) {
|
||||
initials = this.authUser.first_name[0]
|
||||
}
|
||||
if (this.authUser.last_name) {
|
||||
initials = initials ? initials + this.authUser.last_name[0] : this.authUser.last_name[0]
|
||||
}
|
||||
if (!initials) {
|
||||
initials = this.authUser.this.authUsername[0]
|
||||
}
|
||||
return initials
|
||||
},
|
||||
displayName () {
|
||||
return (this.authUser.first_name || this.authUser.last_name)
|
||||
? `${this.authUser.first_name} ${this.authUser.last_name}`
|
||||
: this.authUser.username
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
"""A client for Modoboa's public API."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pkg_resources
|
||||
import requests
|
||||
from requests.exceptions import RequestException
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
logger = logging.getLogger("modoboa.admin")
|
||||
|
||||
|
||||
class ModoAPIClient(object):
|
||||
|
||||
@@ -26,7 +31,10 @@ class ModoAPIClient(object):
|
||||
params = {}
|
||||
try:
|
||||
resp = requests.get(url, params=params)
|
||||
except RequestException:
|
||||
except RequestException as err:
|
||||
logger.critical(
|
||||
_("Failed to communicate with public API: %s"), str(err)
|
||||
)
|
||||
return None
|
||||
if resp.status_code != 200:
|
||||
return None
|
||||
@@ -57,7 +65,13 @@ class ModoAPIClient(object):
|
||||
url = "{}instances/".format(self._api_url)
|
||||
data = {
|
||||
"hostname": hostname, "known_version": self.local_core_version}
|
||||
response = requests.post(url, data=data)
|
||||
try:
|
||||
response = requests.post(url, data=data)
|
||||
except RequestException as err:
|
||||
logger.critical(
|
||||
_("Failed to communicate with public API: %s"), str(err)
|
||||
)
|
||||
return None
|
||||
if response.status_code != 201:
|
||||
return None
|
||||
instance = response.json()
|
||||
@@ -66,8 +80,16 @@ class ModoAPIClient(object):
|
||||
def update_instance(self, pk, data):
|
||||
"""Update instance and send stats."""
|
||||
url = "{}instances/{}/".format(self._api_url, pk)
|
||||
response = requests.put(url, data=data)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = requests.put(url, data=data)
|
||||
except RequestException as err:
|
||||
logger.critical(
|
||||
_("Failed to communicate with public API: %s"), str(err)
|
||||
)
|
||||
if response.status_code != 200:
|
||||
logger.critical(
|
||||
_("Failed to communicate with public API: %s"), response.text
|
||||
)
|
||||
|
||||
def versions(self):
|
||||
"""Fetch core and extension versions."""
|
||||
|
||||
Reference in New Issue
Block a user