Merge branch 'master' into auto-conversion-options-for-animated-gif
This commit is contained in:
commit
82c295fb60
6 changed files with 44 additions and 19 deletions
|
@ -47,10 +47,12 @@ class TopNavigationController {
|
||||||
topNavigation.hide('users');
|
topNavigation.hide('users');
|
||||||
}
|
}
|
||||||
if (api.isLoggedIn()) {
|
if (api.isLoggedIn()) {
|
||||||
topNavigation.hide('register');
|
if (!api.hasPrivilege('users:create:any')) {
|
||||||
|
topNavigation.hide('register');
|
||||||
|
}
|
||||||
topNavigation.hide('login');
|
topNavigation.hide('login');
|
||||||
} else {
|
} else {
|
||||||
if (!api.hasPrivilege('users:create')) {
|
if (!api.hasPrivilege('users:create:self')) {
|
||||||
topNavigation.hide('register');
|
topNavigation.hide('register');
|
||||||
}
|
}
|
||||||
topNavigation.hide('account');
|
topNavigation.hide('account');
|
||||||
|
|
|
@ -10,7 +10,7 @@ const EmptyView = require('../views/empty_view.js');
|
||||||
|
|
||||||
class UserRegistrationController {
|
class UserRegistrationController {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (!api.hasPrivilege('users:create')) {
|
if (!api.hasPrivilege('users:create:self')) {
|
||||||
this._view = new EmptyView();
|
this._view = new EmptyView();
|
||||||
this._view.showError('Registration is closed.');
|
this._view.showError('Registration is closed.');
|
||||||
return;
|
return;
|
||||||
|
@ -29,12 +29,22 @@ class UserRegistrationController {
|
||||||
user.name = e.detail.name;
|
user.name = e.detail.name;
|
||||||
user.email = e.detail.email;
|
user.email = e.detail.email;
|
||||||
user.password = e.detail.password;
|
user.password = e.detail.password;
|
||||||
|
const isLoggedIn = api.isLoggedIn();
|
||||||
user.save().then(() => {
|
user.save().then(() => {
|
||||||
api.forget();
|
if (isLoggedIn) {
|
||||||
return api.login(e.detail.name, e.detail.password, false);
|
return Promise.resolve();
|
||||||
|
} else {
|
||||||
|
api.forget();
|
||||||
|
return api.login(e.detail.name, e.detail.password, false);
|
||||||
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const ctx = router.show(uri.formatClientLink());
|
if (isLoggedIn) {
|
||||||
ctx.controller.showSuccess('Welcome aboard!');
|
const ctx = router.show(uri.formatClientLink('users'));
|
||||||
|
ctx.controller.showSuccess('User added!');
|
||||||
|
} else {
|
||||||
|
const ctx = router.show(uri.formatClientLink());
|
||||||
|
ctx.controller.showSuccess('Welcome aboard!');
|
||||||
|
}
|
||||||
}, error => {
|
}, error => {
|
||||||
this._view.showError(error.message);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
|
|
|
@ -68,7 +68,8 @@ default_rank: regular
|
||||||
|
|
||||||
|
|
||||||
privileges:
|
privileges:
|
||||||
'users:create': anonymous
|
'users:create:self': anonymous # Registration permission
|
||||||
|
'users:create:any': administrator
|
||||||
'users:list': regular
|
'users:list': regular
|
||||||
'users:view': regular
|
'users:view': regular
|
||||||
'users:edit:any:name': moderator
|
'users:edit:any:name': moderator
|
||||||
|
|
|
@ -26,7 +26,11 @@ def get_users(
|
||||||
@rest.routes.post('/users/?')
|
@rest.routes.post('/users/?')
|
||||||
def create_user(
|
def create_user(
|
||||||
ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
|
ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
|
||||||
auth.verify_privilege(ctx.user, 'users:create')
|
if ctx.user.user_id is None:
|
||||||
|
auth.verify_privilege(ctx.user, 'users:create:self')
|
||||||
|
else:
|
||||||
|
auth.verify_privilege(ctx.user, 'users:create:any')
|
||||||
|
|
||||||
name = ctx.get_param_as_string('name')
|
name = ctx.get_param_as_string('name')
|
||||||
password = ctx.get_param_as_string('password')
|
password = ctx.get_param_as_string('password')
|
||||||
email = ctx.get_param_as_string('email', default='')
|
email = ctx.get_param_as_string('email', default='')
|
||||||
|
@ -40,6 +44,7 @@ def create_user(
|
||||||
ctx.get_file('avatar', default=b''))
|
ctx.get_file('avatar', default=b''))
|
||||||
ctx.session.add(user)
|
ctx.session.add(user)
|
||||||
ctx.session.commit()
|
ctx.session.commit()
|
||||||
|
|
||||||
return _serialize(ctx, user, force_show_email=True)
|
return _serialize(ctx, user, force_show_email=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,6 @@ from szurubooru.func import mime, util
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
_SCALE_FIT_FMT = (
|
|
||||||
r'scale=iw*max({width}/iw\,{height}/ih):ih*max({width}/iw\,{height}/ih)')
|
|
||||||
|
|
||||||
|
|
||||||
class Image:
|
class Image:
|
||||||
def __init__(self, content: bytes) -> None:
|
def __init__(self, content: bytes) -> None:
|
||||||
self.content = content
|
self.content = content
|
||||||
|
@ -33,10 +29,14 @@ class Image:
|
||||||
return self.info['streams'][0]['nb_read_frames']
|
return self.info['streams'][0]['nb_read_frames']
|
||||||
|
|
||||||
def resize_fill(self, width: int, height: int) -> None:
|
def resize_fill(self, width: int, height: int) -> None:
|
||||||
|
width_greater = self.width > self.height
|
||||||
|
width, height = (-1, height) if width_greater else (width, -1)
|
||||||
|
|
||||||
cli = [
|
cli = [
|
||||||
'-i', '{path}',
|
'-i', '{path}',
|
||||||
'-f', 'image2',
|
'-f', 'image2',
|
||||||
'-vf', _SCALE_FIT_FMT.format(width=width, height=height),
|
'-filter:v', "scale='{width}:{height}'".format(
|
||||||
|
width=width, height=height),
|
||||||
'-map', '0:v:0',
|
'-map', '0:v:0',
|
||||||
'-vframes', '1',
|
'-vframes', '1',
|
||||||
'-vcodec', 'png',
|
'-vcodec', 'png',
|
||||||
|
@ -50,7 +50,7 @@ class Image:
|
||||||
'-ss',
|
'-ss',
|
||||||
'%d' % math.floor(duration * 0.3),
|
'%d' % math.floor(duration * 0.3),
|
||||||
] + cli
|
] + cli
|
||||||
content = self._execute(cli)
|
content = self._execute(cli, ignore_error_if_data=True)
|
||||||
if not content:
|
if not content:
|
||||||
raise errors.ProcessingError('Error while resizing image.')
|
raise errors.ProcessingError('Error while resizing image.')
|
||||||
self.content = content
|
self.content = content
|
||||||
|
@ -141,7 +141,11 @@ class Image:
|
||||||
with open(mp4_temp_path, 'rb') as mp4_temp:
|
with open(mp4_temp_path, 'rb') as mp4_temp:
|
||||||
return mp4_temp.read()
|
return mp4_temp.read()
|
||||||
|
|
||||||
def _execute(self, cli: List[str], program: str = 'ffmpeg') -> bytes:
|
def _execute(
|
||||||
|
self,
|
||||||
|
cli: List[str],
|
||||||
|
program: str = 'ffmpeg',
|
||||||
|
ignore_error_if_data: bool = False) -> bytes:
|
||||||
extension = mime.get_extension(mime.get_mime_type(self.content))
|
extension = mime.get_extension(mime.get_mime_type(self.content))
|
||||||
assert extension
|
assert extension
|
||||||
with util.create_temp_file(suffix='.' + extension) as handle:
|
with util.create_temp_file(suffix='.' + extension) as handle:
|
||||||
|
@ -160,8 +164,11 @@ class Image:
|
||||||
'Failed to execute ffmpeg command (cli=%r, err=%r)',
|
'Failed to execute ffmpeg command (cli=%r, err=%r)',
|
||||||
' '.join(shlex.quote(arg) for arg in cli),
|
' '.join(shlex.quote(arg) for arg in cli),
|
||||||
err)
|
err)
|
||||||
raise errors.ProcessingError(
|
if ((len(out) > 0 and not ignore_error_if_data)
|
||||||
'Error while processing image.\n' + err.decode('utf-8'))
|
or len(out) == 0):
|
||||||
|
raise errors.ProcessingError(
|
||||||
|
'Error while processing image.\n'
|
||||||
|
+ err.decode('utf-8'))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def _reload_info(self) -> None:
|
def _reload_info(self) -> None:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from szurubooru.func import users
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def inject_config(config_injector):
|
def inject_config(config_injector):
|
||||||
config_injector({'privileges': {'users:create': 'regular'}})
|
config_injector({'privileges': {'users:create:self': 'regular'}})
|
||||||
|
|
||||||
|
|
||||||
def test_creating_user(user_factory, context_factory, fake_datetime):
|
def test_creating_user(user_factory, context_factory, fake_datetime):
|
||||||
|
|
Reference in a new issue