Skip to content

Commit

Permalink
[to #8] multiset check permission & support more params
Browse files Browse the repository at this point in the history
  • Loading branch information
newnius committed Nov 23, 2022
1 parent d4a67a0 commit bff3545
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ function print_response($res)
foreach ($urls as $url) {
$link = new CRObject();
$link->set('url', $url);
$link->set('remark', cr_get_POST('remark'));
$link->set('valid_from', cr_get_POST('valid_from'));
$link->set('valid_to', cr_get_POST('valid_to'));
$links[] = $link;
}
$res = link_multiadd($links);
Expand Down
30 changes: 29 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,37 @@
<label for="form-multiset-text" class="sr-only">Token</label>
<textarea type="text" id="form-multiset-text"
class="form-control"
rows="10"
rows="10" autocomplete="off"
placeholder="一行一个链接,不超过50个" required></textarea>
</div>
<label>备注(可选)</label>
<div class="form-group form-group-lg">
<label for="form-multiset-remark" class="sr-only">Custom Token</label>
<input type="text" id="form-multiset-remark" class="form-control"
placeholder="短链接备注" autocomplete="off"/>
</div>
<label>有效期自(可选)</label>
<div class="form-group form-group-lg">
<div class='input-group date date-picker'>
<label for="form-multiset-valid-from" class="sr-only">Valid From</label>
<input type='text' class="form-control" placeholder="留空表示不限制"
id="form-multiset-valid-from" autocomplete="off"/>
<div class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</div>
</div>
</div>
<label>有效期至(可选)</label>
<div class="form-group form-group-lg">
<div class='input-group date date-picker'>
<label for="form-multiset-valid-to" class="sr-only">Valid To</label>
<input type='text' class="form-control" placeholder="留空表示不限制"
id="form-multiset-valid-to" autocomplete="off"/>
<div class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</div>
</div>
</div>
<div><span class="text-infp">* 仅对部分用户开放</span></div>
<button id="form-multiset-submit" type="submit" class="btn btn-lg btn-default">批量生成</button>
</form>
Expand Down
1 change: 1 addition & 0 deletions init.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function init_accessMap()

/* link */
'link.set' => array('root', 'admin', 'developer', 'normal', 'visitor'),
'link.multiset' => array('root', 'admin', 'developer', 'normal'),
'link.get' => array('root', 'admin', 'developer', 'normal', 'visitor'),
'link.update' => array('root', 'admin', 'developer', 'normal'),
'link.remove' => array('root', 'admin', 'developer', 'normal'),
Expand Down
11 changes: 11 additions & 0 deletions link.logic.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function link_add(CRObject $link)
}

function link_multiadd(/* array(CRObject) */ $links) {
if (!AccessController::hasAccess(Session::get('role', 'visitor'), 'link.multiset')) {
$res['errno'] = Code::NO_PRIVILEGE;
return $res;
}
$res['errno'] = Code::SUCCESS;
$url_token_pairs = array();
foreach($links as $link) {
Expand All @@ -68,6 +72,13 @@ function link_multiadd(/* array(CRObject) */ $links) {
$url_token_pairs[] = array($link->get('url', ''), $r['token']);
}
$res['url_token_pairs'] = $url_token_pairs;

$log = new CRObject();
$log->set('scope', Session::get('uid'));
$log->set('tag', 'link.multiadd');
$content = array('url_token_pairs' => $url_token_pairs, 'response' => $res['errno']);
$log->set('content', json_encode($content));
CRLogger::log($log);
return $res;
}

Expand Down
14 changes: 13 additions & 1 deletion static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,25 @@ $(function () {
$("#modal-msg").modal('show');
return false;
}
var remark = $('#form-multiset-remark').val();
var valid_from = $('#form-multiset-valid-from').val();
if (valid_from.length !== 0) {
valid_from = moment(valid_from).unix();
}
var valid_to = $('#form-multiset-valid-to').val();
if (valid_to.length !== 0) {
valid_to = moment(valid_to).unix();
}
$("#form-multiset-submit").attr("disabled", "disabled");

var ajax = $.ajax({
url: window.config.BASE_URL + "/service?action=multiset",
type: 'POST',
data: {
urls: urls
urls: urls,
remark: remark,
valid_from: valid_from,
valid_to: valid_to
}
});
ajax.done(function (res) {
Expand Down

0 comments on commit bff3545

Please sign in to comment.