component file sharing: quotas implementation:

quotas can now be specified using the `quotas_json` option of `component file_sharing`
section in settings. This must be a dict where:
    - `users` key contains default quotas for all users
    - `admins` key contains quotas for administrators (not implemented yet)
    - `jids` contain bare JID to quota mapping, to have user-specific quota

The value can be either a int for quota in bytes, or a case insensitive string with an
optional multiplier symbol (e.g. "500 Mio"). `None` can be used for explicit unlimited
quota (which is the default is `users` is not set).

When a file size is too big for quota, upload is refused with an error message indicating
allowed quota, used space, and the size of the file that user wants to upload.
This commit is contained in:
Goffi 2021-05-05 15:37:33 +02:00
commit ac8f9f7817

View file

@ -17,18 +17,19 @@
# 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 sat.core.i18n import _, D_
from sat.core.constants import Const as C
from sat.core.log import getLogger
log = getLogger(__name__)
from sat.core import exceptions
from sat.tools import xml_tools
from sat.tools import stream
import os
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid
from twisted.words.protocols.jabber import error
import os
from twisted.internet import defer
from sat.core.i18n import _, D_
from sat.core.constants import Const as C
from sat.core.log import getLogger
from sat.core import exceptions
from sat.tools import xml_tools
from sat.tools import stream
log = getLogger(__name__)
NS_SI_FT = "http://jabber.org/protocol/si/profile/file-transfer"
@ -205,7 +206,9 @@ class XEP_0096(object):
"stream_plugin": plugin,
}
d = self._f.getDestDir(client, peer_jid, data, data, stream_object=True)
d = defer.ensureDeferred(
self._f.getDestDir(client, peer_jid, data, data, stream_object=True)
)
d.addCallback(self.confirmationCb, client, iq_elt, data)
def confirmationCb(self, accepted, client, iq_elt, data):