Basic SVN management web UI works.
[pillar-svnman.git] / src / templates / svnman / project_settings / settings.pug
1 | {% extends 'svnman/project_settings/svnman_layout.html'  %}
2
3 | {% block head %}
4 | {{ super() }}
5 style.
6         section {
7                 margin-bottom: 2.5em;
8         }
9         .access-users-list td {
10                 padding: 0 0.2em;
11         }
12         .access-users-list tr.self td {
13                 font-weight: bold;
14         }
15 | {% endblock head %}
16
17 | {% block svnman_container %}
18 #node-edit-form
19         section
20                 h4 Using the repository
21
22                 p This project has a Subversion repository. To do a checkout, use:
23                 p
24                         code svn checkout {{ svn_url }} my_repo
25
26         section
27                 h4 Manage Access
28                 p.
29                         Users in this list have read/write access to the Subversion repository. It is not
30                         possible to allow read-only access. Their password is <em>not</em> their Blender ID
31                         password, but has to be set separately.
32                 p.
33                         Your login for Subversion is <a href='{{ url_for('settings.profile') }}'>your username</a>
34                         as it was at the moment you were granted access to the repository.
35
36                 .access-users-search
37                         .form-group
38                                 input#user-search.form-control(
39                                         name='contacts',
40                                         type='text',
41                                         placeholder='Grant user access by name')
42
43                 table.access-users-list
44                         tbody
45                                 tr
46                                         th
47                                         th Subversion Login
48                                         th Password set?
49                                         th
50
51                                 | {% for userinfo in svn_users %}
52                                 | {% set user=userinfo['db'] %}
53                                 | {% set is_self=current_user.user_id == user['_id'] %}
54                                 tr(data-user-id="{{ user['_id'] }}",
55                                         class="{% if is_self %}self{% endif %}")
56                                         td
57                                                 img.access-users-avatar(src="{{ user['email'] | gravatar(24) }}")
58                                                 span.access-users-name
59                                                         | {{ user['full_name'] }}
60                                                         | {% if current_user.objectid == user['_id'] %}
61                                                         small (You)
62                                                         | {% endif %}
63                                         td.copy-to-clipboard(data-clipboard-text="{{ userinfo['username'] }}") {{ userinfo['username'] }}
64                                         td.col-password
65                                                 | {% if userinfo['pw_set'] %}
66                                                 button.btn.btn-default(title="{% if is_self %}You have{% else %}The user has{% endif %} set a password; click to change it.") Change password
67                                                 | {% else %}
68                                                 i.pi-cancel
69                                                 button.btn.btn-warning(title="{% if is_self %}You have{% else %}The user has{% endif %} no password; click to set it.") Set password
70                                                 | {% endif %}
71                                         td.col-revoke
72                                                 | {%     if is_self %}
73                                                 button.user-remove(title="Revoke your own access")
74                                                         i.pi-trash
75                                                 | {%     else %}
76                                                 button.user-remove(title="Revoke access of this user")
77                                                         i.pi-trash
78                                                 | {%     endif %}
79
80                         | {% endfor %}
81
82         section
83                 h4 Dangerous operations
84                 p
85                         button.btn.btn-danger(onclick='deleteRepo()') Delete Subversion repository
86                 p Note that deleting an operation is permanent and <em>cannot be undone</em>. Use with caution.
87
88 | {% endblock svnman_container %}
89
90 | {% block footer_scripts %}
91 script.
92         var algolia_application_id = '{{config.ALGOLIA_USER}}'
93         var algolia_public_key = '{{config.ALGOLIA_PUBLIC_KEY}}';
94         var algolia_index_users = '{{config.ALGOLIA_INDEX_USERS}}';
95
96         var grant_access_url = '{{ url_for( "svnman.grant_access", project_url=project.url, repo_id=repo_id) }}';
97         var revoke_access_url = '{{ url_for( "svnman.revoke_access", project_url=project.url, repo_id=repo_id) }}';
98         var delete_repo_url = '{{ url_for( "svnman.delete_repo", project_url=project.url, repo_id=repo_id) }}';
99
100         $('#user-search').userSearch(algolia_application_id, algolia_public_key, algolia_index_users,
101                 function(event, hit, dataset) {
102                         var $existing = $('li.access-users-item[data-user-id="' + hit.objectID + '"]');
103                         if ($existing.length) {
104                                 $existing
105                                         .addClass('active')
106                                         .delay(1000)
107                                         .queue(function() {
108                                                 console.log('no');
109                                                 $existing.removeClass('active');
110                                                 $existing.dequeue();
111                                         });
112                                 toastr.info('User already has access');
113                         }
114                         else {
115                                 grantUser(hit.objectID);
116                         }
117                 }
118         );
119
120         $('.access-users-list .col-password button').click(function() {
121                 var user_id = $(this).closest('*[data-user-id]').data('user-id');
122                 setPassword(user_id);
123         })
124
125         $('.access-users-list .col-revoke button').click(function() {
126                 var user_id = $(this).closest('*[data-user-id]').data('user-id');
127                 revokeUser(user_id);
128         })
129
130         function setPassword(user_id) {
131                 var randomstring = Password.generate(16);
132
133                 password = prompt("Provide a new password. We have generated a random one for you. " +
134                         "It's up to you to send this password to the user in a secure way.", randomstring);
135                 if (!password) return;
136
137                 ajax(grant_access_url, {user_id: user_id, password: password});
138         }
139
140         function grantUser(user_id) {
141                 toastr.info('Granting access to user')
142                 ajax(grant_access_url, {user_id: user_id});
143         }
144
145         function revokeUser(user_id) {
146                 toastr.info('Revoking access from user')
147                 ajax(revoke_access_url, {user_id: user_id});
148         }
149
150         function deleteRepo() {
151                 if (!confirm('Are you sure you want to delete this repository? This CANNOT be undone! You WILL loose this data.'))
152                         return;
153                 toastr.info('Deleting repository')
154                 ajax(delete_repo_url);
155         }
156
157         function ajax(url, payload) {
158                 $.ajax({
159                         url: url,
160                         data: payload,
161                         method: 'POST',
162                 })
163                 .done(function() {
164                         window.location.reload();
165                 })
166                 .fail(function(err) {
167                         var err_elt = xhrErrorResponseElement(err, 'Error granting access: ');
168                         toastr.error(err_elt);
169                 });
170         }
171
172         var clipboard = null;
173         function createClipboard() {
174                 if (clipboard != null) {
175                         clipboard.destroy();
176                 }
177
178                 clipboard = new Clipboard('.copy-to-clipboard');
179
180                 clipboard.on('success', function(e) {
181                         $(e.trigger).flashOnce();
182                         toastr.success('Copied to clipboard');
183                 });
184         }
185         createClipboard();
186
187 | {% endblock %}