member._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * $Id: member.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 #include <assert.h>
20 #include <macros.h>
21 #include <database.h>
22 #include <exception.h>
23 class member {
24 public:
25 
26 
27 
28 
29 
30  void require_save(string|void a, string|void b) { _Persistence->require_save(a,b); }
31 
32  array aoGroups;
33 
34 
35 /**
36  * Initialize the member variables. This is only the array of groups.
37  *
38  */
39 private:
40  void init_member()
41 {
42  aoGroups = ({ });
43 }
44 
45 public:
46 
47 /**
48  * The function is called when the object is deleted and it
49  * calls each group then and removes the member from the group.
50  *
51  */
52 protected:
53  void
54 delete_object()
55 {
56  array groups = copy_value(aoGroups);
57  if ( arrayp(groups) ) {
58  object grp;
59  foreach(groups, grp) {
60  }
61  }
62 }
63 
64 public:
65 
66 /**
67  * Get an array of groups of this member.
68  *
69  * @return the groups of the user
70  * @see set_groups
71  */
72 final array
73 get_groups()
74 {
75  aoGroups -= ({ 0 });
76 
77  return copy_value(aoGroups);
78 }
79 
80 /**
81  * Set the groups for this user. Only trusted objects are able to call this
82  * function. In fact I am not sure if this is used at all.
83  *
84  * @param grps - list of groups of the user
85  * @see query_groups
86  */
87 final void
88 set_groups(array grps)
89 {
90  if ( !_SECURITY->trust(CALLER) )
91  THROW("Unauthorized call to set_groups()", E_ACCESS);
92  aoGroups = copy_value(grps);
93  require_save(STORE_GROUP);
94 }
95 
96 /**
97  * join_group() should not be called - instead call group->add_member() !
98  * Invalid calls are checked. The add_member() function will call this
99  * one automatically.
100  *
101  * @param grp - the group to join
102  * @see leave_group
103  */
104 bool
105 join_group(object grp)
106 {
107  ASSERTINFO(IS_PROXY(grp),"Group is not a proxy !");
108  ASSERTINFO(_SECURITY->valid_group(CALLER) && grp->get_object() == CALLER,
109  "Invalid calling object in join_group()");
110 
111  aoGroups += ({ grp });
112  require_save(STORE_GROUP);
113  return true;
114 }
115 
116 /**
117  * This function is called to remove a group from the list of groups.
118  * It should not be called directly. Instead the group has to be called to
119  * remove one of its members. Invalid calls are checked and thrown.
120  *
121  * @param grp - the group to leave
122  * @return successfully or not
123  * @see join_group
124  */
125 bool leave_group(object grp)
126 {
127  ASSERTINFO(IS_PROXY(grp),"Group is not a proxy !");
128  ASSERTINFO(_SECURITY->valid_group(CALLER) && grp->get_object() == CALLER,
129  "Invalid calling object in join_group(): "+
130  master()->describe_object(CALLER));
131  aoGroups -= ({ grp });
132  require_save(STORE_GROUP);
133  return true;
134 }
135 
136 
137 };