3D Repo Bouncer  1.4
repo_bson_user.h
1 
22 #pragma once
23 #include "repo_bson.h"
24 
25 namespace repo {
26  namespace core {
27  namespace model {
28  //------------------------------------------------------------------------------
29  //
30  // Fields specific to user only
31  //
32  //------------------------------------------------------------------------------
33 #define REPO_USER_LABEL_AVATAR "avatar"
34 #define REPO_USER_LABEL_CREDENTIALS "credentials"
35 #define REPO_USER_LABEL_CUSTOM_DATA "customData"
36 #define REPO_USER_LABEL_EMAIL "email"
37 #define REPO_USER_LABEL_FIRST_NAME "firstName"
38 #define REPO_USER_LABEL_LAST_NAME "lastName"
39 #define REPO_USER_LABEL_ENCRYPTION "MONGODB-CR"
40 #define REPO_USER_LABEL_CLEARTEXT "cleartext"
41 #define REPO_USER_LABEL_LABEL "label"
42 #define REPO_USER_LABEL_OWNER "account"
43 #define REPO_USER_LABEL_KEY "key"
44 #define REPO_USER_LABEL_PWD "pwd"
45 #define REPO_USER_LABEL_USER "user"
46 #define REPO_USER_LABEL_DB "db"
47 #define REPO_USER_LABEL_ROLES "roles"
48 #define REPO_USER_LABEL_ROLE "role"
49 #define REPO_USER_LABEL_API_KEYS "apiKeys"
50 #define REPO_USER_LABEL_SUBS "subscriptions"
51 #define REPO_USER_LABEL_SUBS_PLAN "plan"
52 #define REPO_USER_LABEL_SUBS_ID "_id"
53 #define REPO_USER_LABEL_SUBS_ACTIVE "active"
54 #define REPO_USER_LABEL_SUBS_CURRENT_AGREE "inCurrentAgreement"
55 #define REPO_USER_LABEL_SUBS_PENDING_DEL "pendingDelete"
56 #define REPO_USER_LABEL_SUBS_TOKEN "token"
57 #define REPO_USER_LABEL_SUBS_CREATED_AT "createdAt"
58 #define REPO_USER_LABEL_SUBS_UPDATED_AT "updatedAt"
59 #define REPO_USER_LABEL_SUBS_EXPIRES_AT "expiredAt"
60 #define REPO_USER_LABEL_SUBS_BILLING_USER "billingUser"
61 #define REPO_USER_LABEL_SUBS_ASSIGNED_USER "assignedUser"
62 #define REPO_USER_LABEL_SUBS_LIMITS "limits"
63 #define REPO_USER_LABEL_SUBS_LIMITS_COLLAB "collaboratorLimit"
64 #define REPO_USER_LABEL_SUBS_LIMITS_SPACE "spaceLimit"
65 
66  //name of free user plan
67 #define REPO_USER_SUBS_STANDARD_FREE "BASIC"
68 
69  class REPO_API_EXPORT RepoUser : public RepoBSON
70  {
71  public:
73  {
74  std::string id;
75  bool active;
76  bool inCurrentAgreement;
77  bool pendingDelete;
78  int64_t updatedAt;
79  int64_t createdAt;
80  int64_t expiresAt;
81  std::string billingUser;
82  std::string assignedUser;
83  std::string token;
84  std::string planName;
85  int collaboratorLimit;
86  double spaceLimit;
87  };
88 
89  RepoUser();
90 
91  RepoUser(RepoBSON bson) : RepoBSON(bson){}
92 
93  ~RepoUser();
94 
98  static SubscriptionInfo createDefaultSub(
99  const int64_t &expireTS = -1);
100 
108  RepoUser cloneAndAddRole(
109  const std::string &dbName,
110  const std::string &role) const;
111 
117  RepoUser cloneAndMergeUserInfo(
118  const RepoUser &newUserInfo) const;
119 
128  RepoUser cloneAndUpdateLicenseCount(
129  const int &diff,
130  const int64_t expDate = -1
131  ) const;
132 
133  RepoUser cloneAndUpdateSubscriptions(
134  const std::vector<SubscriptionInfo> &subs) const;
135 
144  std::list<std::pair<std::string, std::string> > getAPIKeysList() const;
145 
150  std::vector<char> getAvatarAsRawData() const;
151 
156  std::string getCleartextPassword() const;
157 
162  RepoBSON getCustomDataBSON() const;
163 
168  RepoBSON getRolesBSON() const;
169 
174  std::string getFirstName() const
175  {
176  RepoBSON customData = getCustomDataBSON();
177  return customData.isEmpty() ? "" : customData.getStringField(REPO_USER_LABEL_FIRST_NAME);
178  }
179 
184  std::string getLastName() const
185  {
186  RepoBSON customData = getCustomDataBSON();
187  return customData.isEmpty() ? "" : customData.getStringField(REPO_USER_LABEL_LAST_NAME);
188  }
189 
194  std::string getUserName() const
195  {
196  return getStringField(REPO_USER_LABEL_USER);
197  }
198 
203  std::string getEmail() const
204  {
205  RepoBSON customData = getCustomDataBSON();
206  return customData.isEmpty() ? "" : customData.getStringField(REPO_USER_LABEL_EMAIL);
207  }
208 
214  std::list<std::pair<std::string, std::string>> getLicenseAssignment() const;
215 
220  std::string getPassword() const;
221 
226  std::list<std::pair<std::string, std::string>>
227  getRolesList() const;
228 
233  std::vector<SubscriptionInfo> getSubscriptionInfo() const;
234 
239  uint32_t getNCollaborators() const;
240 
245  double getQuota() const;
246 
247  private:
253  bool isSubActive(const RepoUser::SubscriptionInfo &sub) const;
254  };
255  }// end namespace model
256  } // end namespace core
257 } // end namespace repo
Definition: repo_connection_pool_mongo.h:32
std::string getFirstName() const
Definition: repo_bson_user.h:174
std::string getEmail() const
Definition: repo_bson_user.h:203
Definition: repo_bson.h:53
std::string getUserName() const
Definition: repo_bson_user.h:194
std::string getLastName() const
Definition: repo_bson_user.h:184
Definition: repo_bson_user.h:72
Definition: repo_bson_user.h:69