credentials.inc.php 2.55 KB
Newer Older
Lukas Fleischer's avatar
Lukas Fleischer committed
1
2
3
4
5
6
7
8
<?php

define("CRED_ACCOUNT_CHANGE_TYPE", 1);
define("CRED_ACCOUNT_EDIT", 2);
define("CRED_ACCOUNT_EDIT_DEV", 3);
define("CRED_ACCOUNT_LAST_LOGIN", 4);
define("CRED_ACCOUNT_SEARCH", 5);
define("CRED_COMMENT_DELETE", 6);
9
define("CRED_COMMENT_UNDELETE", 27);
10
define("CRED_COMMENT_VIEW_DELETED", 22);
Marcel Korpel's avatar
Marcel Korpel committed
11
define("CRED_COMMENT_EDIT", 25);
12
define("CRED_COMMENT_PIN", 26);
Lukas Fleischer's avatar
Lukas Fleischer committed
13
define("CRED_PKGBASE_ADOPT", 7);
14
define("CRED_PKGBASE_SET_KEYWORDS", 8);
Lukas Fleischer's avatar
Lukas Fleischer committed
15
16
define("CRED_PKGBASE_DELETE", 9);
define("CRED_PKGBASE_DISOWN", 10);
17
define("CRED_PKGBASE_EDIT_COMAINTAINERS", 24);
Lukas Fleischer's avatar
Lukas Fleischer committed
18
19
20
21
22
define("CRED_PKGBASE_FLAG", 11);
define("CRED_PKGBASE_LIST_VOTERS", 12);
define("CRED_PKGBASE_NOTIFY", 13);
define("CRED_PKGBASE_UNFLAG", 15);
define("CRED_PKGBASE_VOTE", 16);
23
define("CRED_PKGREQ_FILE", 23);
Lukas Fleischer's avatar
Lukas Fleischer committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
define("CRED_PKGREQ_CLOSE", 17);
define("CRED_PKGREQ_LIST", 18);
define("CRED_TU_ADD_VOTE", 19);
define("CRED_TU_LIST_VOTES", 20);
define("CRED_TU_VOTE", 21);

/**
 * Determine if a user has the permission to perform a given action
 *
 * @param int $credential The type of action to peform
 * @param array $approved_users A user whitelist for this query
 *
 * @return bool Return true if the user has the permission, false if not
 */
function has_credential($credential, $approved_users=array()) {
	if (!isset($_COOKIE['AURSID'])) {
		return false;
	}

	$uid = uid_from_sid($_COOKIE['AURSID']);
	if (in_array($uid, $approved_users)) {
		return true;
	}

	$atype = account_from_sid($_COOKIE['AURSID']);

	switch ($credential) {
	case CRED_PKGBASE_FLAG:
	case CRED_PKGBASE_NOTIFY:
	case CRED_PKGBASE_VOTE:
54
	case CRED_PKGREQ_FILE:
Lukas Fleischer's avatar
Lukas Fleischer committed
55
		return ($atype == 'User' || $atype == 'Trusted User' ||
56
57
			$atype == 'Developer' ||
			$atype == 'Trusted User & Developer');
Lukas Fleischer's avatar
Lukas Fleischer committed
58
59
60
61
62
	case CRED_ACCOUNT_CHANGE_TYPE:
	case CRED_ACCOUNT_EDIT:
	case CRED_ACCOUNT_LAST_LOGIN:
	case CRED_ACCOUNT_SEARCH:
	case CRED_COMMENT_DELETE:
63
	case CRED_COMMENT_UNDELETE:
64
	case CRED_COMMENT_VIEW_DELETED:
Marcel Korpel's avatar
Marcel Korpel committed
65
	case CRED_COMMENT_EDIT:
66
	case CRED_COMMENT_PIN:
Lukas Fleischer's avatar
Lukas Fleischer committed
67
	case CRED_PKGBASE_ADOPT:
68
	case CRED_PKGBASE_SET_KEYWORDS:
Lukas Fleischer's avatar
Lukas Fleischer committed
69
	case CRED_PKGBASE_DELETE:
70
	case CRED_PKGBASE_EDIT_COMAINTAINERS:
Lukas Fleischer's avatar
Lukas Fleischer committed
71
72
73
74
75
	case CRED_PKGBASE_DISOWN:
	case CRED_PKGBASE_LIST_VOTERS:
	case CRED_PKGBASE_UNFLAG:
	case CRED_PKGREQ_CLOSE:
	case CRED_PKGREQ_LIST:
76
77
		return ($atype == 'Trusted User' || $atype == 'Developer' ||
			$atype == 'Trusted User & Developer');
Lukas Fleischer's avatar
Lukas Fleischer committed
78
79
80
	case CRED_TU_ADD_VOTE:
	case CRED_TU_LIST_VOTES:
	case CRED_TU_VOTE:
81
82
		return ($atype == 'Trusted User' ||
			$atype == 'Trusted User & Developer');
Lukas Fleischer's avatar
Lukas Fleischer committed
83
	case CRED_ACCOUNT_EDIT_DEV:
84
85
		return ($atype == 'Developer' ||
			$atype == 'Trusted User & Developer');
Lukas Fleischer's avatar
Lukas Fleischer committed
86
87
88
89
	}

	return false;
}