Commit af91933f99eda376ddc88a8b9b77c9c461905919
1 parent
b831b2b5
Exists in
master
Implementado a opção do usuário excluir seus próprios dados
Showing
4 changed files
with
79 additions
and
10 deletions
Show diff stats
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 | |
14 | 14 | <metal:main fill-slot="main"> |
15 | 15 | |
16 | + <tal:view condition="not: view/was_deleted"> | |
16 | 17 | <div class="row"> |
17 | 18 | <div class="cell width-full position-0 "> |
18 | 19 | <div class="tile azul ui-droppable"> |
... | ... | @@ -62,6 +63,19 @@ |
62 | 63 | </div> |
63 | 64 | </div> |
64 | 65 | </div> |
66 | + </tal:view> | |
67 | + | |
68 | + <tal:view condition="view/was_deleted"> | |
69 | + <h2>Confirmar exclusão</h2> | |
70 | + <p>Você optou por excluir seus dados da Lista Telefônica do DPF.</p> | |
71 | + <p>Clicando no botão "Confirmar Exclusão" abaixo seus dados serão totalmente excluídos da lista. Esta operação é irreversível.</p> | |
72 | + <p>Tem certeza de que deseja continuar?</p> | |
73 | + <a href="" class="btn btn-danger" style="color: #fff" | |
74 | + tal:attributes="href string:${context/absolute_url}/@@lista_delete_data?cancel=yes">Não, foi um engano</a> | |
75 | + <a href="./@@lista_delete_data" class="btn" | |
76 | + tal:attributes="href string:${context/absolute_url}/@@lista_delete_data">Confirmar Exclusão</a> | |
77 | + </tal:view> | |
78 | + | |
65 | 79 | </metal:main> |
66 | 80 | |
67 | 81 | </body> | ... | ... |
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | import json |
4 | 4 | |
5 | +from Products.statusmessages.interfaces import IStatusMessage | |
5 | 6 | from plone import api |
6 | 7 | from five import grok |
7 | 8 | from zope.interface import Interface |
... | ... | @@ -73,7 +74,26 @@ class ListaTelefonicaView(grok.View): |
73 | 74 | return self.context.Description() |
74 | 75 | |
75 | 76 | |
76 | -class PessoaView(grok.View): | |
77 | +class PessoaMixin(object): | |
78 | + | |
79 | + def is_owner(self): | |
80 | + # Get username | |
81 | + current = api.user.get_current() | |
82 | + username = current.getUserName() | |
83 | + | |
84 | + # Check if logged user is object's creator | |
85 | + owner = self.context.Creator() | |
86 | + if username == owner: | |
87 | + return True | |
88 | + return False | |
89 | + | |
90 | + def was_deleted(self): | |
91 | + if self.is_owner() and self.context.excluir_dados: | |
92 | + return True | |
93 | + return False | |
94 | + | |
95 | + | |
96 | +class PessoaView(PessoaMixin, grok.View): | |
77 | 97 | grok.context(IPessoa) |
78 | 98 | grok.require('zope2.View') |
79 | 99 | grok.name('view') |
... | ... | @@ -87,16 +107,32 @@ class PessoaView(grok.View): |
87 | 107 | |
88 | 108 | return "<span>{0}</span> <br /> <span>{1}</span>".format(ramal1, ramal2) |
89 | 109 | |
90 | - def is_owner(self): | |
91 | - # Get username | |
92 | - current = api.user.get_current() | |
93 | - username = current.getUserName() | |
94 | 110 | |
95 | - # Check if logged user is object's creator | |
96 | - owner = self.context.Creator() | |
97 | - if username == owner: | |
98 | - return True | |
99 | - return False | |
111 | +class SelfDeleteData(PessoaMixin, grok.View): | |
112 | + """ """ | |
113 | + grok.context(IPessoa) | |
114 | + grok.require('zope2.View') | |
115 | + grok.name('lista_delete_data') | |
116 | + | |
117 | + def __call__(self): | |
118 | + if not self.was_deleted() or not self.is_owner(): | |
119 | + return self.redirect(self.context.absolute_url()) | |
120 | + self.delete() | |
121 | + return super(SelfDeleteData, self).__call__() | |
122 | + | |
123 | + def delete(self): | |
124 | + if 'cancel' in self.request.form and self.request.form['cancel'] == 'yes': | |
125 | + import transaction | |
126 | + self.context.excluir_dados = False | |
127 | + transaction.commit() | |
128 | + return self.redirect(self.context.absolute_url()) | |
129 | + else: | |
130 | + api.content.delete(self.context) | |
131 | + messages = IStatusMessage(self.request) | |
132 | + messages.add(u'Seus dados foram excluídos com sucesso!', type=u'info') | |
133 | + portal_url = api.portal.get().absolute_url() | |
134 | + url_return = "{0}/lista-telefonica".format(portal_url) | |
135 | + return self.redirect(url_return) | |
100 | 136 | |
101 | 137 | |
102 | 138 | class UnidadesView(grok.View): |
... | ... | @@ -205,6 +241,12 @@ class UnidadesView(grok.View): |
205 | 241 | def update(self): |
206 | 242 | self.persons = self.get_results() |
207 | 243 | |
244 | + def registry(self): | |
245 | + """ """ | |
246 | + portal_url = self.context.absolute_url() | |
247 | + login_url = "{0}/login_form?came_from=after_login".format(portal_url) | |
248 | + return login_url | |
249 | + | |
208 | 250 | |
209 | 251 | class UnidadesIframeView(UnidadesView): |
210 | 252 | grok.name('unidade_iframe') | ... | ... |
... | ... | @@ -89,6 +89,19 @@ class IPessoa(model.Schema): |
89 | 89 | required=False |
90 | 90 | ) |
91 | 91 | |
92 | + excluir_dados = schema.Bool( | |
93 | + title=u"Apagar meus dados", | |
94 | + description=u"Selecione essa opção apenas se tiver absoluta certeza de que deseja apagar todos os seus dados da Lista Telefônica.", | |
95 | + required=False, | |
96 | + default=False, | |
97 | + ) | |
98 | + | |
99 | + model.fieldset( | |
100 | + 'privacidade', | |
101 | + label=u"Privacidade", | |
102 | + fields=['excluir_dados', ] | |
103 | + ) | |
104 | + | |
92 | 105 | |
93 | 106 | @form.default_value(field=IPessoa['email']) |
94 | 107 | def default_email(data): | ... | ... |