Skip to content

Commit 2cb5235

Browse files
committed
Non-collaborator restrictions on browsing issues.
Non-collaborators are not allowed to change assignee/milestones/labels when browsing issues. Refs pockethub#413
1 parent 00a943e commit 2cb5235

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

app/src/main/java/com/github/mobile/Intents.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public class Intents {
116116
*/
117117
public static final String EXTRA_USERS = INTENT_EXTRA_PREFIX + "USERS";
118118

119+
/**
120+
* Boolean value which indicates if a user is a collaborator on the repo
121+
*/
122+
public static final String EXTRA_IS_COLLABORATOR = INTENT_EXTRA_PREFIX + "IS_COLLABORATOR";
123+
119124
/**
120125
* Issue filter handle
121126
*/

app/src/main/java/com/github/mobile/ui/issue/IssueFragment.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static com.github.mobile.Intents.EXTRA_COMMENT;
2222
import static com.github.mobile.Intents.EXTRA_ISSUE;
2323
import static com.github.mobile.Intents.EXTRA_ISSUE_NUMBER;
24+
import static com.github.mobile.Intents.EXTRA_IS_COLLABORATOR;
2425
import static com.github.mobile.Intents.EXTRA_REPOSITORY_NAME;
2526
import static com.github.mobile.Intents.EXTRA_REPOSITORY_OWNER;
2627
import static com.github.mobile.Intents.EXTRA_USER;
@@ -104,6 +105,8 @@ public class IssueFragment extends DialogFragment {
104105

105106
private User user;
106107

108+
private boolean isCollaborator;
109+
107110
@Inject
108111
private AvatarLoader avatars;
109112

@@ -176,6 +179,7 @@ public void onCreate(Bundle savedInstanceState) {
176179
args.getString(EXTRA_REPOSITORY_NAME));
177180
issueNumber = args.getInt(EXTRA_ISSUE_NUMBER);
178181
user = (User) args.getSerializable(EXTRA_USER);
182+
isCollaborator = args.getBoolean(EXTRA_IS_COLLABORATOR, false);
179183

180184
DialogFragmentActivity dialogActivity = (DialogFragmentActivity) getActivity();
181185

@@ -308,7 +312,7 @@ public void onClick(View v) {
308312
milestoneArea.setOnClickListener(new OnClickListener() {
309313

310314
public void onClick(View v) {
311-
if (issue != null)
315+
if (issue != null && isCollaborator)
312316
milestoneTask.prompt(issue.getMilestone());
313317
}
314318
});
@@ -317,15 +321,15 @@ public void onClick(View v) {
317321
new OnClickListener() {
318322

319323
public void onClick(View v) {
320-
if (issue != null)
324+
if (issue != null && isCollaborator)
321325
assigneeTask.prompt(issue.getAssignee());
322326
}
323327
});
324328

325329
labelsArea.setOnClickListener(new OnClickListener() {
326330

327331
public void onClick(View v) {
328-
if (issue != null)
332+
if (issue != null && isCollaborator)
329333
labelsTask.prompt(issue.getLabels());
330334
}
331335
});

app/src/main/java/com/github/mobile/ui/issue/IssuesPagerAdapter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.github.mobile.ui.issue;
1717

1818
import static com.github.mobile.Intents.EXTRA_ISSUE_NUMBER;
19+
import static com.github.mobile.Intents.EXTRA_IS_COLLABORATOR;
1920
import static com.github.mobile.Intents.EXTRA_REPOSITORY_NAME;
2021
import static com.github.mobile.Intents.EXTRA_REPOSITORY_OWNER;
2122
import static com.github.mobile.Intents.EXTRA_USER;
@@ -51,36 +52,42 @@ public class IssuesPagerAdapter extends FragmentStatePagerAdapter {
5152

5253
private final IssueStore store;
5354

55+
private boolean isCollaborator;
56+
5457
/**
5558
* @param activity
5659
* @param repoIds
5760
* @param issueNumbers
5861
* @param issueStore
62+
* @param collaborator
5963
*/
6064
public IssuesPagerAdapter(SherlockFragmentActivity activity,
6165
List<RepositoryId> repoIds, int[] issueNumbers,
62-
IssueStore issueStore) {
66+
IssueStore issueStore, boolean collaborator) {
6367
super(activity);
6468

6569
repos = repoIds;
6670
repo = null;
6771
issues = issueNumbers;
6872
store = issueStore;
73+
isCollaborator = collaborator;
6974
}
7075

7176
/**
7277
* @param activity
7378
* @param repository
7479
* @param issueNumbers
80+
* @param collaborator
7581
*/
7682
public IssuesPagerAdapter(SherlockFragmentActivity activity,
77-
Repository repository, int[] issueNumbers) {
83+
Repository repository, int[] issueNumbers, boolean collaborator) {
7884
super(activity);
7985

8086
repos = null;
8187
repo = repository;
8288
issues = issueNumbers;
8389
store = null;
90+
isCollaborator = collaborator;
8491
}
8592

8693
@Override
@@ -104,6 +111,7 @@ public Fragment getItem(int position) {
104111
}
105112
}
106113
args.putInt(EXTRA_ISSUE_NUMBER, issues[position]);
114+
args.putBoolean(EXTRA_IS_COLLABORATOR, isCollaborator);
107115
fragment.setArguments(args);
108116
return fragment;
109117
}

app/src/main/java/com/github/mobile/ui/issue/IssuesViewActivity.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,9 @@ protected void onCreate(Bundle savedInstanceState) {
189189
pullRequests = getBooleanArrayExtra(EXTRA_PULL_REQUESTS);
190190
repoIds = getSerializableExtra(EXTRA_REPOSITORIES);
191191
repo = getSerializableExtra(EXTRA_REPOSITORY);
192-
int initialPosition = getIntExtra(EXTRA_POSITION);
193192

194193
setContentView(layout.pager);
195194

196-
pager = finder.find(id.vp_pages);
197-
198-
if (repo != null)
199-
adapter = new IssuesPagerAdapter(this, repo, issueNumbers);
200-
else
201-
adapter = new IssuesPagerAdapter(this, repoIds, issueNumbers, store);
202-
pager.setAdapter(adapter);
203-
204-
pager.setOnPageChangeListener(this);
205-
pager.scheduleSetItem(initialPosition, this);
206-
onPageSelected(initialPosition);
207-
208195
if (repo != null) {
209196
ActionBar actionBar = getSupportActionBar();
210197
actionBar.setSubtitle(repo.generateId());
@@ -233,6 +220,21 @@ protected void onSuccess(Repository fullRepository)
233220
checkCollaboratorStatus();
234221
}
235222

223+
private void configurePager() {
224+
int initialPosition = getIntExtra(EXTRA_POSITION);
225+
pager = finder.find(id.vp_pages);
226+
227+
if (repo != null)
228+
adapter = new IssuesPagerAdapter(this, repo, issueNumbers, isCollaborator);
229+
else
230+
adapter = new IssuesPagerAdapter(this, repoIds, issueNumbers, store, isCollaborator);
231+
pager.setAdapter(adapter);
232+
233+
pager.setOnPageChangeListener(this);
234+
pager.scheduleSetItem(initialPosition, this);
235+
onPageSelected(initialPosition);
236+
}
237+
236238
private void updateTitle(final int position) {
237239
int number = issueNumbers[position];
238240
boolean pullRequest = pullRequests[position];
@@ -301,8 +303,12 @@ protected FragmentProvider getProvider() {
301303

302304
@Override
303305
public boolean onPrepareOptionsMenu(Menu menu) {
304-
menu.findItem(id.m_edit).setVisible(isCollaborator);
305-
menu.findItem(id.m_state).setVisible(isCollaborator);
306+
MenuItem editItem = menu.findItem(id.m_edit);
307+
MenuItem stateItem = menu.findItem(id.m_state);
308+
if (editItem != null && stateItem != null) {
309+
editItem.setVisible(isCollaborator);
310+
stateItem.setVisible(isCollaborator);
311+
}
306312

307313
return super.onPrepareOptionsMenu(menu);
308314
}
@@ -349,6 +355,7 @@ protected void onSuccess(Boolean collaborator) throws Exception {
349355

350356
isCollaborator = collaborator;
351357
invalidateOptionsMenu();
358+
configurePager();
352359
}
353360
}.execute();
354361
}

0 commit comments

Comments
 (0)