Continued work on documentation
This commit is contained in:
parent
e59b7e8b7b
commit
9e756e28e4
4 changed files with 106 additions and 39 deletions
|
@ -80,10 +80,12 @@ registerAccount=anonymous
|
||||||
;registerAccount=nobody
|
;registerAccount=nobody
|
||||||
|
|
||||||
listPosts=anonymous
|
listPosts=anonymous
|
||||||
|
listPosts.safe=anonymous
|
||||||
listPosts.sketchy=registered
|
listPosts.sketchy=registered
|
||||||
listPosts.unsafe=registered
|
listPosts.unsafe=registered
|
||||||
listPosts.hidden=moderator
|
listPosts.hidden=moderator
|
||||||
viewPost=anonymous
|
viewPost=anonymous
|
||||||
|
viewPost.safe=anonymous
|
||||||
viewPost.sketchy=registered
|
viewPost.sketchy=registered
|
||||||
viewPost.unsafe=registered
|
viewPost.unsafe=registered
|
||||||
viewPost.hidden=moderator
|
viewPost.hidden=moderator
|
||||||
|
@ -118,8 +120,8 @@ flagPost=registered
|
||||||
|
|
||||||
listUsers=registered
|
listUsers=registered
|
||||||
viewUser=registered
|
viewUser=registered
|
||||||
viewUserEmail.all=admin
|
|
||||||
viewUserEmail.own=registered
|
viewUserEmail.own=registered
|
||||||
|
viewUserEmail.all=admin
|
||||||
editUserPassword.own=registered
|
editUserPassword.own=registered
|
||||||
editUserPassword.all=admin
|
editUserPassword.all=admin
|
||||||
editUserEmail.own=registered
|
editUserEmail.own=registered
|
||||||
|
@ -127,8 +129,8 @@ editUserEmail.all=admin
|
||||||
editUserEmailNoConfirm=admin
|
editUserEmailNoConfirm=admin
|
||||||
editUserAccessRank=admin
|
editUserAccessRank=admin
|
||||||
editUserName=moderator
|
editUserName=moderator
|
||||||
editUserSettings.all=nobody
|
|
||||||
editUserSettings.own=registered
|
editUserSettings.own=registered
|
||||||
|
editUserSettings.all=nobody
|
||||||
acceptUserRegistration=moderator
|
acceptUserRegistration=moderator
|
||||||
banUser.own=nobody
|
banUser.own=nobody
|
||||||
banUser.all=admin
|
banUser.all=admin
|
||||||
|
|
|
@ -1,5 +1,18 @@
|
||||||
pre {
|
#content pre {
|
||||||
background: ghostwhite;
|
background: ghostwhite;
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
border-left: 0.2em solid silver;
|
border-left: 0.2em solid silver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#content table {
|
||||||
|
border-spacing: 0;
|
||||||
|
border-collapse: collapsue;
|
||||||
|
}
|
||||||
|
#content th,
|
||||||
|
#content td {
|
||||||
|
text-align: left;
|
||||||
|
padding: 0.2em 0.5em;
|
||||||
|
}
|
||||||
|
#content tbody:nth-child(2n) {
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
|
|
@ -12,19 +12,18 @@ class Access
|
||||||
if (strpos($key, '.') === false)
|
if (strpos($key, '.') === false)
|
||||||
$key .= '.';
|
$key .= '.';
|
||||||
list ($privilegeName, $subPrivilegeName) = explode('.', $key);
|
list ($privilegeName, $subPrivilegeName) = explode('.', $key);
|
||||||
|
$minAccessRank = new AccessRank(TextHelper::resolveConstant($minAccessRankName, 'AccessRank'));
|
||||||
$key = rtrim($privilegeName . '.' . $subPrivilegeName, '.');
|
|
||||||
|
|
||||||
if (!in_array($privilegeName, Privilege::getAllConstants()))
|
if (!in_array($privilegeName, Privilege::getAllConstants()))
|
||||||
throw new Exception('Invalid privilege name in config: ' . $privilegeName);
|
throw new Exception('Invalid privilege name in config: ' . $privilegeName);
|
||||||
|
|
||||||
$minAccessRank = TextHelper::resolveConstant($minAccessRankName, 'AccessRank');
|
|
||||||
self::$privileges[$key] = $minAccessRank;
|
|
||||||
|
|
||||||
if (!isset(self::$privileges[$privilegeName]))
|
if (!isset(self::$privileges[$privilegeName]))
|
||||||
{
|
{
|
||||||
self::$privileges[$privilegeName] = $minAccessRank;
|
self::$privileges[$privilegeName] = [];
|
||||||
|
self::$privileges[$privilegeName][null] = $minAccessRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self::$privileges[$privilegeName][$subPrivilegeName] = $minAccessRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo: move to scripts etc.
|
//todo: move to scripts etc.
|
||||||
|
@ -40,18 +39,15 @@ class Access
|
||||||
if ($user === null)
|
if ($user === null)
|
||||||
$user = Auth::getCurrentUser();
|
$user = Auth::getCurrentUser();
|
||||||
|
|
||||||
$minAccessRank = AccessRank::Nobody;
|
$minAccessRank = new AccessRank(AccessRank::Nobody);
|
||||||
|
|
||||||
$key = $privilege->toString();
|
if (isset(self::$privileges[$privilege->primary][$privilege->secondary]))
|
||||||
$privilege->secondary = null;
|
$minAccessRank = self::$privileges[$privilege->primary][$privilege->secondary];
|
||||||
$key2 = $privilege->toString();
|
|
||||||
|
|
||||||
if (isset(self::$privileges[$key]))
|
elseif (isset(self::$privileges[$privilege->primary][null]))
|
||||||
$minAccessRank = self::$privileges[$key];
|
$minAccessRank = self::$privileges[$privilege->primary][null];
|
||||||
elseif (isset(self::$privileges[$key2]))
|
|
||||||
$minAccessRank = self::$privileges[$key2];
|
|
||||||
|
|
||||||
return $user->getAccessRank()->toInteger() >= $minAccessRank;
|
return $user->getAccessRank()->toInteger() >= $minAccessRank->toInteger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkEmailConfirmation($user = null)
|
public static function checkEmailConfirmation($user = null)
|
||||||
|
@ -109,6 +105,13 @@ class Access
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAllDefinedSubPrivileges($privilege)
|
||||||
|
{
|
||||||
|
if (!isset(self::$privileges[$privilege]))
|
||||||
|
return null;
|
||||||
|
return self::$privileges[$privilege];
|
||||||
|
}
|
||||||
|
|
||||||
public static function disablePrivilegeChecking()
|
public static function disablePrivilegeChecking()
|
||||||
{
|
{
|
||||||
self::$checkPrivileges = false;
|
self::$checkPrivileges = false;
|
||||||
|
|
|
@ -56,8 +56,8 @@ encoding.</p>
|
||||||
|
|
||||||
<h3>Handling errors</h3>
|
<h3>Handling errors</h3>
|
||||||
|
|
||||||
<p>When errors occur all errors are logged to <code>message</code> field and changes done with request is rolled
|
<p>Normally all jobs return <code>200 OK</code>. However, when an error occurs, its reason is logged to
|
||||||
back.</p>
|
<code>message</code> field, changes are rolled back and API returns <code>400 Bad Request</code>.</p>
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
|
@ -69,32 +69,51 @@ back.</p>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Privilege</th>
|
<th>Privilege</th>
|
||||||
|
<th>Sub privilege</th>
|
||||||
<th>Minimum access rank</th>
|
<th>Minimum access rank</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
<?php foreach (Privilege::getAllConstants() as $privilege): ?>
|
||||||
|
<?php $i = 0 ?>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach (Core::getConfig()->privileges as $privilege => $minAccessRank): ?>
|
<?php foreach (Access::getAllDefinedSubPrivileges($privilege) as $subPrivilege => $minAccessRank): ?>
|
||||||
|
<?php if ($i == 0): ?>
|
||||||
|
<tr id="privilege-<?= $privilege ?>">
|
||||||
|
<?php else: ?>
|
||||||
<tr>
|
<tr>
|
||||||
|
<?php endif ?>
|
||||||
<td><?= $privilege ?></td>
|
<td><?= $privilege ?></td>
|
||||||
<td><?= $minAccessRank ?></td>
|
<td><?= $subPrivilege ?: '—' ?></td>
|
||||||
|
<td><?= $minAccessRank->toDisplayString() ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<?php $i ++ ?>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
<?php endforeach ?>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
<h2>Full list of available jobs</h2>
|
<h2>Full list of available jobs</h2>
|
||||||
|
|
||||||
|
<p>Some jobs execute other jobs. Such relations are listed under „chained jobs” sections. This means you
|
||||||
|
shouldn't be too surprised if <code>add-user</code> doesn't require any arguments – they're enforced in its
|
||||||
|
chained jobs.</p>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$jobClassNames = Api::getAllJobClassNames();
|
$jobClassNames = Api::getAllJobClassNames();
|
||||||
natcasesort($jobClassNames);
|
natcasesort($jobClassNames);
|
||||||
|
$jobClassNames = array_values($jobClassNames);
|
||||||
|
|
||||||
foreach ($jobClassNames as $className)
|
foreach ($jobClassNames as $i => $className)
|
||||||
{
|
{
|
||||||
$job = new $className;
|
$job = new $className;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<?php if ($i != 0): ?>
|
||||||
|
<hr/>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
<h3 id="job-<?= $job->getName() ?>">
|
<h3 id="job-<?= $job->getName() ?>">
|
||||||
<a href="#job-<?= $job->getName() ?>"><?= $job->getName() ?></a>
|
<a href="#job-<?= $job->getName() ?>"><?= $job->getName() ?></a>
|
||||||
</h3>
|
</h3>
|
||||||
|
@ -125,17 +144,47 @@ foreach ($jobClassNames as $className)
|
||||||
};
|
};
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<p>Required arguments: <?= $showArgs($job->getRequiredArguments()) ?></p>
|
<p>
|
||||||
<p>Requires e-mail confirmation: <?= $job->isConfirmedEmailRequired() ? 'yes' : 'no' ?></p>
|
Required arguments:
|
||||||
<p>Requires authentication: <?= $job->isAuthenticationRequired() ? 'yes' : 'no' ?></p>
|
<?php if ($job->getRequiredArguments()): ?>
|
||||||
|
<?= $showArgs($job->getRequiredArguments()) ?>
|
||||||
|
<?php else: ?>
|
||||||
|
none
|
||||||
|
<?php endif ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Required privilege:
|
||||||
|
<?php if ($job->getRequiredMainPrivilege()): ?>
|
||||||
|
<a href="#privilege-<?= $job->getRequiredMainPrivilege() ?>">
|
||||||
|
<?= $job->getRequiredMainPrivilege() ?>
|
||||||
|
</a>
|
||||||
|
<?php else: ?>
|
||||||
|
none
|
||||||
|
<?php endif ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Requires e-mail confirmation:
|
||||||
|
<?= $job->isConfirmedEmailRequired() ? 'yes' : 'no' ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Requires authentication:
|
||||||
|
<?= $job->isAuthenticationRequired() ? 'yes' : 'no' ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
<?php if (!empty($job->getSubJobs())): ?>
|
<?php if (!empty($job->getSubJobs())): ?>
|
||||||
<p>Sub jobs: <?= implode(', ', array_map(function($job)
|
<p>
|
||||||
|
Chained jobs:
|
||||||
|
<?php
|
||||||
|
echo implode(', ', array_map(function($job)
|
||||||
{
|
{
|
||||||
return '<a href="#job-' . $job->getName() . '">' . $job->getName() . '</a>';
|
return '<a href="#job-' . $job->getName() . '">' . $job->getName() . '</a>';
|
||||||
}, $job->getSubJobs())); ?></p>
|
}, $job->getSubJobs()));
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<hr/>
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue