django-cas-server/cas_server/admin.py

202 lines
6.7 KiB
Python
Raw Normal View History

2015-05-27 20:10:06 +00:00
# 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 version 3 for
# more details.
#
# You should have received a copy of the GNU General Public License version 3
# along with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
2016-06-30 22:00:53 +00:00
# (c) 2015-2016 Valentin Samir
2015-05-27 19:56:39 +00:00
"""module for the admin interface of the app"""
from .default_settings import settings
2015-05-16 21:43:46 +00:00
from django.contrib import admin
2015-05-27 19:56:39 +00:00
from .models import ServiceTicket, ProxyTicket, ProxyGrantingTicket, User, ServicePattern
from .models import Username, ReplaceAttributName, ReplaceAttributValue, FilterAttributValue
from .models import FederatedIendityProvider, FederatedUser, UserAttributes
2015-05-27 19:56:39 +00:00
from .forms import TicketForm
2015-05-16 21:43:46 +00:00
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
class BaseInlines(admin.TabularInline):
"""
Bases: :class:`django.contrib.admin.TabularInline`
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
Base class for inlines in the admin interface.
"""
#: This controls the number of extra forms the formset will display in addition to
#: the initial forms.
2015-05-16 21:43:46 +00:00
extra = 0
2016-07-20 16:28:23 +00:00
class UserAdminInlines(BaseInlines):
"""
Bases: :class:`BaseInlines`
Base class for inlines in :class:`UserAdmin` interface
"""
#: The form :class:`TicketForm<cas_server.forms.TicketForm>` used to display tickets.
2015-05-16 21:43:46 +00:00
form = TicketForm
2016-07-20 16:28:23 +00:00
#: Fields to display on a object that are read only (not editable).
readonly_fields = (
'validate', 'service', 'service_pattern',
'creation', 'renew', 'single_log_out', 'value'
)
#: Fields to display on a object.
fields = (
'validate', 'service', 'service_pattern',
'creation', 'renew', 'single_log_out'
)
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
class ServiceTicketInline(UserAdminInlines):
"""
Bases: :class:`UserAdminInlines`
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
:class:`ServiceTicket<cas_server.models.ServiceTicket>` in admin interface
"""
#: The model which the inline is using.
model = ServiceTicket
class ProxyTicketInline(UserAdminInlines):
"""
Bases: :class:`UserAdminInlines`
:class:`ProxyTicket<cas_server.models.ProxyTicket>` in admin interface
"""
#: The model which the inline is using.
2015-05-16 21:43:46 +00:00
model = ProxyTicket
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
class ProxyGrantingInline(UserAdminInlines):
"""
Bases: :class:`UserAdminInlines`
:class:`ProxyGrantingTicket<cas_server.models.ProxyGrantingTicket>` in admin interface
"""
#: The model which the inline is using.
2015-05-16 21:43:46 +00:00
model = ProxyGrantingTicket
2015-06-12 16:10:52 +00:00
2015-05-16 21:43:46 +00:00
class UserAdmin(admin.ModelAdmin):
2016-07-20 16:28:23 +00:00
"""
Bases: :class:`django.contrib.admin.ModelAdmin`
:class:`User<cas_server.models.User>` in admin interface
"""
#: See :class:`ServiceTicketInline`, :class:`ProxyTicketInline`, :class:`ProxyGrantingInline`
#: objects below the :class:`UserAdmin` fields.
2015-05-16 21:43:46 +00:00
inlines = (ServiceTicketInline, ProxyTicketInline, ProxyGrantingInline)
2016-07-20 16:28:23 +00:00
#: Fields to display on a object that are read only (not editable).
2015-06-12 16:10:52 +00:00
readonly_fields = ('username', 'date', "session_key")
2016-07-20 16:28:23 +00:00
#: Fields to display on a object.
fields = ('username', 'date', "session_key")
2016-07-20 16:28:23 +00:00
#: Fields to display on the list of class:`UserAdmin` objects.
2015-06-12 14:37:50 +00:00
list_display = ('username', 'date', "session_key")
2015-05-16 21:43:46 +00:00
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
class UsernamesInline(BaseInlines):
"""
Bases: :class:`BaseInlines`
:class:`Username<cas_server.models.Username>` in admin interface
"""
#: The model which the inline is using.
2015-05-27 19:56:39 +00:00
model = Username
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
class ReplaceAttributNameInline(BaseInlines):
"""
Bases: :class:`BaseInlines`
:class:`ReplaceAttributName<cas_server.models.ReplaceAttributName>` in admin interface
"""
#: The model which the inline is using.
2015-05-18 18:30:00 +00:00
model = ReplaceAttributName
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
class ReplaceAttributValueInline(BaseInlines):
"""
Bases: :class:`BaseInlines`
:class:`ReplaceAttributValue<cas_server.models.ReplaceAttributValue>` in admin interface
"""
#: The model which the inline is using.
2015-05-18 18:30:00 +00:00
model = ReplaceAttributValue
2015-06-12 16:10:52 +00:00
2016-07-20 16:28:23 +00:00
class FilterAttributValueInline(BaseInlines):
"""
Bases: :class:`BaseInlines`
:class:`FilterAttributValue<cas_server.models.FilterAttributValue>` in admin interface
"""
#: The model which the inline is using.
2015-05-18 18:30:00 +00:00
model = FilterAttributValue
2015-06-12 16:10:52 +00:00
2015-05-16 21:43:46 +00:00
class ServicePatternAdmin(admin.ModelAdmin):
2016-07-20 16:28:23 +00:00
"""
Bases: :class:`django.contrib.admin.ModelAdmin`
:class:`ServicePattern<cas_server.models.ServicePattern>` in admin interface
"""
#: See :class:`UsernamesInline`, :class:`ReplaceAttributNameInline`,
#: :class:`ReplaceAttributValueInline`, :class:`FilterAttributValueInline` objects below
#: the :class:`ServicePatternAdmin` fields.
2015-05-27 19:56:39 +00:00
inlines = (
UsernamesInline,
ReplaceAttributNameInline,
ReplaceAttributValueInline,
FilterAttributValueInline
)
2016-07-20 16:28:23 +00:00
#: Fields to display on the list of class:`ServicePatternAdmin` objects.
2015-06-12 16:10:52 +00:00
list_display = ('pos', 'name', 'pattern', 'proxy',
'single_log_out', 'proxy_callback', 'restrict_users')
2015-05-16 21:43:46 +00:00
class FederatedIendityProviderAdmin(admin.ModelAdmin):
2016-07-20 16:28:23 +00:00
"""
Bases: :class:`django.contrib.admin.ModelAdmin`
:class:`FederatedIendityProvider<cas_server.models.FederatedIendityProvider>` in admin
interface
"""
#: Fields to display on a object.
fields = ('pos', 'suffix', 'server_url', 'cas_protocol_version', 'verbose_name', 'display')
2016-07-20 16:28:23 +00:00
#: Fields to display on the list of class:`FederatedIendityProviderAdmin` objects.
list_display = ('verbose_name', 'suffix', 'display')
class FederatedUserAdmin(admin.ModelAdmin):
"""
Bases: :class:`django.contrib.admin.ModelAdmin`
:class:`FederatedUser<cas_server.models.FederatedUser>` in admin
interface
"""
#: Fields to display on a object.
fields = ('username', 'provider', 'last_update')
#: Fields to display on the list of class:`FederatedUserAdmin` objects.
list_display = ('username', 'provider', 'last_update')
class UserAttributesAdmin(admin.ModelAdmin):
"""
Bases: :class:`django.contrib.admin.ModelAdmin`
:class:`UserAttributes<cas_server.models.UserAttributes>` in admin
interface
"""
#: Fields to display on a object.
fields = ('username', '_attributs')
2015-05-16 21:43:46 +00:00
admin.site.register(ServicePattern, ServicePatternAdmin)
admin.site.register(FederatedIendityProvider, FederatedIendityProviderAdmin)
if settings.DEBUG: # pragma: no branch (we always test with DEBUG True)
admin.site.register(User, UserAdmin)
admin.site.register(FederatedUser, FederatedUserAdmin)
admin.site.register(UserAttributes, UserAttributesAdmin)