14 |
14 |
# You should have received a copy of the GNU General Public License
|
15 |
15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
16 |
16 |
|
|
17 |
from quixote import get_publisher
|
|
18 |
|
17 |
19 |
from qommon import _
|
18 |
20 |
from qommon.misc import simplify
|
19 |
21 |
from qommon.storage import StorableObject
|
20 |
22 |
from qommon import get_cfg
|
|
23 |
from qommon.cron import CronJob
|
21 |
24 |
import wcs.qommon.storage as st
|
22 |
25 |
|
23 |
26 |
from qommon.substitution import Substitutions, invalidate_substitution_cache
|
|
27 |
from qommon.publisher import get_publisher_class
|
|
28 |
|
24 |
29 |
|
25 |
30 |
class User(StorableObject):
|
26 |
31 |
_names = 'users'
|
... | ... | |
221 |
226 |
def get_full_name(self):
|
222 |
227 |
return self.display_name
|
223 |
228 |
|
|
229 |
@classmethod
|
|
230 |
def clean_deleted_users(cls):
|
|
231 |
# really delete users without any form
|
|
232 |
if get_publisher().is_using_postgresql():
|
|
233 |
cls.clean_deleted_users_sql()
|
|
234 |
else:
|
|
235 |
cls.clean_deleted_users_pickle()
|
|
236 |
|
|
237 |
@classmethod
|
|
238 |
def clean_deleted_users_sql(cls):
|
|
239 |
from wcs.sql import AnyFormData
|
|
240 |
from wcs.formdef import FormDef
|
|
241 |
|
|
242 |
deleted = cls.select([st.Equal('deleted', True)])
|
|
243 |
deleted_ids = set(str(u.id) for u in deleted)
|
|
244 |
active_ids = set()
|
|
245 |
if FormDef.count():
|
|
246 |
# without any FormDef global views are not created.
|
|
247 |
active_ids = set(f.user_id for f in AnyFormData.select(
|
|
248 |
[st.Contains('user_id', deleted_ids)], iterator=True))
|
|
249 |
to_delete_ids = deleted_ids - active_ids
|
|
250 |
for user_id in to_delete_ids:
|
|
251 |
cls.remove_object(user_id)
|
|
252 |
|
|
253 |
@classmethod
|
|
254 |
def clean_deleted_users_pickle(cls):
|
|
255 |
from wcs.formdef import FormDef
|
|
256 |
|
|
257 |
deleted = cls.select([st.Equal('deleted', True)])
|
|
258 |
deleted_ids = set(str(u.id) for u in deleted)
|
|
259 |
active_ids = set()
|
|
260 |
for formdef in FormDef.select():
|
|
261 |
for formdata in formdef.data_class().select([st.Contains('user_id', deleted_ids)], iterator=True):
|
|
262 |
active_ids.add(str(formdata.user_id))
|
|
263 |
to_delete_ids = deleted_ids - active_ids
|
|
264 |
for user_id in to_delete_ids:
|
|
265 |
cls.remove_object(user_id)
|
|
266 |
|
224 |
267 |
|
225 |
268 |
Substitutions.register('session_user_display_name', category=N_('User'), comment=N_('Session User Display Name'))
|
226 |
269 |
Substitutions.register('session_user_email', category=N_('User'), comment=N_('Session User Email'))
|
227 |
270 |
Substitutions.register_dynamic_source(User)
|
|
271 |
|
|
272 |
if get_publisher_class():
|
|
273 |
# clean deleted users hourly
|
|
274 |
get_publisher_class().register_cronjob(CronJob(User.clean_deleted_users, minutes=[20], hours=[6]))
|
228 |
|
-
|