Fossil

Check-in [d3fbf717]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved display of the user list on the setup menu.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | user-config-revamp
Files: files | file ages | folders
SHA1: d3fbf717386970ebb8c29630698f697745b0fa48
User & Date: drh 2015-11-17 17:12:49
Context
2015-11-17
19:51
Change the user list to a sortable table. Closed-Leaf check-in: 72de3100 user: drh tags: user-config-revamp
17:12
Improved display of the user list on the setup menu. check-in: d3fbf717 user: drh tags: user-config-revamp
14:29
Move the side-bar documentation for the user-list page onto a separate page accessible from the "Help" submen of the user-list page, for improved readability. check-in: 18df719e user: drh tags: user-config-revamp
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/setup.c.

143
144
145
146
147
148
149
















150
151
152
153
154
155



156
157
158

159
160
161
162
163

164
165
166
167
168

169
170
171

172
173
174
175
176
177

178
179
180
181
182
183
184
185



186
187
188
189
190
191
192
193
194
195
196

197
198
199
200
201
202








203









204
205
206
207







208
209
210
211
212





213

214
215
216

217
218
219
220
221
222
223
**
** Show a list of users.  Clicking on any user jumps to the edit
** screen for that user.  Requires Admin privileges.
*/
void setup_ulist(void){
  Stmt s;
  int prevLevel = 0;

















  login_check_credentials();
  if( !g.perm.Admin ){
    login_needed(0);
    return;
  }




  style_submenu_element("Add", "Add User", "setup_uedit");
  style_submenu_element("Help", "Help", "setup_ulist_notes");

  style_header("User List");
  @ <table class="usetupUserList">
  prevLevel = 0;
  db_prepare(&s,
     "SELECT uid, login, cap, info, 1 FROM user"

     " WHERE login IN ('anonymous','nobody','developer','reader') "
     " UNION ALL "
     "SELECT uid, login, cap, info, 2 FROM user"
     " WHERE login NOT IN ('anonymous','nobody','developer','reader') "
     "ORDER BY 5, 2 COLLATE nocase"

  );
  while( db_step(&s)==SQLITE_ROW ){
    int iLevel = db_column_int(&s, 4);

    const char *zCap = db_column_text(&s, 2);
    const char *zLogin = db_column_text(&s, 1);
    if( iLevel>prevLevel ){
      if( prevLevel>0 ){
        @ <tr><td colspan="3"><hr></td></tr>
      }

      if( iLevel==1 ){
        @ <tr>
        @   <th class="usetupListUser"
        @    style="text-align: right;padding-right: 20px;">Category</th>
        @   <th class="usetupListCap"
        @    style="text-align: center;padding-right: 15px;">Capabilities</th>
        @   <th class="usetupListCon"
        @    style="text-align: left;">Notes</th>



        @ </tr>
      }else{
        @ <tr>
        @   <th class="usetupListUser"
        @    style="text-align: right;padding-right: 20px;">User&nbsp;ID</th>
        @   <th class="usetupListCap"
        @    style="text-align: center;padding-right: 15px;">Capabilities</th>
        @   <th class="usetupListCon"
        @    style="text-align: left;">Contact&nbsp;Info</th>
        @ </tr>
      }

      prevLevel = iLevel;
    }
    @ <tr>
    @ <td class="usetupListUser"
    @     style="text-align: right;padding-right: 20px;white-space:nowrap;">
    if( g.perm.Admin && (zCap[0]!='s' || g.perm.Setup) ){








      @ <a href="setup_uedit?id=%d(db_column_int(&s,0))">









    }
    @ %h(zLogin)
    if( g.perm.Admin ){
      @ </a>







    }
    @ </td>
    @ <td class="usetupListCap" style="text-align: center;padding-right: 15px;">%s(zCap)</td>
    @ <td  class="usetupListCon"  style="text-align: left;">%h(db_column_text(&s,3))</td>
    @ </tr>





  }

  @ </table>
  style_footer();
  db_finalize(&s);

}

/*
** WEBPAGE: setup_ulist_notes
**
** A documentation page showing notes about user configuration.  This information
** used to be a side-bar on the user list page, but has been factored out for







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>



>

<
|

|
>
|
<
<
<
|
>


|
>

|
|
<
|
|
>
|
|
|
|
|
|
|
|
>
>
>
|
<
<
<
|
|
|
|
|
<
|
>
|
|
|
|
|
|
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>

<
<
<
>
>
>
>
>
>
>

<
<
<
<
>
>
>
>
>
|
>

<

>







143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184



185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208



209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240



241
242
243
244
245
246
247
248




249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
**
** Show a list of users.  Clicking on any user jumps to the edit
** screen for that user.  Requires Admin privileges.
*/
void setup_ulist(void){
  Stmt s;
  int prevLevel = 0;
  int nRow = 0;
  int iSort;
  static const char *azSortOptions[] = {
    "0", "Name",
    "1", "Uid",
    "2", "Capabilities",
    "3", "Last Change",
    "4", "Expiration"
  };
  const char *zOrderBy[] = {
    "login COLLATE nocase",
    "uid",
    "cap, login COLLATE nocase",
    "mtime DESC",
    "exp DESC, login COLLATE nocase"
  };

  login_check_credentials();
  if( !g.perm.Admin ){
    login_needed(0);
    return;
  }
  iSort = atoi(PD("sx", "0"));
  if( iSort<0 || iSort>ArraySize(zOrderBy) ) iSort = 0;
  

  style_submenu_element("Add", "Add User", "setup_uedit");
  style_submenu_element("Help", "Help", "setup_ulist_notes");
  style_submenu_multichoice("sx", ArraySize(azSortOptions)/2, azSortOptions, 0);
  style_header("User List");

  @ <table border=0 cellpadding=0 cellspacing=0>
  db_prepare(&s,
     "SELECT uid, login, cap, info, datetime(mtime,'unixepoch'), NULL AS exp "
     "  FROM user"
     " WHERE login IN ('anonymous','nobody','developer','reader')"



     " ORDER BY %s",
     zOrderBy[iSort]/*safe-for-%s*/
  );
  while( db_step(&s)==SQLITE_ROW ){
    int uid = db_column_int(&s, 0);
    const char *zLogin = db_column_text(&s, 1);
    const char *zCap = db_column_text(&s, 2);
    const char *zDate = db_column_text(&s, 4);
    if( nRow++ ){

      @ <tr><td colspan=3><hr></td></tr>
    }
    @ <tr><td valign='top'>Category:</td>
    @ <td>&nbsp;&nbsp;</td>
    @ <td><a href='setup_uedit?id=%d(uid)'>%h(zLogin)</a>
    if( fossil_strcmp(zLogin,"anonymous")==0 ){
      @ (All logged-in users)
    }else if( fossil_strcmp(zLogin,"developer")==0 ){
      @ (Users with '<b>v</b>' capability)
    }else if( fossil_strcmp(zLogin,"nobody")==0 ){
      @ (All users without login)
    }else if( fossil_strcmp(zLogin,"reader")==0 ){
      @ (Users with '<b>u</b>' capability)
    }
    @ </td></tr>



    @ <tr><td valign='top'>Capabilities:</td><td></td>
    @ <td>%h(zCap)</a></td></tr>
    if( zDate && zDate[0] ){
      @ <tr><td valign='top'>Last&nbsp;change:</td><td></td>
      @ <td>%h(zDate)</a></td></tr>

    }
  }
  db_finalize(&s);

  nRow = 0;
  db_prepare(&s,
     "SELECT uid, login, cap, info, datetime(mtime,'unixepoch'), "
     "       CASE WHEN info LIKE '%%expires 20%%'"
             "    THEN substr(info,instr(lower(info),'expires')+8,10)"
             "    END AS exp"
     "  FROM user"
     " WHERE login NOT IN ('anonymous','nobody','developer','reader')"
     " ORDER BY %s",
     zOrderBy[iSort]/*safe-for-%s*/
  );
  while( db_step(&s)==SQLITE_ROW ){
    int uid = db_column_int(&s, 0);
    const char *zLogin = db_column_text(&s, 1);
    const char *zCap = db_column_text(&s, 2);
    const char *zInfo = db_column_text(&s, 3);
    const char *zDate = db_column_text(&s, 4);
    const char *zExp = db_column_text(&s,5);
    if( (nRow++)==0 ){
      @ <tr><td colspan=3><div class='section'>Users</div></tr>
    }else{
      @ <tr><td colspan=3><hr></td></tr>
    }



    @ <tr><td valign='top'>Username:</td><td></td>
    @ <td><a href='setup_uedit?id=%d(uid)'>%h(zLogin) (uid: %d(uid))</a></td><tr>
    @ <tr><td valign='top'>Capabilities:</td><td></td>
    @ <td>%h(zCap)</a></td></tr>
    if( zExp && zExp[0] ){
      @ <tr><td valign='top'>Login&nbsp;expires:</td><td></td>
      @ <td>%h(zExp)</a></td></tr>
    }




    @ <tr><td valign='top'>Notes:</td><td></td>
    @ <td>%h(zInfo)</a></td></tr>
    if( zDate && zDate[0] ){
      @ <tr><td valign='top'>Last&nbsp;change:</td><td></td>
      @ <td>%h(zDate)</a></td></tr>
    }
  }
  @ </table>

  db_finalize(&s);
  style_footer();
}

/*
** WEBPAGE: setup_ulist_notes
**
** A documentation page showing notes about user configuration.  This information
** used to be a side-bar on the user list page, but has been factored out for