xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit f2626cb2fcfedd9c567b1fa50ce9521981241693

Sort rights by prio for real
Author: Catalin(ux) M. BOIE
Author date (UTC): 2015-12-18 05:49
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2015-12-18 05:49
Parent(s): 1c50981db99bc9ba05cfa1a6e735eddc3af2a0e8
Signing key:
Tree: 5492187fe313335b5b679f255f92b51da863704e
File Lines added Lines deleted
inc/rights.inc.php 76 55
root/themes/default/user/repo/rights/list_repo/line.html 1 1
root/themes/default/user/repo/rights/list_repo_path/line.html 1 1
root/themes/default/user/repo/rights/list_repo_refs/line.html 1 1
File inc/rights.inc.php changed (mode: 100644) (index 2543306..0509c04)
... ... function rg_rights_cosmetic($db, &$row)
228 228
229 229 $_a = rg_xss_safe(trim($row['description'])); $_a = rg_xss_safe(trim($row['description']));
230 230 $row['HTML:description_nlbr'] = nl2br($_a); $row['HTML:description_nlbr'] = nl2br($_a);
231
232 if (isset($row['prio'])) {
233 if (($row['prio'] >= 10) && ($row['prio'] <= 30000))
234 $row['can_be_deleted'] = 1;
235 else
236 $row['can_be_deleted'] = 0;
237 }
231 238 } }
232 239
233 240 /* /*
 
... ... function rg_rights_load($db, $obj_id, $type)
240 247
241 248 $ret = FALSE; $ret = FALSE;
242 249 while (1) { while (1) {
250 $key = "rights_by_obj_id::$obj_id::$type";
251 $r = rg_cache_get($key);
252 if ($r !== FALSE) {
253 $ret = $r;
254 break;
255 }
256
243 257 $params = array("type" => $type, "obj_id" => $obj_id); $params = array("type" => $type, "obj_id" => $obj_id);
244 258 $sql = "SELECT * FROM rights" $sql = "SELECT * FROM rights"
245 259 . " WHERE type = @@type@@" . " WHERE type = @@type@@"
246 260 . " AND obj_id = @@obj_id@@" . " AND obj_id = @@obj_id@@"
247 . " ORDER BY prio";
261 . " ORDER BY prio, itime";
248 262 $res = rg_sql_query_params($db, $sql, $params); $res = rg_sql_query_params($db, $sql, $params);
249 263 if ($res === FALSE) { if ($res === FALSE) {
250 rg_rights_set_error("cannot get info (" . rg_sql_error() . ")!");
264 rg_rights_set_error("cannot get info");
251 265 break; break;
252 266 } }
253 267
268 // TODO: we have a problem when we delete a right: we
269 // have to invalidate them all. Index by right_id!
270
254 271 $ret = array(); $ret = array();
255 while (($row = rg_sql_fetch_array($res))) {
256 rg_rights_cosmetic($db, $row);
257 $row['can_be_deleted'] = 1;
272 while (($row = rg_sql_fetch_array($res)))
258 273 $ret[] = $row; $ret[] = $row;
259 }
260 274 rg_sql_free_result($res); rg_sql_free_result($res);
261 275
276 rg_cache_set($key, $ret, RG_SOCKET_NO_WAIT);
262 277 break; break;
263 278 } }
264 279
 
... ... function rg_rights_load($db, $obj_id, $type)
267 282 return $ret; return $ret;
268 283 } }
269 284
285 /*
286 * Helper for rg_rights_sort
287 */
288 function rg_rights_sort_helper($a, $b)
289 {
290 if ($a['prio'] > $b['prio'])
291 return 1;
292
293 if ($a['prio'] == $b['prio'])
294 return 0;
295
296 return -1;
297 }
298
270 299 /* /*
271 300 * Get rights for an object * Get rights for an object
272 301 * @uid - the uid of the (normally) logged in user. If -1, do not filter by uid. * @uid - the uid of the (normally) logged in user. If -1, do not filter by uid.
 
... ... function rg_rights_get($db, $obj_id, $type, $owner, $uid, $right_id)
285 314 $ret['ok'] = 0; $ret['ok'] = 0;
286 315 $ret['list'] = array(); $ret['list'] = array();
287 316 while (1) { while (1) {
288 $key = "rights_by_obj_id::$obj_id::$type";
289 $r = rg_cache_get($key);
290 if ($r === FALSE) {
291 //rg_log("CHECK: rights_get: key not found in cache! Search in DB.");
292
293 $r = array();
294
295 // Inject rights for owner
296 if ($owner > 0) {
297 $a = array();
298 $a['type'] = $type;
299 $a['obj_id'] = $obj_id;
300 $a['uid'] = $owner;
301 $a['itime'] = 0;
302 $a['misc'] = "";
303 $a['prio'] = 0;
304 $a['who'] = $owner;
305 $a['right_id'] = 0;
306 $a['ip'] = "";
307 $a['can_be_deleted'] = 0;
308 $a['rights'] = rg_rights_all($type);
309 $a['description'] = 'Autogenerated (owner)';
310 rg_rights_cosmetic($db, $a);
311
312 $r[] = $a;
313 //rg_log_ml("rights_get: inject all rights for owner");
314 }
315
316 // Inject specific rights
317 if (isset($rg_rights_inject[$type])) {
318 $f = $rg_rights_inject[$type];
319 $rows = $f($db, $obj_id, $type, $owner, $uid);
320 //rg_log_ml("CHECK: inject function for '$type' [$f] returned: " . print_r($rows, TRUE));
321 foreach ($rows as $row) {
322 rg_rights_cosmetic($db, $row);
323 //rg_log_ml("rights_get: inject specific rights: " . print_r($row, TRUE));
324 $r[] = $row;
325 }
326 }
327
328 $x = rg_rights_load($db, $obj_id, $type);
329 if ($x === FALSE)
330 break;
317 $r = rg_rights_load($db, $obj_id, $type);
318 if ($r === FALSE)
319 break;
331 320
332 $r = array_merge($r, $x);
321 // Inject rights for owner
322 if ($owner > 0) {
323 $a = array();
324 $a['type'] = $type;
325 $a['obj_id'] = $obj_id;
326 $a['uid'] = $owner;
327 $a['itime'] = 0;
328 $a['misc'] = '';
329 $a['prio'] = 0;
330 $a['who'] = $owner;
331 $a['right_id'] = 0;
332 $a['ip'] = '';
333 $a['can_be_deleted'] = 0;
334 $a['rights'] = rg_rights_all($type);
335 $a['description'] = 'Autogenerated (owner)';
336 rg_rights_cosmetic($db, $a);
337
338 $r[] = $a;
339 }
333 340
334 // We store the big list
335 rg_cache_set($key, $r, RG_SOCKET_NO_WAIT);
336 } else {
337 //rg_log("CHECK: rights returned from cache for key $key");
341 // Inject specific rights
342 if (isset($rg_rights_inject[$type])) {
343 $f = $rg_rights_inject[$type];
344 $rows = $f($db, $obj_id, $type, $owner, $uid);
345 //rg_log_ml("CHECK: inject function for '$type' [$f] returned: " . print_r($rows, TRUE));
346 foreach ($rows as $row) {
347 //rg_log_ml("rights_get: inject specific rights: " . print_r($row, TRUE));
348 $r[] = $row;
349 }
338 350 } }
339 351
340 352 // now, filter by uid and right_id // now, filter by uid and right_id
 
... ... function rg_rights_get($db, $obj_id, $type, $owner, $uid, $right_id)
345 357 if (($uid == -1) || ($v['uid'] == $uid) || ($v['uid'] == 0)) if (($uid == -1) || ($v['uid'] == $uid) || ($v['uid'] == 0))
346 358 $ret['list'][] = $v; $ret['list'][] = $v;
347 359 } }
348 $ret['ok'] = 1;
349 360
361 // sorting by prio
362 uasort($r, 'rg_rights_sort_helper');
363
364 // cosmetic
365 rg_log_ml('before cosmetic: ' . print_r($r, TRUE));
366 foreach ($r as $index => &$row)
367 rg_rights_cosmetic($db, $row);
368
369 $ret['list'] = $r;
370 $ret['ok'] = 1;
350 371 break; break;
351 372 } }
352 373
File root/themes/default/user/repo/rights/list_repo/line.html changed (mode: 100644) (index 0581e59..390cab0)
6 6 <td>@@username@@</td> <td>@@username@@</td>
7 7 <td>@@ip_nice@@</td> <td>@@ip_nice@@</td>
8 8 <td>@@rights_text@@</td> <td>@@rights_text@@</td>
9 <td>@@description_nlbr@@</td>
9 <td><small>@@description_nlbr@@</small></td>
10 10 <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/repo_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td> <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/repo_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td>
11 11 </tr> </tr>
File root/themes/default/user/repo/rights/list_repo_path/line.html changed (mode: 100644) (index fdb0cc5..4dfbd0f)
7 7 <td>@@ip_nice@@</td> <td>@@ip_nice@@</td>
8 8 <td>@@misc@@</td> <td>@@misc@@</td>
9 9 <td>@@rights_text@@</td> <td>@@rights_text@@</td>
10 <td>@@description_nlbr@@</td>
10 <td><small>@@description_nlbr@@</small></td>
11 11 <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/path_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td> <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/path_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td>
12 12 </tr> </tr>
File root/themes/default/user/repo/rights/list_repo_refs/line.html changed (mode: 100644) (index 67e9b10..61d1c58)
7 7 <td>@@ip_nice@@</td> <td>@@ip_nice@@</td>
8 8 <td>@@misc@@</td> <td>@@misc@@</td>
9 9 <td>@@rights_text@@</td> <td>@@rights_text@@</td>
10 <td>@@description_nlbr@@</td>
10 <td><small>@@description_nlbr@@</small></td>
11 11 <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/refs_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td> <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/refs_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td>
12 12 </tr> </tr>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master