|
1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2008 the Melange authors. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 |
|
17 """Views for Organization Admins. |
|
18 """ |
|
19 |
|
20 __authors__ = [ |
|
21 '"Lennard de Rijk" <ljvderijk@gmail.com>' |
|
22 ] |
|
23 |
|
24 |
|
25 from django import forms |
|
26 |
|
27 from soc.logic import dicts |
|
28 from soc.logic.models import organization as org_logic |
|
29 from soc.views.helper import access |
|
30 from soc.views.helper import dynaform |
|
31 from soc.views.helper import widgets |
|
32 from soc.views.models import organization as org_view |
|
33 from soc.views.models import role |
|
34 |
|
35 import soc.logic.models.org_admin |
|
36 |
|
37 |
|
38 class View(role.View): |
|
39 """View methods for the Organization Admin model. |
|
40 """ |
|
41 |
|
42 def __init__(self, params=None): |
|
43 """Defines the fields and methods required for the base View class |
|
44 to provide the user with list, public, create, edit and delete views. |
|
45 |
|
46 Params: |
|
47 params: a dict with params for this View |
|
48 """ |
|
49 |
|
50 rights = access.Checker(params) |
|
51 rights['create'] = ['checkIsDeveloper'] |
|
52 rights['edit'] = [('checkIsMyActiveRole', soc.logic.models.org_admin)] |
|
53 rights['delete'] = ['checkIsDeveloper'] |
|
54 # TODO accessCheck checkIsAdministratorForOrg |
|
55 rights['invite'] = ['checkIsDeveloper'] |
|
56 rights['accept_invite'] = [('checkCanCreateFromRequest', 'org_admin')] |
|
57 # TODO accessCheck checkIsAdministratorForOrg |
|
58 rights['process_request'] = ['checkIsDeveloper', |
|
59 ('checkCanProcessRequest', 'org_admin')] |
|
60 rights['manage'] = [ |
|
61 ('checkIsAllowedToManageRole', [soc.logic.models.org_admin, |
|
62 soc.logic.models.org_admin])] |
|
63 |
|
64 new_params = {} |
|
65 new_params['logic'] = soc.logic.models.org_admin.logic |
|
66 new_params['group_logic'] = org_logic.logic |
|
67 new_params['group_view'] = org_view.view |
|
68 new_params['rights'] = rights |
|
69 |
|
70 new_params['scope_view'] = org_view |
|
71 |
|
72 new_params['name'] = "Organization Admin" |
|
73 new_params['module_name'] = "org_admin" |
|
74 new_params['sidebar_grouping'] = 'Organizations' |
|
75 |
|
76 new_params['extra_dynaexclude'] = ['agreed_to_tos'] |
|
77 |
|
78 new_params['allow_invites'] = True |
|
79 |
|
80 params = dicts.merge(params, new_params) |
|
81 |
|
82 super(View, self).__init__(params=params) |
|
83 |
|
84 # register the role with the group_view |
|
85 params['group_view'].registerRole(params['module_name'], self) |
|
86 |
|
87 # create and store the special form for invited users |
|
88 updated_fields = { |
|
89 'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
|
90 required=False)} |
|
91 |
|
92 invited_create_form = dynaform.extendDynaForm( |
|
93 dynaform = self._params['create_form'], |
|
94 dynafields = updated_fields) |
|
95 |
|
96 params['invited_create_form'] = invited_create_form |
|
97 |
|
98 def _editPost(self, request, entity, fields): |
|
99 """See base.View._editPost(). |
|
100 """ |
|
101 if not entity: |
|
102 fields['user'] = fields['link_id'] |
|
103 fields['link_id'] = fields['user'].link_id |
|
104 |
|
105 super(View, self)._editPost(request, entity, fields) |
|
106 |
|
107 def _acceptInvitePost(self, fields, request, context, params, **kwargs): |
|
108 """Fills in the fields that were missing in the invited_created_form. |
|
109 |
|
110 For params see base.View._acceptInvitePost() |
|
111 """ |
|
112 # fill in the appropriate fields that were missing in the form |
|
113 fields['user'] = fields['link_id'] |
|
114 fields['link_id'] = fields['user'].link_id |
|
115 |
|
116 |
|
117 view = View() |
|
118 |
|
119 accept_invite = view.acceptInvite |
|
120 create = view.create |
|
121 delete = view.delete |
|
122 edit = view.edit |
|
123 invite = view.invite |
|
124 list = view.list |
|
125 manage = view.manage |
|
126 process_request = view.processRequest |
|
127 public = view.public |
|
128 export = view.export |