root/db/role.hh

Revision f2c6ab73bbeb02eb513a3952a380305eeeae60ff, 3.6 KB (checked in by ajk <ajk@…>, 16 months ago)

#82: Integrate sub/unsub messages and email confirmation messages

Signed-off-by: ajk <ajk@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009, 2010, 2011 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#ifndef GUARD_DB_ROLE_HH
21#define GUARD_DB_ROLE_HH
22
23#include <boost/noncopyable.hpp>
24#include <boost/shared_ptr.hpp>
25
26#include <set>
27#include <string>
28
29namespace db
30{
31        class user;
32        class role : private boost::noncopyable
33        {
34                std::string name;
35                std::string description;
36                std::set<boost::shared_ptr<user> > users;
37
38                friend class db;
39                friend class user;
40
41                static const std::string subscriber_prefix;
42                static const std::string moderator_prefix;
43        public:
44                typedef boost::shared_ptr<role> ptr;
45                typedef boost::shared_ptr<const role> const_ptr;
46
47                role(std::string name, std::string descr)
48                        : name(name), description(descr)
49                        {}
50
51                std::string get_name() const { return name; }
52                std::string get_description() const { return name; }
53
54                bool is_moderator() {
55                        return  name.substr(0, moderator_prefix.length())
56                                ==
57                                moderator_prefix;
58                }
59                bool is_moderator_for(std::string grn);
60
61                const std::set<boost::shared_ptr<user> > &get_users() const {
62                        return users;
63                }
64
65                static ptr anon() {
66                        static ptr rv;
67                        if (!rv) rv.reset(new role("anonymous",
68                                                   "Anonymous user"));
69                        return rv;
70                }
71                static ptr authn() {
72                        static ptr rv;
73                        if (!rv) rv.reset(new role("authenticated",
74                                                   "Authenticated user"));
75                        return rv;
76                }
77                static ptr poster() {
78                        static ptr rv;
79                        if (!rv) rv.reset(new role("poster",
80                                                   "Basic poster authorization")
81                                );
82                        return rv;
83                }
84
85                bool is_subscriber_role() const
86                        { return is_subscriber_role(name); }
87
88                std::string whose_subscriber_role() const {
89                        return name.substr(subscriber_prefix.length());
90                }
91
92                static bool is_subscriber_role(std::string str) {
93                        return  str.substr(0, subscriber_prefix.length())
94                                ==
95                                subscriber_prefix;
96                }
97
98                static std::string get_subscriber_role(std::string group) {
99                        return subscriber_prefix + group;
100                }
101        };
102}
103
104#endif /* GUARD_DB_ROLE_HH */
Note: See TracBrowser for help on using the browser.