Updated response queryuser
[dashstudio.git] / src / dashserver / project / member.cpp
blobfba546aae8f8f5f8f271d594ebc5dbaffc567adc
1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "member.h"
24 #include <QHash>
25 #include <QString>
27 #include "dashserver/users/user.h"
28 #include "dashserver/xdbms/manager.h"
30 #include "project.h"
32 namespace DashServer {
33 namespace Project {
35 struct Member::Private
37 QHash<QString, Users::Permission *> permissions;
40 Member::Member() : d(new Private)
42 setClass("member");
46 Member::~Member()
48 delete d;
51 void Member::setUser(const QString &login)
53 setId(login);
56 Users::User Member::user() const
58 QString login = id();
60 Users::User user;
61 user.setLogin(login);
63 XDBMS::Manager::self()->load("users", &user);
65 return user;
68 void Member::setJob(const QString &job)
70 add("job", job);
73 QString Member::job() const
75 return value("job");
78 void Member::addPermission(int part, Users::Permission::Opts opts)
80 QString m = Project::partName(part);
82 addPermission(m, opts);
85 void Member::addPermission(const QString &part, Users::Permission::Opts opts)
87 addPermission(new Users::Permission(part, opts));
90 void Member::addPermission(Users::Permission *perm)
92 QString module = perm->module();
94 if( !d->permissions.contains(module) )
96 d->permissions[module] = perm;
97 add(perm);
99 else
101 delete perm;
102 perm = 0;
106 QHash<QString, Users::Permission *> Member::permissions()
108 return d->permissions;
111 bool Member::canReadOn(int part) const
113 QString m = Project::partName(part);
115 if( d->permissions.contains(m) )
117 return d->permissions[m]->read();
120 return false;
123 bool Member::canWriteOn(int part) const
125 QString m = Project::partName(part);
127 if( d->permissions.contains(m) )
129 return d->permissions[m]->write();
132 return false;