Fossil

Check-in [72de3100]
Login

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

Overview
Comment:Change the user list to a sortable table.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | user-config-revamp
Files: files | file ages | folders
SHA1: 72de3100c29070aaf2c237a0d1ddaf2f7e6f7543
User & Date: drh 2015-11-17 19:51:13
Context
2015-11-17
19:52
Revamp the user list setup page. Show the last change time and expiration date for each login. Make the user list sortable using javascript. check-in: 01b13199 user: drh tags: trunk
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
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
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
**
** 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







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






<
<
<



<

>
|
>

|


|
<






|
|
<
<
<

>
>

|

|

|

|
>
>

<
<
<

<
|
>
>

>


<
>
|
>
>
>
>

|





|
<







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

>







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
**
** 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 border=1 cellpadding=2 cellspacing=0 class='userTable'>
  @ <thead><tr><th>UID <th>Category <th>Capabilities <th>Info <th>Last Change</tr></thead>
  @ <tbody>
  db_prepare(&s,
     "SELECT uid, login, cap, date(mtime,'unixepoch')"
     "  FROM user"
     " WHERE login IN ('anonymous','nobody','developer','reader')"
     " ORDER BY login"

  );
  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);
    @ <tr>
    @ <td><a href='setup_uedit?id=%d(uid)'>%d(uid)</a>



    @ <td><a href='setup_uedit?id=%d(uid)'>%h(zLogin)</a>
    @ <td>%h(zCap)
    
    if( fossil_strcmp(zLogin,"anonymous")==0 ){
      @ <td>All logged-in users
    }else if( fossil_strcmp(zLogin,"developer")==0 ){
      @ <td>Users with '<b>v</b>' capability
    }else if( fossil_strcmp(zLogin,"nobody")==0 ){
      @ <td>All users without login
    }else if( fossil_strcmp(zLogin,"reader")==0 ){
      @ <td>Users with '<b>u</b>' capability
    }else{
      @ <td>
    }



    if( zDate && zDate[0] ){

      @ <td>%h(zDate)
    }else{
      @ <td>
    }
    @ </tr>
  }
  db_finalize(&s);

  @ </tbody></table>
  @ <div class='section'>Users</div>
  @ <table border=1 cellpadding=2 cellspacing=0 class='userTable' id='userlist'>
  @ <thead><tr>
  @ <th>ID<th>Login<th>Caps<th>Info<th>Chng<th>Expire</tr></thead>
  @ <tbody>
  db_prepare(&s,
     "SELECT uid, login, cap, info, date(mtime,'unixepoch'), lower(login) AS sortkey, "
     "       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 sortkey"

  );
  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 *zSortKey = db_column_text(&s,5);
    const char *zExp = db_column_text(&s,6);

    @ <tr>




    @ <td><a href='setup_uedit?id=%d(uid)'>%d(uid)</a>

    @ <td data-sortkey='%h(zSortKey)'><a href='setup_uedit?id=%d(uid)'>%h(zLogin)</a>
    @ <td>%h(zCap)


    @ <td>%h(zInfo)


    @ <td>%h(zDate?zDate:"")


    @ <td>%h(zExp?zExp:"")
    @ </tr>
  }


  @ </tbody></table>
  db_finalize(&s);
  output_table_sorting_javascript("userlist","nktxTT",2);
  style_footer();
}

/*
** WEBPAGE: setup_ulist_notes
**
** A documentation page showing notes about user configuration.  This information