mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] first implementation of update
This commit is contained in:
parent
1064729c18
commit
cf9284e9f2
2 changed files with 67 additions and 4 deletions
|
@ -235,7 +235,7 @@ alias:
|
|||
|
||||
### alias_list()
|
||||
list:
|
||||
action_help: List alias
|
||||
action_help: List existing aliases
|
||||
api: GET /alias
|
||||
configuration:
|
||||
authenticate: all
|
||||
|
@ -243,19 +243,19 @@ alias:
|
|||
|
||||
### alias_create()
|
||||
create:
|
||||
action_help: Create alias
|
||||
action_help: Create a new alias
|
||||
api: POST /alias
|
||||
configuration:
|
||||
authenticate: all
|
||||
arguments:
|
||||
alias:
|
||||
help: The unique alias name to create
|
||||
help: The unique email alias to create
|
||||
extra:
|
||||
required: True
|
||||
pattern: *pattern_email
|
||||
-f:
|
||||
full: --mailforward
|
||||
help: List of email to forward, separated by commas without space
|
||||
help: List of email to forward to, separated by commas without space
|
||||
extra:
|
||||
ask: ask_alias_mailforward
|
||||
required: True
|
||||
|
@ -263,6 +263,24 @@ alias:
|
|||
- !!str ^([\w.-]+(\+[\w.-]+)*@([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+([^\W\d_]{2,}),?)+$
|
||||
- "pattern_listemail"
|
||||
|
||||
### alias_update()
|
||||
update:
|
||||
action_help: Update an existing email alias
|
||||
api: PUT /alias/<alias>
|
||||
configuration:
|
||||
authenticate: all
|
||||
arguments:
|
||||
alias:
|
||||
help: Alias to update
|
||||
--add-mailforward:
|
||||
help: List of mailforward addresses to add, separated by commas without space
|
||||
extra:
|
||||
pattern: *pattern_listemail
|
||||
--remove-mailforward:
|
||||
help: List of mailforward addresses to remove, separated by commas without space
|
||||
extra:
|
||||
pattern: *pattern_listemail
|
||||
|
||||
### alias_delete()
|
||||
delete:
|
||||
action_help: Delete alias
|
||||
|
|
|
@ -78,6 +78,51 @@ def alias_create(auth, alias, mailforward):
|
|||
msignals.display(m18n.n('alias_created'), 'success')
|
||||
return { 'alias' : alias, 'maildrop' : attr_dict['maildrop'] }
|
||||
|
||||
def alias_update(auth, alias, add_mailforward=None, remove_mailforward=None):
|
||||
"""
|
||||
Update alias informations
|
||||
Keyword argument:
|
||||
alias
|
||||
add_mailforward -- Mailforward addresses to add
|
||||
remove_mailforward -- Mailforward addresses to remove
|
||||
"""
|
||||
_ensure_ldap_ou_is_created(auth)
|
||||
|
||||
alias_attrs = [
|
||||
'mail', 'maildrop'
|
||||
]
|
||||
|
||||
if len(alias.split('@')) is 2:
|
||||
filter = 'mail=' + alias
|
||||
else:
|
||||
# TODO better error message
|
||||
raise MoulinetteError(167, m18n.n('alias_info_failed'))
|
||||
|
||||
result = auth.search('ou=aliases,dc=yunohost,dc=org', filter, alias_attrs)
|
||||
|
||||
if not result:
|
||||
raise MoulinetteError(errno.EINVAL, m18n.n('alias_unknown'))
|
||||
|
||||
current_alias_info = result[0]
|
||||
|
||||
# Get modifications from arguments
|
||||
if add_mailforward:
|
||||
add_mailforward = add_mailforward.split(",")
|
||||
for mail in add_mailforward:
|
||||
if mail not in current_alias_info['maildrop']:
|
||||
current_alias_info['maildrop'].append(mail)
|
||||
|
||||
if remove_mailforward:
|
||||
remove_mailforward = remove_mailforward.split(",")
|
||||
for mail in remove_mailforward:
|
||||
if mail in current_alias_info['maildrop'][1:]:
|
||||
current_alias_info['maildrop'].remove(mail)
|
||||
|
||||
if auth.update('mail=%s,ou=aliases' % alias, current_alias_info):
|
||||
msignals.display(m18n.n('alias_updated'), 'success')
|
||||
return alias_info(auth, alias)
|
||||
else:
|
||||
raise MoulinetteError(169, m18n.n('alias_update_failed'))
|
||||
|
||||
def alias_delete(auth, alias):
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue