Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit a723632

Browse files
committedApr 29, 2020
Disable toggle WIP status button if user isn't logged-in
1 parent 653231e commit a723632

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed
 

‎html/options.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@
4848
<div class="browser-style man"><input type="radio" required name="jira_ticket_link_label_type" value="icon" id="jira_ticket_link_label_type_icon" class="man"> <label for="jira_ticket_link_label_type_icon">An icon</label></div>
4949
</div>
5050
</div>
51-
<div class="pts pbs row">
51+
<div class="pts row">
5252
<div class="w40p txt-center browser-style">
5353
<input type="checkbox" id="enable_button_to_toggle_wip_status">
5454
</div>
5555
<div>
5656
<label for="enable_button_to_toggle_wip_status">Enable button allowing to toggle WIP status</label>
5757
</div>
5858
</div>
59+
<div class="pbs pll">
60+
<small class="txt-muted">This feature is automatically disabled if logged-out</small>
61+
</div>
5962
<div class="txt-center pts pbs"><button type="submit" class="browser-style">Save preferences</button></div>
6063
</form>
6164

‎js/content.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123

124124
this.baseUrl = location.protocol + '//' + location.host;
125125
this.baseApiUrl = this.baseUrl + '/api/v4/';
126+
this.userAuthenticated = this.isUserAuthenticated();
126127
this.apiClient = new GitLabApiClient(this.baseApiUrl, this.getCsrfToken());
127128

128129
let currentMergeRequestIds = this.getCurrentMergeRequestIds();
@@ -167,6 +168,13 @@
167168
return meta ? meta.getAttribute('content') : null;
168169
}
169170

171+
/**
172+
* Determines if the current user is logged-in to GitLab.
173+
*/
174+
isUserAuthenticated() {
175+
return document.querySelector('.navbar-nav .header-user') ? true : false;
176+
}
177+
170178
/**
171179
* Gets all Merge Requests IDs that are currently displayed.
172180
*/
@@ -199,7 +207,7 @@
199207
self.attachClickEventToCopyMergeRequestInfoButtons();
200208
}
201209

202-
if (self.preferences.enable_button_to_toggle_wip_status) {
210+
if (self.userAuthenticated && self.preferences.enable_button_to_toggle_wip_status) {
203211
self.attachClickEventToToggleWipStatusButtons();
204212
}
205213
} else {
@@ -275,7 +283,7 @@
275283
// -----------------------------------------------
276284
// Toggle WIP status button
277285

278-
if (this.preferences.enable_button_to_toggle_wip_status) {
286+
if (this.userAuthenticated && this.preferences.enable_button_to_toggle_wip_status) {
279287
let toggleWipStatusButton = '<button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-toggle-wip-status" title="Toggle WIP status" style="padding-left: 0">' +
280288
'<i class="fa fa-wrench" aria-hidden="true"></i>' +
281289
'</button> ';

0 commit comments

Comments
 (0)
Failed to load comments.