Commit fa5ff74d authored by Olga Brani's avatar Olga Brani Committed by Giorgos Korfiatis

admin: Add modify_email to user available actions

parent 78a3efde
# Copyright (C) 2010-2014 GRNET S.A. # Copyright (C) 2010-2016 GRNET S.A.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -54,7 +54,7 @@ class GroupJSONView(AdminJSONView): ...@@ -54,7 +54,7 @@ class GroupJSONView(AdminJSONView):
JSON_CLASS = GroupJSONView JSON_CLASS = GroupJSONView
def do_action(request, op, id): def do_action(request, op, id, data):
raise AdminHttp404("There are no actions for Groups") raise AdminHttp404("There are no actions for Groups")
......
# Copyright (C) 2010-2014 GRNET S.A. # Copyright (C) 2010-2016 GRNET S.A.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -155,7 +155,7 @@ JSON_CLASS = IPJSONView ...@@ -155,7 +155,7 @@ JSON_CLASS = IPJSONView
@transaction.commit_on_success @transaction.commit_on_success
@has_permission_or_403(cached_actions) @has_permission_or_403(cached_actions)
def do_action(request, op, id): def do_action(request, op, id, data):
"""Apply the requested action on the specified ip.""" """Apply the requested action on the specified ip."""
if op == "contact": if op == "contact":
user = get_user_or_404(id) user = get_user_or_404(id)
......
...@@ -146,7 +146,7 @@ JSON_CLASS = NetworkJSONView ...@@ -146,7 +146,7 @@ JSON_CLASS = NetworkJSONView
@transaction.commit_on_success @transaction.commit_on_success
@has_permission_or_403(cached_actions) @has_permission_or_403(cached_actions)
def do_action(request, op, id): def do_action(request, op, id, data):
"""Apply the requested action on the specified network.""" """Apply the requested action on the specified network."""
if op == "contact": if op == "contact":
user = get_user_or_404(id) user = get_user_or_404(id)
......
...@@ -199,7 +199,7 @@ JSON_CLASS = ProjectJSONView ...@@ -199,7 +199,7 @@ JSON_CLASS = ProjectJSONView
@has_permission_or_403(cached_actions) @has_permission_or_403(cached_actions)
@transaction.commit_on_success @transaction.commit_on_success
def do_action(request, op, id): def do_action(request, op, id, data):
"""Apply the requested action on the specified user.""" """Apply the requested action on the specified user."""
if op == "contact": if op == "contact":
user = get_user_or_404(id) user = get_user_or_404(id)
......
# Copyright (C) 2010-2014 GRNET S.A. # Copyright (C) 2010-2016 GRNET S.A.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -21,6 +21,7 @@ from astakos.im import user_logic as users ...@@ -21,6 +21,7 @@ from astakos.im import user_logic as users
from synnefo_admin.admin.actions import AdminAction from synnefo_admin.admin.actions import AdminAction
from synnefo_admin.admin.utils import update_actions_rbac, send_admin_email from synnefo_admin.admin.utils import update_actions_rbac, send_admin_email
from astakos.im.user_utils import change_user_email
class UserAction(AdminAction): class UserAction(AdminAction):
...@@ -82,6 +83,10 @@ def generate_actions(): ...@@ -82,6 +83,10 @@ def generate_actions():
actions['contact'] = UserAction(name='Send e-mail', f=send_admin_email,) actions['contact'] = UserAction(name='Send e-mail', f=send_admin_email,)
actions['modify_email'] = UserAction(name='Change e-mail',
f=change_user_email,karma='bad',
caution_level='dangerous',)
update_actions_rbac(actions) update_actions_rbac(actions)
return actions return actions
......
...@@ -171,7 +171,7 @@ JSON_CLASS = UserJSONView ...@@ -171,7 +171,7 @@ JSON_CLASS = UserJSONView
@has_permission_or_403(cached_actions) @has_permission_or_403(cached_actions)
@transaction.commit_on_success @transaction.commit_on_success
def do_action(request, op, id): def do_action(request, op, id, data):
"""Apply the requested action on the specified user.""" """Apply the requested action on the specified user."""
user = get_user_or_404(id, for_update=True) user = get_user_or_404(id, for_update=True)
actions = get_permitted_actions(cached_actions, request.user) actions = get_permitted_actions(cached_actions, request.user)
...@@ -180,6 +180,9 @@ def do_action(request, op, id): ...@@ -180,6 +180,9 @@ def do_action(request, op, id):
actions[op].apply(user, 'Rejected by the admin') actions[op].apply(user, 'Rejected by the admin')
elif op == 'contact': elif op == 'contact':
actions[op].apply(user, request) actions[op].apply(user, request)
elif op == 'modify_email':
if isinstance(data, dict):
actions[op].apply(user, data.get('new_email'))
else: else:
actions[op].apply(user) actions[op].apply(user)
......
...@@ -147,7 +147,7 @@ JSON_CLASS = VMJSONView ...@@ -147,7 +147,7 @@ JSON_CLASS = VMJSONView
@transaction.commit_on_success @transaction.commit_on_success
@has_permission_or_403(cached_actions) @has_permission_or_403(cached_actions)
def do_action(request, op, id): def do_action(request, op, id, data):
"""Apply the requested action on the specified user.""" """Apply the requested action on the specified user."""
if op == "contact": if op == "contact":
user = get_user_or_404(id) user = get_user_or_404(id)
......
...@@ -169,7 +169,7 @@ JSON_CLASS = VolumeJSONView ...@@ -169,7 +169,7 @@ JSON_CLASS = VolumeJSONView
@transaction.commit_on_success @transaction.commit_on_success
@has_permission_or_403(cached_actions) @has_permission_or_403(cached_actions)
def do_action(request, op, id): def do_action(request, op, id, data):
"""Apply the requested action on the specified volume.""" """Apply the requested action on the specified volume."""
if op == "contact": if op == "contact":
user = get_user_or_404(id) user = get_user_or_404(id)
......
# Copyright (C) 2010-2014 GRNET S.A. # Copyright (C) 2010-2016 GRNET S.A.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -320,8 +320,10 @@ def admin_actions(request): ...@@ -320,8 +320,10 @@ def admin_actions(request):
for item in items: for item in items:
id = item['id'] id = item['id']
data = item.get('data')
try: try:
mod.do_action(request, op, id) mod.do_action(request, op, id, data)
except faults.BadRequest as e: except faults.BadRequest as e:
status = 400 status = 400
response['result'] = e.message response['result'] = e.message
......
# Copyright (C) 2010-2014 GRNET S.A. # Copyright (C) 2010-2016 GRNET S.A.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -89,6 +89,7 @@ DEFAULT_ADMIN_RBAC = { ...@@ -89,6 +89,7 @@ DEFAULT_ADMIN_RBAC = {
'verify': [ADMIN_GROUP], 'verify': [ADMIN_GROUP],
'resend_verification': [ADMIN_GROUP], 'resend_verification': [ADMIN_GROUP],
'contact': [ADMIN_HELPDESK_GROUP, ADMIN_GROUP], 'contact': [ADMIN_HELPDESK_GROUP, ADMIN_GROUP],
'modify_email': [ADMIN_HELPDESK_GROUP, ADMIN_GROUP],
}, 'vm': { }, 'vm': {
'start': [ADMIN_HELPDESK_GROUP, ADMIN_GROUP], 'start': [ADMIN_HELPDESK_GROUP, ADMIN_GROUP],
'shutdown': [ADMIN_HELPDESK_GROUP, ADMIN_GROUP], 'shutdown': [ADMIN_HELPDESK_GROUP, ADMIN_GROUP],
......
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 to comment