gitcontacts 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gitcontacts/Request.rb +10 -1
- data/lib/gitcontacts/User.rb +1 -1
- data/lib/gitcontacts/version.rb +1 -1
- data/lib/gitcontacts.rb +78 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d837531ae0cd458381ab3de9f8c7de45bf66dd4d
|
4
|
+
data.tar.gz: f5ac1de4f69c59e31549d5f25d4d71431d8bb378
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86c2493fd291a5c0cc7e84648f1bb072f31fa6530f1184420839509f947d55dae13d1a3c9746f0a4fd063fb9d5b8ac04a8f2bcb6e5b557086d05fd4037af165e
|
7
|
+
data.tar.gz: e2aa8858d3b06a545208e85504656552342b62ef286eb89e613748ac4c9203fdc0a54f3275348a1558591782d0d2a69d60f1887c7c135765e79f38977d6b1896
|
data/lib/gitcontacts/Request.rb
CHANGED
@@ -55,7 +55,16 @@ module GitContacts
|
|
55
55
|
|
56
56
|
# code review: @AustinChou
|
57
57
|
def auto_merge? uid
|
58
|
-
|
58
|
+
if contacts = Contacts.new(getgid)
|
59
|
+
if contacts.getadmins.include? uid
|
60
|
+
return true
|
61
|
+
else
|
62
|
+
case getaction
|
63
|
+
when "setdata" ,"delete"
|
64
|
+
return true if Gitdb::Card.new(getgid).access(getcard_id).getmeta[:owner] == getuid # to-do
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
59
68
|
end
|
60
69
|
|
61
70
|
def allow operator
|
data/lib/gitcontacts/User.rb
CHANGED
data/lib/gitcontacts/version.rb
CHANGED
data/lib/gitcontacts.rb
CHANGED
@@ -34,6 +34,21 @@ module GitContacts
|
|
34
34
|
[user, contacts] if user.getcontacts.include?(gid) && contacts.getusers.include?(operator)
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
def get_a_user operator, uid
|
39
|
+
return unless User.exist?(operator)
|
40
|
+
if User.exist? uid
|
41
|
+
user = User.new uid
|
42
|
+
{
|
43
|
+
:uid => user.getuid,
|
44
|
+
:email => user.getemail,
|
45
|
+
:password => user.getpassword,
|
46
|
+
:contacts => user.getcontacts,
|
47
|
+
:request => user.getrequests
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
37
52
|
# code review: @abbshr
|
38
53
|
# meta => :owner, :gid, :count, :name
|
39
54
|
def get_all_contacts operator
|
@@ -81,7 +96,7 @@ module GitContacts
|
|
81
96
|
return unless GitContacts::relation_valid? operator, gid
|
82
97
|
contacts = Gitdb::Contacts.new operator
|
83
98
|
contacts.access gid
|
84
|
-
contacts.get_card_by_id(card_id).getdata
|
99
|
+
contacts.get_card_by_id(card_id).getdata.merge! card.getmeta
|
85
100
|
end
|
86
101
|
# code review: @abbshr
|
87
102
|
def get_contacts_cards_by_related operator, gid, keyword
|
@@ -90,7 +105,7 @@ module GitContacts
|
|
90
105
|
contacts.access gid
|
91
106
|
contacts.get_cards do |card|
|
92
107
|
info = card.getdata
|
93
|
-
info if (card.getmeta[:owner].include? keyword) || info.find { |k,v| true if v.include? keyword }
|
108
|
+
info.merge! card.getmeta if (card.getmeta[:owner].include? keyword) || info.find { |k,v| true if v.include? keyword }
|
94
109
|
end
|
95
110
|
end
|
96
111
|
# code review: @abbshr
|
@@ -121,38 +136,47 @@ module GitContacts
|
|
121
136
|
end
|
122
137
|
# code review: @abbshr
|
123
138
|
def add_contacts_card operator, gid, payload
|
124
|
-
return unless GitContacts::relation_valid?
|
139
|
+
return unless result = GitContacts::relation_valid?(operator, gid)
|
140
|
+
user = result.first
|
125
141
|
# request id
|
126
142
|
qid = Request::create :uid => operator, :gid => gid, :action => "create"
|
127
|
-
# create a
|
143
|
+
# create a request
|
128
144
|
req = Request.new qid
|
129
145
|
if req.auto_merge? operator
|
130
146
|
# here should return card_id if success
|
131
147
|
cid = req.allow operator
|
132
148
|
Request::delete qid
|
133
149
|
return cid
|
150
|
+
else
|
151
|
+
user.add_request qid
|
134
152
|
end
|
135
153
|
true
|
136
154
|
end
|
137
155
|
# code review: @abbshr
|
138
156
|
def edit_contacts_card operator, gid, card_id, payload
|
139
|
-
return unless GitContacts::relation_valid?
|
157
|
+
return unless result = GitContacts::relation_valid?(operator, gid)
|
158
|
+
user = result.first
|
140
159
|
qid = Request::create :uid => operator, :gid => gid, :action => "setdata", :card_id => card_id, :content => JSON.generate(payload)
|
141
160
|
req = Request.new qid
|
142
161
|
if req.auto_merge? operator
|
143
162
|
req.allow operator
|
144
163
|
Request::delete qid
|
164
|
+
else
|
165
|
+
user.add_request qid
|
145
166
|
end
|
146
167
|
true
|
147
168
|
end
|
148
169
|
# code review: @abbshr
|
149
170
|
def delete_contacts_card operator, gid, card_id
|
150
|
-
return unless GitContacts::relation_valid?
|
171
|
+
return unless result = GitContacts::relation_valid?(operator, gid)
|
172
|
+
user = result.first
|
151
173
|
qid = Request::create :uid => operator, :gid => gid, :action => "delete", :card_id => card_id
|
152
174
|
req = Request.new qid
|
153
175
|
if req.auto_merge? operator
|
154
176
|
req.allow operator
|
155
177
|
Request::delete qid
|
178
|
+
else
|
179
|
+
user.add_request qid
|
156
180
|
end
|
157
181
|
true
|
158
182
|
end
|
@@ -162,6 +186,10 @@ module GitContacts
|
|
162
186
|
contacts = result.last
|
163
187
|
contacts.getusers
|
164
188
|
end
|
189
|
+
def get_contacts_user operator, gid, uid
|
190
|
+
return unless GitContacts::relation_valid?(operator, gid)
|
191
|
+
User.new uid if User.exist? uid
|
192
|
+
end
|
165
193
|
# code review: @abbshr
|
166
194
|
def add_contacts_user operator, gid, uid
|
167
195
|
return unless result = GitContacts::relation_valid?(operator, gid)
|
@@ -172,14 +200,23 @@ module GitContacts
|
|
172
200
|
true
|
173
201
|
end
|
174
202
|
end
|
203
|
+
def remove_contacts_user operator, gid, uid
|
204
|
+
return unless result = GitContacts::relation_valid?(operator, gid)
|
205
|
+
user = result.first
|
206
|
+
contacts = result.last
|
207
|
+
if contacts.getadmins.include?(user.getuid)
|
208
|
+
contacts.remove_user uid
|
209
|
+
true
|
210
|
+
end
|
211
|
+
end
|
175
212
|
|
176
213
|
# code review: @AustinChou
|
177
214
|
def edit_contacts_user_privileges operator, gid, uid, payload
|
178
215
|
return unless result = GitContacts::relation_valid?(operator, gid)
|
179
216
|
user = result.first
|
180
217
|
contacts = result.last
|
181
|
-
if contacts.getadmins.include?(user.getuid)
|
182
|
-
case payload
|
218
|
+
if contacts.getadmins.include?(user.getuid) && contacts.getusers.include?(uid)
|
219
|
+
case payload
|
183
220
|
when "admin"
|
184
221
|
contacts.add_admin uid
|
185
222
|
true
|
@@ -215,10 +252,42 @@ module GitContacts
|
|
215
252
|
|
216
253
|
# code review: @AustinChou
|
217
254
|
def get_all_requests operator
|
255
|
+
requests = []
|
256
|
+
if user = User.new(operator)
|
257
|
+
user.getrequests.each do |qid|
|
258
|
+
requests << Request.new(qid)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
requests
|
262
|
+
end
|
263
|
+
|
264
|
+
def get_a_request operator, qid
|
265
|
+
if user = User.new(operator)
|
266
|
+
Request.new qid if Request.exist? qid
|
267
|
+
end
|
218
268
|
end
|
219
269
|
|
220
270
|
# code review: @AustinChou
|
221
|
-
def edit_request_status operator
|
271
|
+
def edit_request_status operator, qid, payload
|
272
|
+
if req = Request.new(qid)
|
273
|
+
if result = GitContacts::relation_valid?(operator, req.getgid)
|
274
|
+
user = result.first
|
275
|
+
contacts = result.last
|
276
|
+
if contacts.getadmins.include?(user.getuid)
|
277
|
+
case payload
|
278
|
+
when "permit"
|
279
|
+
req.allow operator
|
280
|
+
Request::delete qid
|
281
|
+
when "reject"
|
282
|
+
Request::delete qid
|
283
|
+
end
|
284
|
+
author = User.new req.getuid
|
285
|
+
author.remove_request qid
|
286
|
+
true
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
222
290
|
end
|
291
|
+
|
223
292
|
end
|
224
293
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitcontacts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AustinChou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|