Commit 41bf08ce authored by Alex Pyrgiotis's avatar Alex Pyrgiotis

admin: Align auth_providers/groups with resources

Split the auth_providers.py and groups.py to four different categories:
views, filters, actions, utils. This split aligns these files with the
rest of the resources in the `resources` folder.

Note that due to the simplicity of these resources, the actions, filters
and utils files are left blank.
parent edc275e6
# Copyright (C) 2010-2014 GRNET S.A.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Auth-Providers have no actions."""
# Copyright (C) 2010-2014 GRNET S.A.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Copyright (C) 2010-2014 GRNET S.A.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -12,20 +12,11 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import re
from collections import OrderedDict
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from django.core.urlresolvers import reverse
from astakos.im.models import AstakosUserAuthProvider
from astakos.im.models import AstakosUser
from eztables.views import DatatablesView
from actions import AdminAction
from synnefo_admin.admin.tables import AdminJSONView
templates = {
'list': 'admin/auth_provider_list.html',
......@@ -33,19 +24,7 @@ templates = {
}
def get_allowed_actions(auth_provider):
"""Get a list of actions that can apply to an auth_provider."""
allowed_actions = []
actions = generate_actions()
for key, action in actions.iteritems():
if action.can_apply(auth_provider):
allowed_actions.append(key)
return allowed_actions
class AstakosUserAuthProviderJSONView(DatatablesView):
class AstakosUserAuthProviderJSONView(AdminJSONView):
model = AstakosUserAuthProvider
fields = ('id', 'module', 'identifier', 'active', 'created')
......@@ -55,7 +34,7 @@ class AstakosUserAuthProviderJSONView(DatatablesView):
extra_dict = {
'allowed_actions': {
'display_name': "",
'value': get_allowed_actions(inst),
'value': [],
'visible': False,
}, 'id': {
'display_name': "ID",
......@@ -95,47 +74,10 @@ class AstakosUserAuthProviderJSONView(DatatablesView):
JSON_CLASS = AstakosUserAuthProviderJSONView
class AstakosUserAuthProviderAction(AdminAction):
"""Class for actions on auth_providers. Derived from AdminAction.
Pre-determined Attributes:
target: auth_provider
"""
def __init__(self, name, f, **kwargs):
"""Initialize the class with provided values."""
AdminAction.__init__(self, name=name, target='auth_provider', f=f,
**kwargs)
def generate_actions():
"""Create a list of actions on auth_providers.
The actions are: activate/deactivate, accept/reject, verify, contact.
"""
actions = OrderedDict()
actions['contact'] = AstakosUserAuthProviderAction(name='Send e-mail',
f=send_email)
return actions
def do_action(request, op, id):
"""Apply the requested action on the specified auth_provider."""
auth_provider = AstakosUserAuthProvider.objects.get(id=id)
actions = generate_actions()
if op == 'contact':
actions[op].apply(auth_provider, request.POST['text'])
else:
actions[op].apply(auth_provider)
def catalog(request):
"""List view for Cyclades auth_providers."""
context = {}
context['action_dict'] = generate_actions()
context['action_dict'] = {}
context['columns'] = ["Name", "Identifier", "Active",
"Creation date", ""]
context['item_type'] = 'auth_provider'
......
# Copyright (C) 2010-2014 GRNET S.A.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Groups have no actions."""
# Copyright (C) 2010-2014 GRNET S.A.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Copyright (C) 2010-2014 GRNET S.A.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -13,20 +13,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import re
from collections import OrderedDict
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group
from synnefo_admin.admin.exceptions import AdminHttp404
from synnefo_admin.admin.tables import AdminJSONView
from eztables.views import DatatablesView
from synnefo_admin.admin.actions import AdminAction
templates = {
'list': 'admin/group_list.html',
......@@ -34,19 +25,7 @@ templates = {
}
def get_allowed_actions(group):
"""Get a list of actions that can apply to a group."""
allowed_actions = []
actions = generate_actions()
for key, action in actions.iteritems():
if action.can_apply(group):
allowed_actions.append(key)
return allowed_actions
class GroupJSONView(DatatablesView):
class GroupJSONView(AdminJSONView):
model = Group
fields = ('id', 'name')
......@@ -56,7 +35,7 @@ class GroupJSONView(DatatablesView):
extra_dict = {
'allowed_actions': {
'display_name': "",
'value': get_allowed_actions(inst),
'value': [],
'visible': False,
}, 'id': {
'display_name': "ID",
......@@ -75,44 +54,14 @@ class GroupJSONView(DatatablesView):
JSON_CLASS = GroupJSONView
class GroupAction(AdminAction):
"""Class for actions on groups. Derived from AdminAction.
Pre-determined Attributes:
target: group
"""
def __init__(self, name, f, **kwargs):
"""Initialize the class with provided values."""
AdminAction.__init__(self, name=name, target='group', f=f, **kwargs)
def generate_actions():
"""Create a list of actions on groups.
Currently there are none
"""
actions = OrderedDict()
return actions
def do_action(request, op, id):
"""Apply the requested action on the specified group."""
group = Group.objects.get(id=id)
actions = generate_actions()
if op == 'contact':
actions[op].apply(group, request.POST['text'])
else:
actions[op].apply(group)
raise AdminHttp404("There are no actions for Groups")
def catalog(request):
"""List view for Cyclades groups."""
context = {}
context['action_dict'] = generate_actions()
context['action_dict'] = {}
context['columns'] = ["ID", "Name", ""]
context['item_type'] = 'group'
......
......@@ -16,7 +16,6 @@
import logging
import json
from importlib import import_module
import inspect
from django.views.generic.simple import direct_to_template
from django.conf import settings
......@@ -42,7 +41,6 @@ from synnefo_admin.admin.exceptions import AdminHttp404, AdminHttp405
from synnefo_admin import admin_settings
from synnefo_admin.admin import exceptions
from synnefo_admin.admin import tables
from synnefo_admin.admin.utils import (conditionally_gzip_page,
customize_details_context, admin_log)
......@@ -63,11 +61,8 @@ def get_view_module(view_type):
setting.
"""
if view_type in admin_settings.ADMIN_VIEWS:
try:
# This module will not be reloaded again as it's probably cached.
return import_module('synnefo_admin.admin.resources.%ss.views' % view_type)
except ImportError:
return import_module('synnefo_admin.admin.resources.%ss' % view_type)
# The modules will not be loaded per-call but only once.
return import_module('synnefo_admin.admin.resources.%ss.views' % view_type)
return None
......@@ -137,7 +132,7 @@ def admin_user_required(func, permitted_groups=admin_settings.\
raise PermissionDenied
logging.debug("User %s accessed admininterface view (%s)",
request.user_uniq, request.path)
request.user_uniq, request.path)
return func(request, *args, **kwargs)
return wrapper
......
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