Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 1 | // Copyright 2019 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {LitElement, html, css} from 'lit-element'; |
| 6 | import {store, connectStore} from 'reducers/base.js'; |
| 7 | import * as userV0 from 'reducers/userV0.js'; |
| 8 | import 'elements/chops/chops-button/chops-button.js'; |
| 9 | import 'elements/chops/chops-dialog/chops-dialog.js'; |
| 10 | import {SHARED_STYLES} from 'shared/shared-styles.js'; |
| 11 | |
| 12 | /** |
| 13 | * `<mr-click-throughs>` |
| 14 | * |
| 15 | * An element that displays help dialogs that the user is required |
| 16 | * to click through before they can participate in the community. |
| 17 | * |
| 18 | */ |
| 19 | export class MrClickThroughs extends connectStore(LitElement) { |
| 20 | /** @override */ |
| 21 | constructor() { |
| 22 | super(); |
| 23 | } |
| 24 | |
| 25 | /** @override */ |
| 26 | static get properties() { |
| 27 | return { |
| 28 | userDisplayName: {type: String}, |
| 29 | prefs: {type: Object}, |
| 30 | prefsLoaded: {type: Boolean}, |
| 31 | }; |
| 32 | } |
| 33 | |
| 34 | /** @override */ |
| 35 | static get styles() { |
| 36 | return [SHARED_STYLES, css` |
| 37 | :host { |
| 38 | --chops-dialog-max-width: 800px; |
| 39 | } |
| 40 | h2 { |
| 41 | margin-top: 0; |
| 42 | display: flex; |
| 43 | justify-content: space-between; |
| 44 | font-weight: normal; |
| 45 | border-bottom: 2px solid white; |
| 46 | font-size: var(--chops-large-font-size); |
| 47 | padding-bottom: 0.5em; |
| 48 | } |
| 49 | .edit-actions { |
| 50 | width: 100%; |
| 51 | margin: 0.5em 0; |
| 52 | text-align: right; |
| 53 | } |
| 54 | `]; |
| 55 | } |
| 56 | |
| 57 | /** @override */ |
| 58 | render() { |
| 59 | return html` |
| 60 | <chops-dialog |
| 61 | id="privacyDialog" |
| 62 | ?opened=${this._showPrivacyDialog} |
| 63 | forced |
| 64 | > |
| 65 | <h2>Email display settings</h2> |
| 66 | |
| 67 | <p>There is a <a href="/hosting/settings">setting</a> to control how |
| 68 | your email address appears on comments and issues that you post.</p> |
| 69 | |
| 70 | <p>Project members will always see your full email address. By |
| 71 | default, other users who visit the site will see an |
| 72 | abbreviated version of your email address.</p> |
| 73 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 74 | |
| 75 | <div class="edit-actions"> |
| 76 | <chops-button @click=${this.dismissPrivacyDialog}> |
| 77 | Got it |
| 78 | </chops-button> |
| 79 | </div> |
| 80 | </chops-dialog> |
| 81 | |
| 82 | <chops-dialog |
| 83 | id="corpModeDialog" |
| 84 | ?opened=${this._showCorpModeDialog} |
| 85 | forced |
| 86 | > |
| 87 | <h2>This site hosts public issues in public projects</h2> |
| 88 | |
| 89 | <p>Unlike our internal issue tracker, this site makes most |
| 90 | issues public, unless the issue is labeled with a Restrict-View-* |
| 91 | label, such as Restrict-View-Google.</p> |
| 92 | |
| 93 | <p>Components are not used for permissions. And, regardless of |
| 94 | restriction labels, the issue reporter, owner, |
| 95 | and Cc'd users may always view the issue.</p> |
| 96 | |
| 97 | ${this.prefs.get('restrict_new_issues') ? html` |
| 98 | <p>Your account is a member of a user group that indicates that |
| 99 | you may have access to confidential information. To help prevent |
| 100 | leaks when working in public projects, the issue tracker UX has |
| 101 | been altered for you:</p> |
| 102 | |
| 103 | <ul> |
| 104 | <li>When you open a new issue, the form will initially have a |
| 105 | Restrict-View-Google label. If you know that your issue does |
| 106 | not contain confidential information, please remove the label.</li> |
| 107 | <li>When you view public issues, a red banner is shown to remind |
| 108 | you that any comments or attachments you post will be public.</li> |
| 109 | </ul> |
| 110 | ` : ''} |
| 111 | |
| 112 | <div class="edit-actions"> |
| 113 | <chops-button @click=${this.dismissCorpModeDialog}> |
| 114 | Got it |
| 115 | </chops-button> |
| 116 | </div> |
| 117 | </chops-dialog> |
| 118 | `; |
| 119 | } |
| 120 | |
| 121 | /** @override */ |
| 122 | stateChanged(state) { |
| 123 | this.prefs = userV0.prefs(state); |
| 124 | this.prefsLoaded = userV0.currentUser(state).prefsLoaded; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Checks whether the user should see a dialogue telling them about |
| 129 | * Monorail's privacy settings. |
| 130 | */ |
| 131 | get _showPrivacyDialog() { |
| 132 | if (!this.userDisplayName) return false; |
| 133 | if (!this.prefsLoaded) return false; |
| 134 | if (!this.prefs) return false; |
| 135 | if (this.prefs.get('privacy_click_through')) return false; |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Computes whether the user should see the dialog telling them about corp mode. |
| 141 | */ |
| 142 | get _showCorpModeDialog() { |
| 143 | // TODO(jrobbins): Replace this with a API call that gets the project. |
| 144 | if (window.CS_env.projectIsRestricted) return false; |
| 145 | if (!this.userDisplayName) return false; |
| 146 | if (!this.prefsLoaded) return false; |
| 147 | if (!this.prefs) return false; |
| 148 | if (!this.prefs.get('public_issue_notice')) return false; |
| 149 | if (this.prefs.get('corp_mode_click_through')) return false; |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Event handler for dismissing Monorail's privacy notice. |
| 155 | */ |
| 156 | dismissPrivacyDialog() { |
| 157 | this.dismissCue('privacy_click_through'); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Event handler for dismissing corp mode. |
| 162 | */ |
| 163 | dismissCorpModeDialog() { |
| 164 | this.dismissCue('corp_mode_click_through'); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Dispatches a Redux action to tell Monorail's backend that the user |
| 169 | * clicked through a particular cue. |
| 170 | * @param {string} pref The pref to set to true. |
| 171 | */ |
| 172 | dismissCue(pref) { |
| 173 | const newPrefs = [{name: pref, value: 'true'}]; |
| 174 | store.dispatch(userV0.setPrefs(newPrefs, !!this.userDisplayName)); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | customElements.define('mr-click-throughs', MrClickThroughs); |