1 """special management views to manage repository content (initialization and |
1 """special management views to manage repository content (initialization and |
2 restoration). |
2 restoration). |
3 |
3 |
4 :organization: Logilab |
4 :organization: Logilab |
5 :copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
10 from os.path import exists, join, abspath |
10 from os.path import exists, join, abspath |
11 from pickle import loads, dumps |
11 from pickle import loads, dumps |
12 |
12 |
13 from logilab.common.decorators import cached |
13 from logilab.common.decorators import cached |
14 from logilab.mtconverter import html_escape |
14 from logilab.mtconverter import html_escape |
15 |
15 |
|
16 from cubicweb.selectors import none_rset, match_user_groups |
16 from cubicweb.common.view import StartupView |
17 from cubicweb.common.view import StartupView |
17 from cubicweb.web import Redirect |
18 from cubicweb.web import Redirect |
18 from cubicweb.goa.dbinit import fix_entities, init_persistent_schema, insert_versions |
19 from cubicweb.goa.dbinit import fix_entities, init_persistent_schema, insert_versions |
19 |
20 |
20 from google.appengine.api.datastore import Entity, Key, Get, Put, Delete |
21 from google.appengine.api.datastore import Entity, Key, Get, Put, Delete |
37 class AuthInfo(StartupView): |
38 class AuthInfo(StartupView): |
38 """special management view to get cookie values to give to laxctl commands |
39 """special management view to get cookie values to give to laxctl commands |
39 which are doing datastore administration requests |
40 which are doing datastore administration requests |
40 """ |
41 """ |
41 id = 'authinfo' |
42 id = 'authinfo' |
42 require_groups = ('managers',) |
43 __select__ = none_rset() & match_user_groups('managers') |
43 |
44 |
44 def call(self): |
45 def call(self): |
45 cookie = self.req.get_cookie() |
46 cookie = self.req.get_cookie() |
46 values = [] |
47 values = [] |
47 if self.config['use-google-auth']: |
48 if self.config['use-google-auth']: |
51 values.append('%s=%s' % (param, morsel.value)) |
52 values.append('%s=%s' % (param, morsel.value)) |
52 break |
53 break |
53 values.append('__session=%s' % cookie['__session'].value) |
54 values.append('__session=%s' % cookie['__session'].value) |
54 self.w(u"<p>pass this flag to the client: --cookie='%s'</p>" |
55 self.w(u"<p>pass this flag to the client: --cookie='%s'</p>" |
55 % html_escape('; '.join(values))) |
56 % html_escape('; '.join(values))) |
56 |
57 |
57 |
58 |
58 |
59 |
59 class ContentInit(StartupView): |
60 class ContentInit(StartupView): |
60 """special management view to initialize content of a repository, |
61 """special management view to initialize content of a repository, |
61 step by step to avoid depassing quotas |
62 step by step to avoid depassing quotas |
62 """ |
63 """ |
63 id = 'contentinit' |
64 id = 'contentinit' |
64 require_groups = ('managers',) |
65 __select__ = none_rset() & match_user_groups('managers') |
65 |
66 |
66 def server_session(self): |
67 def server_session(self): |
67 ssession = self.config.repo_session(self.req.cnx.sessionid) |
68 ssession = self.config.repo_session(self.req.cnx.sessionid) |
68 ssession.set_pool() |
69 ssession.set_pool() |
69 return ssession |
70 return ssession |
71 def end_core_step(self, msg, status, stepid): |
72 def end_core_step(self, msg, status, stepid): |
72 status['cpath'] = '' |
73 status['cpath'] = '' |
73 status['stepid'] = stepid |
74 status['stepid'] = stepid |
74 Put(status) |
75 Put(status) |
75 self.msg(msg) |
76 self.msg(msg) |
76 |
77 |
77 def call(self): |
78 def call(self): |
78 status = _get_status('creation') |
79 status = _get_status('creation') |
79 if status.get('finished'): |
80 if status.get('finished'): |
80 self.redirect('process already completed') |
81 self.redirect('process already completed') |
81 config = self.config |
82 config = self.config |
146 % cpath) |
147 % cpath) |
147 self.w(u'<div>click <a href="%s?vid=contentclear">here</a> to ' |
148 self.w(u'<div>click <a href="%s?vid=contentclear">here</a> to ' |
148 '<b>delete all datastore content</b> so process can be ' |
149 '<b>delete all datastore content</b> so process can be ' |
149 'reinitialized</div>' % html_escape(self.req.base_url())) |
150 'reinitialized</div>' % html_escape(self.req.base_url())) |
150 Put(status) |
151 Put(status) |
151 |
152 |
152 @property |
153 @property |
153 @cached |
154 @cached |
154 def _migrhandler(self): |
155 def _migrhandler(self): |
155 return self.config.migration_handler(self.schema, interactive=False, |
156 return self.config.migration_handler(self.schema, interactive=False, |
156 cnx=self.req.cnx, |
157 cnx=self.req.cnx, |
161 def redirect(self, msg): |
162 def redirect(self, msg): |
162 raise Redirect(self.req.build_url('', msg)) |
163 raise Redirect(self.req.build_url('', msg)) |
163 def continue_link(self): |
164 def continue_link(self): |
164 self.w(u'<a href="%s">continue</a><br/>' % html_escape(self.req.url())) |
165 self.w(u'<a href="%s">continue</a><br/>' % html_escape(self.req.url())) |
165 |
166 |
166 |
167 |
167 class ContentClear(StartupView): |
168 class ContentClear(StartupView): |
168 id = 'contentclear' |
169 id = 'contentclear' |
169 require_groups = ('managers',) |
170 __select__ = none_rset() & match_user_groups('managers') |
170 skip_etypes = ('EGroup', 'EUser') |
171 skip_etypes = ('CWGroup', 'CWUser') |
171 |
172 |
172 def call(self): |
173 def call(self): |
173 # XXX should use unsafe_execute with all hooks deactivated |
174 # XXX should use unsafe_execute with all hooks deactivated |
174 # XXX step by catching datastore errors? |
175 # XXX step by catching datastore errors? |
175 for eschema in self.schema.entities(): |
176 for eschema in self.schema.entities(): |
176 if eschema.is_final() or eschema in self.skip_etypes: |
177 if eschema.is_final() or eschema in self.skip_etypes: |