Skip to content
This repository was archived by the owner on Oct 29, 2020. It is now read-only.

Commit 7d44475

Browse files
committed
Merge pull request #4533 from weerd/campaign-access
Adding initial access control to a few resources.
2 parents 1055790 + a31f984 commit 7d44475

File tree

6 files changed

+92
-22
lines changed

6 files changed

+92
-22
lines changed

lib/modules/dosomething/dosomething_api/includes/Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ protected function transformCollection($items, $method = 'transform') {
234234
*/
235235
protected function transformCampaign($data) {
236236
$output = array(
237-
'id' => $data->id ?: $data->nid,
237+
'id' => isset($data->id) ? $data->id : $data->nid,
238238
'title' => $data->title,
239239
);
240240

lib/modules/dosomething/dosomething_api/resources/campaign_resource.inc

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function _campaign_resource_definition() {
5555
),
5656
),
5757
'access callback' => '_campaign_resource_alt_access',
58+
'access arguments' => array('view'),
5859
),
5960

6061
),
@@ -188,18 +189,33 @@ function _campaign_resource_access($op = 'view', $args = array()) {
188189
}
189190

190191

191-
function _campaign_resource_alt_access() {
192-
// @TODO: Temp universal access for now.
193-
// Need to rethink how access happens within these callbacks
194-
// for new approach.
195-
return TRUE;
192+
/**
193+
* Determine whether the current user can access campaign resource.
194+
*
195+
* @param string $op
196+
*
197+
* @return bool
198+
*/
199+
function _campaign_resource_alt_access($op) {
200+
// @TODO: replace _campaign_resource_access() with this method once full endpoint switcheroo happens and this method is fleshed out.
201+
if ($op === 'view') {
202+
return TRUE;
203+
}
204+
205+
if ($op === 'index') {
206+
return TRUE;
207+
}
208+
209+
return FALSE;
196210
}
197211

198212

199213
/**
200-
* @param $nid
214+
* Retrieve and show response for campaign request.
215+
*
216+
* @param string $nid
201217
*
202-
* @return mixed
218+
* @return object
203219
*/
204220
function _campaign_resource_retrieve($nid) {
205221
return (new CampaignTransformer)->show($nid);

lib/modules/dosomething/dosomething_api/resources/kudos_resource.inc

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function _kudos_resource_definition() {
2323
),
2424
),
2525
'access callback' => '_kudos_resource_access',
26+
'access arguments' => array('view'),
2627
),
2728

2829
'index' => array(
@@ -46,6 +47,7 @@ function _kudos_resource_definition() {
4647
),
4748
),
4849
'access callback' => '_kudos_resource_access',
50+
'access arguments' => array('index'),
4951
),
5052

5153
'create' => array(
@@ -86,6 +88,7 @@ function _kudos_resource_definition() {
8688
),
8789
),
8890
'access callback' => '_kudos_resource_access',
91+
'access arguments' => array('create'),
8992
),
9093

9194
'delete' => array(
@@ -107,6 +110,7 @@ function _kudos_resource_definition() {
107110
),
108111
),
109112
'access callback' => '_kudos_resource_access',
113+
'access arguments' => array('delete'),
110114
),
111115
),
112116

@@ -116,10 +120,25 @@ function _kudos_resource_definition() {
116120
}
117121

118122

119-
function _kudos_resource_access() {
120-
// @TODO: Temp universal access for now.
121-
// Permissions are still in effect for certain fields returned.
122-
return TRUE;
123+
/**
124+
* Determine whether the current user can access kudos resource.
125+
*
126+
* @param string $op
127+
*
128+
* @return bool
129+
*/
130+
function _kudos_resource_access($op) {
131+
if ($op === 'view') {
132+
return TRUE;
133+
}
134+
135+
if ($op === 'index') {
136+
return TRUE;
137+
}
138+
139+
// @TODO add create & delete and check access with user_access().
140+
141+
return FALSE;
123142
}
124143

125144

@@ -153,4 +172,4 @@ function _kudos_resource_create($reportback_item_id, $user_id, $term_ids) {
153172
function _kudos_resource_delete($kudos_id) {
154173
// Returns number of rows affected.
155174
return dosomething_kudos_delete($kudos_id);
156-
}
175+
}

lib/modules/dosomething/dosomething_api/resources/reportback_item_resource.inc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function _reportback_item_resource_definition() {
2323
),
2424
),
2525
'access callback' => '_reportback_item_resource_access',
26+
'access arguments' => array('view'),
2627
),
2728

2829
'index' => array(
@@ -76,6 +77,7 @@ function _reportback_item_resource_definition() {
7677
),
7778
),
7879
'access callback' => '_reportback_item_resource_access',
80+
'access arguments' => array('index'),
7981
),
8082

8183
),
@@ -86,10 +88,23 @@ function _reportback_item_resource_definition() {
8688
}
8789

8890

89-
function _reportback_item_resource_access() {
90-
// @TODO: Temp universal access for now.
91-
// Permissions are still in effect for certain fields returned.
92-
return TRUE;
91+
/**
92+
* Determine whether the current user can access campaign resource.
93+
*
94+
* @param string $op
95+
*
96+
* @return bool
97+
*/
98+
function _reportback_item_resource_access($op) {
99+
if ($op === 'view') {
100+
return TRUE;
101+
}
102+
103+
if ($op === 'index') {
104+
return TRUE;
105+
}
106+
107+
return FALSE;
93108
}
94109

95110

lib/modules/dosomething/dosomething_api/resources/reportback_resource.inc

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function _reportback_resource_definition() {
2323
),
2424
),
2525
'access callback' => '_reportback_resource_access',
26+
'access arguments' => array('view'),
2627
),
2728

2829
'index' => array(
@@ -76,6 +77,7 @@ function _reportback_resource_definition() {
7677
),
7778
),
7879
'access callback' => '_reportback_resource_access',
80+
'access arguments' => array('index'),
7981
),
8082

8183
),
@@ -86,10 +88,23 @@ function _reportback_resource_definition() {
8688
}
8789

8890

89-
function _reportback_resource_access() {
90-
// @TODO: Temp universal access for now.
91-
// Permissions are still in effect for certain fields returned.
92-
return TRUE;
91+
/**
92+
* Determine whether the current user can access reportback resource.
93+
*
94+
* @param string $op
95+
*
96+
* @return bool
97+
*/
98+
function _reportback_resource_access($op) {
99+
if ($op === 'view') {
100+
return TRUE;
101+
}
102+
103+
if ($op === 'index') {
104+
return TRUE;
105+
}
106+
107+
return FALSE;
93108
}
94109

95110

@@ -110,4 +125,4 @@ function _reportback_resource_index($campaigns, $status, $count, $random, $page)
110125
function _reportback_resource_retrieve($rbid) {
111126
$reportbacks = new ReportbackTransformer;
112127
return $reportbacks->show($rbid);
113-
}
128+
}

lib/modules/dosomething/dosomething_campaign/includes/Campaign.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ protected function getCoverImageAlt() {
186186
*/
187187
protected function getFactData() {
188188
$data = array();
189+
$data['fact_problem'] = NULL;
190+
$data['fact_solution'] = NULL;
191+
$data['sources'] = NULL;
189192

190193
$fact_fields = array('field_fact_problem', 'field_fact_solution');
191194
$fact_vars = dosomething_fact_get_mutiple_fact_field_vars($this->node, $fact_fields);
@@ -206,6 +209,8 @@ protected function getFactData() {
206209
$data['sources'][$index]['formatted'] = $source;
207210
}
208211

212+
213+
209214
return $data;
210215
}
211216

0 commit comments

Comments
 (0)