1 |
3 |
ahitrov@rambler.ru |
package Contenido::User; |
2 |
|
|
|
3 |
|
|
# ---------------------------------------------------------------------------- |
4 |
|
|
# ������������ |
5 |
|
|
# ---------------------------------------------------------------------------- |
6 |
|
|
|
7 |
|
|
use strict; |
8 |
|
|
use warnings; |
9 |
|
|
use locale; |
10 |
|
|
|
11 |
|
|
use base 'Contenido::Object'; |
12 |
|
|
|
13 |
|
|
use Contenido::Section; |
14 |
|
|
use Contenido::Globals; |
15 |
|
|
|
16 |
|
|
# ���� ���������� ������� |
17 |
|
|
sub class_table |
18 |
|
|
{ |
19 |
|
|
return 'SQL::UserTable'; |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
sub class_name |
23 |
|
|
{ |
24 |
|
|
return '������������'; |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
sub class_description |
28 |
|
|
{ |
29 |
|
|
return '������������'; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
sub extra_properties |
34 |
|
|
{ |
35 |
|
|
return ( |
36 |
|
|
{ 'attr' => 'status', 'type' => 'status', |
37 |
|
|
'cases' => [ |
38 |
|
|
[0, '�� �������'], |
39 |
|
|
[1, '�������'], |
40 |
|
|
], |
41 |
|
|
}, |
42 |
|
|
{ 'attr' => 'passwd', 'type' => 'password', 'rusname' => '������ (<font color="red">�� ������������. ��������� ��� �������� � ��� ���������</font>)' }, |
43 |
|
|
) |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
# ---------------------------------------------------------------------------- |
47 |
|
|
# �����������. ������� ����� ������ ������������... |
48 |
|
|
# |
49 |
|
|
# ������ �������������: |
50 |
|
|
# Contenido::User->new() |
51 |
|
|
# Contenido::User->new($keeper) |
52 |
|
|
# Contenido::User->new($keeper,$login) |
53 |
|
|
# ---------------------------------------------------------------------------- |
54 |
|
|
sub new |
55 |
|
|
{ |
56 |
|
|
my ($proto, $keeper, %args) = @_; |
57 |
|
|
my $class = ref($proto) || $proto; |
58 |
|
|
my $login = $args{login}; |
59 |
|
|
my $id = $args{id}; |
60 |
|
|
my $self; |
61 |
|
|
if (defined($login) && (length($login)>0) && defined($keeper)) { |
62 |
|
|
$self=$keeper->get_user_by_login($login, class=>$class); |
63 |
|
|
} elsif (defined($login) && ($id>0) and defined($keeper)) { |
64 |
|
|
$self=$keeper->get_user_by_id($login, class=>$class); |
65 |
|
|
} else { |
66 |
|
|
$self = {}; |
67 |
|
|
bless($self, $class); |
68 |
|
|
$self->init(); |
69 |
|
|
$self->keeper($keeper) if (defined($keeper)); |
70 |
|
|
$self->{class} = $class; |
71 |
|
|
$self->login($login) if (defined($login) && (length $login > 0)); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
return $self; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
#������������ Contenido �������� �� 1 ������� ����������� |
78 |
|
|
sub _get_table { |
79 |
|
|
return class_table()->new(); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
sub pre_store |
83 |
|
|
{ |
84 |
|
|
my $self = shift; |
85 |
|
|
|
86 |
|
|
if ( $self->id ) { |
87 |
|
|
unless ( $self->passwd ) { |
88 |
|
|
my $up = $keeper->get_document_by_id ( $self->id, |
89 |
|
|
class => ref $self, |
90 |
|
|
); |
91 |
|
|
|
92 |
|
|
unless (ref $up && $up->passwd) { return 0 } |
93 |
|
|
$self->passwd($up->passwd); |
94 |
|
|
} |
95 |
|
|
} |
96 |
|
|
return 1; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
# ---------------------------------------------------------------------------- |
101 |
|
|
# ���������� 1, ���� ���� ������������ ������ � �������� ������. |
102 |
|
|
# |
103 |
|
|
# ������� � ������ Contenido 4.0 |
104 |
|
|
# � �� ����� ���� - ���� ������������ ����� ������ ������ � ������ � �������� ���������������. |
105 |
|
|
# ������ ������ - ��� ������ �� ����� �������. |
106 |
|
|
# ---------------------------------------------------------------------------- |
107 |
|
|
sub check_group { |
108 |
|
|
my ($self, $group) = @_; |
109 |
|
|
|
110 |
|
|
my @groups = $self->groups(); |
111 |
|
|
my %G = map { $_ => 1 } @groups; |
112 |
|
|
|
113 |
|
|
return exists($G{$group}); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
|
117 |
|
|
# ---------------------------------------------------------------------------- |
118 |
|
|
# ���������� ������� ������� � ��������� ������: |
119 |
|
|
# 0 - ��� ������� �� � ������ ������ �� � ţ �������� |
120 |
|
|
# 1 - ���� ������ � �������� ������ ������ �� � ����� ������ ������� ��� |
121 |
|
|
# 2 - ���� ������ ��������������� � ������ ������ ��� ţ �������� �� �����-���� ������ |
122 |
|
|
# �������� - ������������� ������ |
123 |
|
|
# ---------------------------------------------------------------------------- |
124 |
|
|
sub get_section_access |
125 |
|
|
{ |
126 |
|
|
my $self = shift; |
127 |
|
|
my $sectionid = shift; |
128 |
|
|
do { $log->error("����� get_section_access() ����� �������� ������ � ��������, �� �� �������"); die } unless ref($self); |
129 |
|
|
|
130 |
|
|
# ��� ����������� ������ ��������� ������ |
131 |
|
|
my $section = ref $sectionid ? $sectionid : $self->keeper()->get_section_by_id($sectionid); |
132 |
|
|
do { $log->error("����� ->get_section_access: �� ������� ������ $sectionid"); return 2 } unless defined $section; |
133 |
|
|
my $section_id = ref $sectionid ? $sectionid->id : $sectionid; |
134 |
|
|
|
135 |
|
|
# 1. ���������, ���� �� ������ � ��������������� ��������� ������ |
136 |
|
|
my $exact = $self->check_group($section_id); |
137 |
|
|
return 2 if $exact; |
138 |
|
|
|
139 |
|
|
# 2.����������, ���� �� ������ � ��������� ������ ������ |
140 |
|
|
my @ancestors = $section->ancestors(); # ������ |
141 |
|
|
my $ancestor_access = 0; |
142 |
|
|
# 2.1. ���� � ����� �� ���� ��������� (�������) �� ���� ������� � ��������� ������ |
143 |
|
|
foreach (@ancestors) |
144 |
|
|
{ |
145 |
|
|
if ($self->check_group($_)) |
146 |
|
|
{ |
147 |
|
|
$ancestor_access = 1; |
148 |
|
|
last; |
149 |
|
|
} |
150 |
|
|
} |
151 |
|
|
return 2 if $ancestor_access; |
152 |
|
|
|
153 |
|
|
# 3. ����������, ���� �� ������ � �������� ������ ������ |
154 |
|
|
my @descendants = $section->descendants(); # ������� |
155 |
|
|
my $descendant_access = 0; |
156 |
|
|
# 3.1. ���� � ����� �� ���� �������-�������� �� ���� ������� � ��������� ������ |
157 |
|
|
foreach (@descendants) |
158 |
|
|
{ |
159 |
|
|
if ($self->check_group($_)) |
160 |
|
|
{ |
161 |
|
|
$descendant_access = 1; |
162 |
|
|
last; |
163 |
|
|
} |
164 |
|
|
} |
165 |
|
|
return 1 if $descendant_access; |
166 |
|
|
return 0; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
|
170 |
|
|
# ---------------------------------------------------------------------------- |
171 |
|
|
# ����������� �������� �� ����������� ������� ������������ � ������ |
172 |
|
|
# ---------------------------------------------------------------------------- |
173 |
|
|
sub section_accesses |
174 |
|
|
{ |
175 |
|
|
my $self = shift; |
176 |
|
|
my ($user, $section) = @_; |
177 |
|
|
|
178 |
|
|
#another dirty hack for documents without sections |
179 |
|
|
return 2 unless ($section); |
180 |
|
|
|
181 |
|
|
my $section_id = ref $section ? $section->id : $section; |
182 |
|
|
unless (defined $user->{_section_accesses_}->{$section_id}) |
183 |
|
|
{ |
184 |
|
|
$user->{_section_accesses_}->{$section_id} = $user->get_section_access($section); |
185 |
|
|
} |
186 |
|
|
return $user->{_section_accesses_}->{$section_id}; |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
# ---------------------------------------------------------------------------- |
191 |
|
|
# ��� ������� ���������� ���� ��� $self->{section_acesses}, �� �����������. |
192 |
|
|
# �� ���� ���������� ��� ���������� ���� ������� ���� �������� ��� ������, � |
193 |
|
|
# ����� �������� �� ���� �����... |
194 |
|
|
# ---------------------------------------------------------------------------- |
195 |
|
|
sub get_accesses { |
196 |
|
|
my $self = shift; |
197 |
|
|
my $keeper = $self->keeper(); |
198 |
|
|
|
199 |
|
|
my $tree = $keeper->get_tree(light => 1); |
200 |
|
|
# ������ ������ �� ������ ������� ������... |
201 |
|
|
my $trefs = {}; |
202 |
|
|
my @tree_ = ($tree); |
203 |
|
|
$self->{_section_accesses_} = {}; |
204 |
|
|
for my $to (@tree_) { |
205 |
|
|
if (ref($to->{childs}) eq 'ARRAY') { |
206 |
|
|
push (@tree_, @{ $to->{childs} }); |
207 |
|
|
} |
208 |
|
|
$trefs->{$to->id()} = $to; |
209 |
|
|
$self->{_section_accesses_}->{ $to->id() } = 0; |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
# ��������� ��� ������� ��������������... |
213 |
|
|
my @groups = $self->groups(); |
214 |
|
|
for my $g (@groups) { |
215 |
|
|
next if (!exists($trefs->{$g}) || !ref($trefs->{$g}) ); |
216 |
|
|
|
217 |
|
|
# ��� ������ |
218 |
|
|
my @ancestors = (); |
219 |
|
|
my $pid = $trefs->{$g}->pid() || ''; |
220 |
|
|
push (@ancestors, $trefs->{$pid}) if ( |
221 |
|
|
exists($trefs->{$pid}) |
222 |
|
|
&& |
223 |
|
|
ref($trefs->{$pid}) |
224 |
|
|
&& ($g != 1) |
225 |
|
|
); |
226 |
|
|
for my $a (@ancestors) { |
227 |
|
|
push (@ancestors, $trefs->{ $trefs->{ $a->id() }->pid() }) if (exists($trefs->{ $trefs->{ $a->id() }->pid() }) && ref($trefs->{ $trefs->{ $a->id() }->pid() }) && ($a->id() != 1)) |
228 |
|
|
} |
229 |
|
|
for my $a (@ancestors) { |
230 |
|
|
$self->{_section_accesses_}->{$a->id()} = 1 if ($self->{_section_accesses_}->{$a->id()} < 1); |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
# ��� ������� |
234 |
|
|
my @descendants = (); |
235 |
|
|
push (@descendants, @{ $trefs->{$g}->{childs} }) if ( |
236 |
|
|
exists($trefs->{$g}->{childs}) |
237 |
|
|
&& |
238 |
|
|
(ref($trefs->{$g}->{childs}) eq 'ARRAY') |
239 |
|
|
); |
240 |
|
|
for my $d (@descendants) { |
241 |
|
|
push (@descendants, @{ $trefs->{$d->id()}->{childs} }) if (exists($trefs->{ $d->id() }->{childs}) && (ref($trefs->{ $d->id() }->{childs}) eq 'ARRAY')); |
242 |
|
|
} |
243 |
|
|
for my $d (@descendants) { |
244 |
|
|
$self->{_section_accesses_}->{$d->id()} = 2; |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
$self->{_section_accesses_}->{$g} = 2; |
248 |
|
|
} |
249 |
|
|
undef $trefs; |
250 |
|
|
undef @tree_; |
251 |
|
|
undef $tree; |
252 |
|
|
return $self->{_section_accesses_}; |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
# ---------------------------------------------------------------------------- |
256 |
|
|
# ��������� ������ �������, ������������ �����. ��� �� ����������� �������! |
257 |
|
|
# ��� ����� ���� ������ ������ �����������. |
258 |
|
|
# ---------------------------------------------------------------------------- |
259 |
|
|
sub get_available_classes { |
260 |
|
|
my $self = shift; |
261 |
|
|
my $class = ref $self || do { $log->error("����� get_available_classes() ����� �������� ������ � ��������, �� �� �������"); die }; |
262 |
|
|
|
263 |
|
|
return $state->{available_documents}; |
264 |
|
|
} |
265 |
|
|
|
266 |
|
|
1; |
267 |
|
|
|