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

Commit

Permalink
Disable toggle WIP status button if user isn't logged-in
Browse files Browse the repository at this point in the history
  • Loading branch information
EpocDotFr committed Apr 29, 2020
1 parent 653231e commit a723632
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@
<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>
</div>
</div>
<div class="pts pbs row">
<div class="pts row">
<div class="w40p txt-center browser-style">
<input type="checkbox" id="enable_button_to_toggle_wip_status">
</div>
<div>
<label for="enable_button_to_toggle_wip_status">Enable button allowing to toggle WIP status</label>
</div>
</div>
<div class="pbs pll">
<small class="txt-muted">This feature is automatically disabled if logged-out</small>
</div>
<div class="txt-center pts pbs"><button type="submit" class="browser-style">Save preferences</button></div>
</form>

Expand Down
12 changes: 10 additions & 2 deletions js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@

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

let currentMergeRequestIds = this.getCurrentMergeRequestIds();
Expand Down Expand Up @@ -167,6 +168,13 @@
return meta ? meta.getAttribute('content') : null;
}

/**
* Determines if the current user is logged-in to GitLab.
*/
isUserAuthenticated() {
return document.querySelector('.navbar-nav .header-user') ? true : false;
}

/**
* Gets all Merge Requests IDs that are currently displayed.
*/
Expand Down Expand Up @@ -199,7 +207,7 @@
self.attachClickEventToCopyMergeRequestInfoButtons();
}

if (self.preferences.enable_button_to_toggle_wip_status) {
if (self.userAuthenticated && self.preferences.enable_button_to_toggle_wip_status) {
self.attachClickEventToToggleWipStatusButtons();
}
} else {
Expand Down Expand Up @@ -275,7 +283,7 @@
// -----------------------------------------------
// Toggle WIP status button

if (this.preferences.enable_button_to_toggle_wip_status) {
if (this.userAuthenticated && this.preferences.enable_button_to_toggle_wip_status) {
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">' +
'<i class="fa fa-wrench" aria-hidden="true"></i>' +
'</button> ';
Expand Down

0 comments on commit a723632

Please sign in to comment.