@@ -77,105 +77,107 @@ def compound_metrics(self, **kwargs):
77
77
return self ._simple_get ('/sidekiq/compound_metrics' , ** kwargs )
78
78
79
79
80
- class UserEmail (GitlabObject ):
81
- _url = '/users/%(user_id)s/emails'
82
- canUpdate = False
83
- shortPrintAttr = 'email'
84
- requiredUrlAttrs = ['user_id' ]
85
- requiredCreateAttrs = ['email' ]
80
+ class UserEmail (RESTObject ):
81
+ _short_print_attr = 'email'
86
82
87
83
88
- class UserEmailManager (BaseManager ):
89
- obj_cls = UserEmail
84
+ class UserEmailManager (RetrieveMixin , CreateMixin , DeleteMixin , RESTManager ):
85
+ _path = '/users/%(user_id)s/emails'
86
+ _obj_cls = UserEmail
87
+ _from_parent_attrs = {'user_id' : 'id' }
88
+ _create_attrs = {'required' : ('email' , ), 'optional' : tuple ()}
90
89
91
90
92
- class UserKey (GitlabObject ):
93
- _url = '/users/%(user_id)s/keys'
94
- canGet = 'from_list'
95
- canUpdate = False
96
- requiredUrlAttrs = ['user_id' ]
97
- requiredCreateAttrs = ['title' , 'key' ]
91
+ class UserKey (RESTObject ):
92
+ pass
98
93
99
94
100
- class UserKeyManager (BaseManager ):
101
- obj_cls = UserKey
95
+ class UserKeyManager (GetFromListMixin , CreateMixin , DeleteMixin , RESTManager ):
96
+ _path = '/users/%(user_id)s/emails'
97
+ _obj_cls = UserKey
98
+ _from_parent_attrs = {'user_id' : 'id' }
99
+ _create_attrs = {'required' : ('title' , 'key' ), 'optional' : tuple ()}
102
100
103
101
104
- class UserProject (GitlabObject ):
105
- _url = '/projects/user/%(user_id)s'
106
- _constructorTypes = {'owner' : 'User' , 'namespace' : 'Group' }
107
- canUpdate = False
108
- canDelete = False
109
- canList = False
110
- canGet = False
111
- requiredUrlAttrs = ['user_id' ]
112
- requiredCreateAttrs = ['name' ]
113
- optionalCreateAttrs = ['default_branch' , 'issues_enabled' , 'wall_enabled' ,
114
- 'merge_requests_enabled' , 'wiki_enabled' ,
115
- 'snippets_enabled' , 'public' , 'visibility' ,
116
- 'description' , 'builds_enabled' , 'public_builds' ,
117
- 'import_url' , 'only_allow_merge_if_build_succeeds' ]
102
+ class UserProject (RESTObject ):
103
+ _constructor_types = {'owner' : 'User' , 'namespace' : 'Group' }
118
104
119
105
120
- class UserProjectManager (BaseManager ):
121
- obj_cls = UserProject
106
+ class UserProjectManager (CreateMixin , RESTManager ):
107
+ _path = '/projects/user/%(user_id)s'
108
+ _obj_cls = UserProject
109
+ _from_parent_attrs = {'user_id' : 'id' }
110
+ _create_attrs = {
111
+ 'required' : ('name' , ),
112
+ 'optional' : ('default_branch' , 'issues_enabled' , 'wall_enabled' ,
113
+ 'merge_requests_enabled' , 'wiki_enabled' ,
114
+ 'snippets_enabled' , 'public' , 'visibility' , 'description' ,
115
+ 'builds_enabled' , 'public_builds' , 'import_url' ,
116
+ 'only_allow_merge_if_build_succeeds' )
117
+ }
122
118
123
119
124
- class User (GitlabObject ):
125
- _url = '/users'
126
- shortPrintAttr = 'username'
127
- optionalListAttrs = ['active' , 'blocked' , 'username' , 'extern_uid' ,
128
- 'provider' , 'external' ]
129
- requiredCreateAttrs = ['email' , 'username' , 'name' ]
130
- optionalCreateAttrs = ['password' , 'reset_password' , 'skype' , 'linkedin' ,
131
- 'twitter' , 'projects_limit' , 'extern_uid' ,
132
- 'provider' , 'bio' , 'admin' , 'can_create_group' ,
133
- 'website_url' , 'skip_confirmation' , 'external' ,
134
- 'organization' , 'location' ]
135
- requiredUpdateAttrs = ['email' , 'username' , 'name' ]
136
- optionalUpdateAttrs = ['password' , 'skype' , 'linkedin' , 'twitter' ,
137
- 'projects_limit' , 'extern_uid' , 'provider' , 'bio' ,
138
- 'admin' , 'can_create_group' , 'website_url' ,
139
- 'skip_confirmation' , 'external' , 'organization' ,
140
- 'location' ]
141
- managers = (
142
- ('emails' , 'UserEmailManager' , [('user_id' , 'id' )]),
143
- ('keys' , 'UserKeyManager' , [('user_id' , 'id' )]),
144
- ('projects' , 'UserProjectManager' , [('user_id' , 'id' )]),
120
+ class User (SaveMixin , RESTObject ):
121
+ _short_print_attr = 'username'
122
+ _managers = (
123
+ ('emails' , 'UserEmailManager' ),
124
+ ('keys' , 'UserKeyManager' ),
125
+ ('projects' , 'UserProjectManager' ),
145
126
)
146
127
147
- def _data_for_gitlab (self , extra_parameters = {}, update = False ,
148
- as_json = True ):
149
- if hasattr (self , 'confirm' ):
150
- self .confirm = str (self .confirm ).lower ()
151
- return super (User , self )._data_for_gitlab (extra_parameters )
152
-
153
128
def block (self , ** kwargs ):
154
- """Blocks the user."""
155
- url = '/users/%s/block' % self .id
156
- r = self .gitlab ._raw_post (url , ** kwargs )
157
- raise_error_from_response (r , GitlabBlockError , 201 )
158
- self .state = 'blocked'
129
+ """Blocks the user.
130
+
131
+ Returns:
132
+ bool: whether the user status has been changed.
133
+ """
134
+ path = '/users/%s/block' % self .id
135
+ server_data = self .manager .gitlab .http_post (path , ** kwargs )
136
+ if server_data is True :
137
+ self ._attrs ['state' ] = 'blocked'
138
+ return server_data
159
139
160
140
def unblock (self , ** kwargs ):
161
- """Unblocks the user."""
162
- url = '/users/%s/unblock' % self .id
163
- r = self .gitlab ._raw_post (url , ** kwargs )
164
- raise_error_from_response (r , GitlabUnblockError , 201 )
165
- self .state = 'active'
141
+ """Unblocks the user.
142
+
143
+ Returns:
144
+ bool: whether the user status has been changed.
145
+ """
146
+ path = '/users/%s/unblock' % self .id
147
+ server_data = self .manager .gitlab .http_post (path , ** kwargs )
148
+ if server_data is True :
149
+ self ._attrs ['state' ] = 'active'
150
+ return server_data
166
151
167
- def __eq__ (self , other ):
168
- if type (other ) is type (self ):
169
- selfdict = self .as_dict ()
170
- otherdict = other .as_dict ()
171
- selfdict .pop ('password' , None )
172
- otherdict .pop ('password' , None )
173
- return selfdict == otherdict
174
- return False
175
152
153
+ class UserManager (CRUDMixin , RESTManager ):
154
+ _path = '/users'
155
+ _obj_cls = User
176
156
177
- class UserManager (BaseManager ):
178
- obj_cls = User
157
+ _list_filters = ('active' , 'blocked' , 'username' , 'extern_uid' , 'provider' ,
158
+ 'external' )
159
+ _create_attrs = {
160
+ 'required' : ('email' , 'username' , 'name' ),
161
+ 'optional' : ('password' , 'reset_password' , 'skype' , 'linkedin' ,
162
+ 'twitter' , 'projects_limit' , 'extern_uid' , 'provider' ,
163
+ 'bio' , 'admin' , 'can_create_group' , 'website_url' ,
164
+ 'skip_confirmation' , 'external' , 'organization' ,
165
+ 'location' )
166
+ }
167
+ _update_attrs = {
168
+ 'required' : ('email' , 'username' , 'name' ),
169
+ 'optional' : ('password' , 'skype' , 'linkedin' , 'twitter' ,
170
+ 'projects_limit' , 'extern_uid' , 'provider' , 'bio' ,
171
+ 'admin' , 'can_create_group' , 'website_url' ,
172
+ 'skip_confirmation' , 'external' , 'organization' ,
173
+ 'location' )
174
+ }
175
+
176
+ def _sanitize_data (self , data , action ):
177
+ new_data = data .copy ()
178
+ if 'confirm' in data :
179
+ new_data ['confirm' ] = str (new_data ['confirm' ]).lower ()
180
+ return new_data
179
181
180
182
181
183
class CurrentUserEmail (GitlabObject ):
0 commit comments