Coverage for cas_server/admin.py: 100%

49 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-17 18:04 +0000

1# This program is distributed in the hope that it will be useful, but WITHOUT 

2# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 

3# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for 

4# more details. 

5# 

6# You should have received a copy of the GNU General Public License version 3 

7# along with this program; if not, write to the Free Software Foundation, Inc., 51 

8# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 

9# 

10# (c) 2015-2016 Valentin Samir 

11"""module for the admin interface of the app""" 

12from .default_settings import settings 

13 

14from django.contrib import admin 

15from .models import ServiceTicket, ProxyTicket, ProxyGrantingTicket, User, ServicePattern 

16from .models import Username, ReplaceAttributName, ReplaceAttributValue, FilterAttributValue 

17from .models import FederatedIendityProvider, FederatedUser, UserAttributes 

18from .forms import TicketForm 

19 

20 

21class BaseInlines(admin.TabularInline): 

22 """ 

23 Bases: :class:`django.contrib.admin.TabularInline` 

24 

25 Base class for inlines in the admin interface. 

26 """ 

27 #: This controls the number of extra forms the formset will display in addition to 

28 #: the initial forms. 

29 extra = 0 

30 

31 

32class UserAdminInlines(BaseInlines): 

33 """ 

34 Bases: :class:`BaseInlines` 

35 

36 Base class for inlines in :class:`UserAdmin` interface 

37 """ 

38 #: The form :class:`TicketForm<cas_server.forms.TicketForm>` used to display tickets. 

39 form = TicketForm 

40 #: Fields to display on a object that are read only (not editable). 

41 readonly_fields = ( 

42 'validate', 'service', 'service_pattern', 

43 'creation', 'renew', 'single_log_out', 'value' 

44 ) 

45 #: Fields to display on a object. 

46 fields = ( 

47 'validate', 'service', 'service_pattern', 

48 'creation', 'renew', 'single_log_out' 

49 ) 

50 

51 

52class ServiceTicketInline(UserAdminInlines): 

53 """ 

54 Bases: :class:`UserAdminInlines` 

55 

56 :class:`ServiceTicket<cas_server.models.ServiceTicket>` in admin interface 

57 """ 

58 #: The model which the inline is using. 

59 model = ServiceTicket 

60 

61 

62class ProxyTicketInline(UserAdminInlines): 

63 """ 

64 Bases: :class:`UserAdminInlines` 

65 

66 :class:`ProxyTicket<cas_server.models.ProxyTicket>` in admin interface 

67 """ 

68 #: The model which the inline is using. 

69 model = ProxyTicket 

70 

71 

72class ProxyGrantingInline(UserAdminInlines): 

73 """ 

74 Bases: :class:`UserAdminInlines` 

75 

76 :class:`ProxyGrantingTicket<cas_server.models.ProxyGrantingTicket>` in admin interface 

77 """ 

78 #: The model which the inline is using. 

79 model = ProxyGrantingTicket 

80 

81 

82class UserAdmin(admin.ModelAdmin): 

83 """ 

84 Bases: :class:`django.contrib.admin.ModelAdmin` 

85 

86 :class:`User<cas_server.models.User>` in admin interface 

87 """ 

88 #: See :class:`ServiceTicketInline`, :class:`ProxyTicketInline`, :class:`ProxyGrantingInline` 

89 #: objects below the :class:`UserAdmin` fields. 

90 inlines = (ServiceTicketInline, ProxyTicketInline, ProxyGrantingInline) 

91 #: Fields to display on a object that are read only (not editable). 

92 readonly_fields = ('username', 'date', "session_key") 

93 #: Fields to display on a object. 

94 fields = ('username', 'date', "session_key") 

95 #: Fields to display on the list of class:`UserAdmin` objects. 

96 list_display = ('username', 'date', "session_key") 

97 

98 

99class UsernamesInline(BaseInlines): 

100 """ 

101 Bases: :class:`BaseInlines` 

102 

103 :class:`Username<cas_server.models.Username>` in admin interface 

104 """ 

105 #: The model which the inline is using. 

106 model = Username 

107 

108 

109class ReplaceAttributNameInline(BaseInlines): 

110 """ 

111 Bases: :class:`BaseInlines` 

112 

113 :class:`ReplaceAttributName<cas_server.models.ReplaceAttributName>` in admin interface 

114 """ 

115 #: The model which the inline is using. 

116 model = ReplaceAttributName 

117 

118 

119class ReplaceAttributValueInline(BaseInlines): 

120 """ 

121 Bases: :class:`BaseInlines` 

122 

123 :class:`ReplaceAttributValue<cas_server.models.ReplaceAttributValue>` in admin interface 

124 """ 

125 #: The model which the inline is using. 

126 model = ReplaceAttributValue 

127 

128 

129class FilterAttributValueInline(BaseInlines): 

130 """ 

131 Bases: :class:`BaseInlines` 

132 

133 :class:`FilterAttributValue<cas_server.models.FilterAttributValue>` in admin interface 

134 """ 

135 #: The model which the inline is using. 

136 model = FilterAttributValue 

137 

138 

139class ServicePatternAdmin(admin.ModelAdmin): 

140 """ 

141 Bases: :class:`django.contrib.admin.ModelAdmin` 

142 

143 :class:`ServicePattern<cas_server.models.ServicePattern>` in admin interface 

144 """ 

145 #: See :class:`UsernamesInline`, :class:`ReplaceAttributNameInline`, 

146 #: :class:`ReplaceAttributValueInline`, :class:`FilterAttributValueInline` objects below 

147 #: the :class:`ServicePatternAdmin` fields. 

148 inlines = ( 

149 UsernamesInline, 

150 ReplaceAttributNameInline, 

151 ReplaceAttributValueInline, 

152 FilterAttributValueInline 

153 ) 

154 #: Fields to display on the list of class:`ServicePatternAdmin` objects. 

155 list_display = ('pos', 'name', 'pattern', 'proxy', 

156 'single_log_out', 'proxy_callback', 'restrict_users') 

157 

158 

159class FederatedIendityProviderAdmin(admin.ModelAdmin): 

160 """ 

161 Bases: :class:`django.contrib.admin.ModelAdmin` 

162 

163 :class:`FederatedIendityProvider<cas_server.models.FederatedIendityProvider>` in admin 

164 interface 

165 """ 

166 #: Fields to display on a object. 

167 fields = ('pos', 'suffix', 'server_url', 'cas_protocol_version', 'verbose_name', 'display') 

168 #: Fields to display on the list of class:`FederatedIendityProviderAdmin` objects. 

169 list_display = ('verbose_name', 'suffix', 'display') 

170 

171 

172class FederatedUserAdmin(admin.ModelAdmin): 

173 """ 

174 Bases: :class:`django.contrib.admin.ModelAdmin` 

175 

176 :class:`FederatedUser<cas_server.models.FederatedUser>` in admin 

177 interface 

178 """ 

179 #: Fields to display on a object. 

180 fields = ('username', 'provider', 'last_update') 

181 #: Fields to display on the list of class:`FederatedUserAdmin` objects. 

182 list_display = ('username', 'provider', 'last_update') 

183 

184 

185class UserAttributesAdmin(admin.ModelAdmin): 

186 """ 

187 Bases: :class:`django.contrib.admin.ModelAdmin` 

188 

189 :class:`UserAttributes<cas_server.models.UserAttributes>` in admin 

190 interface 

191 """ 

192 #: Fields to display on a object. 

193 fields = ('username', '_attributs') 

194 

195 

196admin.site.register(ServicePattern, ServicePatternAdmin) 

197admin.site.register(FederatedIendityProvider, FederatedIendityProviderAdmin) 

198if settings.DEBUG: # pragma: no branch (we always test with DEBUG True) 

199 admin.site.register(User, UserAdmin) 

200 admin.site.register(FederatedUser, FederatedUserAdmin) 

201 admin.site.register(UserAttributes, UserAttributesAdmin)