Skip to content

Commit 00a943e

Browse files
committed
Do not show 'Edit' and 'Close' issues menu to non-collaborators
Refs pockethub#413
1 parent 6fe3733 commit 00a943e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

+40
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@
2121
import static com.github.mobile.Intents.EXTRA_POSITION;
2222
import static com.github.mobile.Intents.EXTRA_REPOSITORIES;
2323
import static com.github.mobile.Intents.EXTRA_REPOSITORY;
24+
import android.accounts.Account;
2425
import android.content.Intent;
2526
import android.os.Bundle;
2627

2728
import com.actionbarsherlock.app.ActionBar;
29+
import com.actionbarsherlock.view.Menu;
2830
import com.actionbarsherlock.view.MenuItem;
2931
import com.github.mobile.Intents.Builder;
3032
import com.github.mobile.R.id;
3133
import com.github.mobile.R.layout;
3234
import com.github.mobile.R.string;
35+
import com.github.mobile.accounts.AccountUtils;
36+
import com.github.mobile.accounts.AuthenticatedUserTask;
3337
import com.github.mobile.core.issue.IssueStore;
3438
import com.github.mobile.core.issue.IssueUtils;
3539
import com.github.mobile.core.repo.RefreshRepositoryTask;
@@ -51,6 +55,7 @@
5155
import org.eclipse.egit.github.core.RepositoryId;
5256
import org.eclipse.egit.github.core.RepositoryIssue;
5357
import org.eclipse.egit.github.core.User;
58+
import org.eclipse.egit.github.core.service.CollaboratorService;
5459

5560
/**
5661
* Activity to display a collection of issues or pull requests in a pager
@@ -164,8 +169,13 @@ public static Intent createIntent(Collection<? extends Issue> issues,
164169
@Inject
165170
private IssueStore store;
166171

172+
@Inject
173+
private CollaboratorService collaboratorService;
174+
167175
private final AtomicReference<User> user = new AtomicReference<User>();
168176

177+
private boolean isCollaborator;
178+
169179
private IssuesPagerAdapter adapter;
170180

171181
private final UrlLauncher urlLauncher = new UrlLauncher(this);
@@ -218,6 +228,9 @@ protected void onSuccess(Repository fullRepository)
218228
fullRepository.getOwner());
219229
}
220230
}.execute();
231+
232+
isCollaborator = false;
233+
checkCollaboratorStatus();
221234
}
222235

223236
private void updateTitle(final int position) {
@@ -286,6 +299,14 @@ protected FragmentProvider getProvider() {
286299
return adapter;
287300
}
288301

302+
@Override
303+
public boolean onPrepareOptionsMenu(Menu menu) {
304+
menu.findItem(id.m_edit).setVisible(isCollaborator);
305+
menu.findItem(id.m_state).setVisible(isCollaborator);
306+
307+
return super.onPrepareOptionsMenu(menu);
308+
}
309+
289310
@Override
290311
public boolean onOptionsItemSelected(MenuItem item) {
291312
switch (item.getItemId()) {
@@ -312,4 +333,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
312333
return super.onOptionsItemSelected(item);
313334
}
314335
}
336+
337+
private void checkCollaboratorStatus() {
338+
new AuthenticatedUserTask<Boolean>(this) {
339+
340+
@Override
341+
protected Boolean run(Account account) throws Exception {
342+
return collaboratorService.isCollaborator(
343+
repo, AccountUtils.getLogin(IssuesViewActivity.this));
344+
}
345+
346+
@Override
347+
protected void onSuccess(Boolean collaborator) throws Exception {
348+
super.onSuccess(collaborator);
349+
350+
isCollaborator = collaborator;
351+
invalidateOptionsMenu();
352+
}
353+
}.execute();
354+
}
315355
}

0 commit comments

Comments
 (0)