Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
lpmoon committed Dec 1, 2015
1 parent feff175 commit a8dd5f9
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 87 deletions.
13 changes: 13 additions & 0 deletions auth_server/authz/acl_mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type ACLMongoDialConfig struct {
PasswordFile string `yaml:"password_file,omitempty"`
}

//
var CH = make(chan int)

// Validate ensures the most common fields inside the mgo.DialInfo portion of
// an ACLMongoDialInfo are set correctly as well as other fields inside the
// ACLMongoConfig itself.
Expand Down Expand Up @@ -90,7 +93,9 @@ func NewACLMongoAuthorizer(c ACLMongoConfig) (Authorizer, error) {
}

go authorizer.continuouslyUpdateACLCache()
go authorizer.immediatelyUpdateACLCache()

//
return authorizer, nil
}

Expand Down Expand Up @@ -144,6 +149,14 @@ func (ma *aclMongoAuthorizer) continuouslyUpdateACLCache() {
}
}

func (ma *aclMongoAuthorizer) immediatelyUpdateACLCache() {
//
for {
<-CH
ma.updateACLCache()
}
}

func (ma *aclMongoAuthorizer) updateACLCache() error {
// Get ACL from MongoDB
var newACL ACL
Expand Down
2 changes: 1 addition & 1 deletion auth_server/server/manager/controllers/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ModifyController struct {
beego.Controller
}

func (c *ModifyController) Get() {
func (c *ModifyController) DoModify() {
// 参数获取
glog.Infoln("--modify request start--")
user := c.GetString("user")
Expand Down
14 changes: 11 additions & 3 deletions auth_server/server/manager/models/configholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ func (acm *AuthConfigManager) Update(user string, name *string, mtype int, ispul
// 删除 pull push
acm.lock.Lock()
defer acm.lock.Unlock() // 强行释放锁
var ret bool
if mtype == ADD {
return acm.add(user, name, ispull)
ret = acm.add(user, name, ispull)
} else if mtype == DEL {
return acm.del(user, name, ispull)
ret = acm.del(user, name, ispull)
} else {
// do thing
}

return true
acm.UpdateCache()
return ret
}

func (acm *AuthConfigManager) add(user string, name *string, ispull bool) bool {
Expand Down Expand Up @@ -168,9 +170,15 @@ func (acm *AuthConfigManager) del(user string, name *string, ispull bool) bool {
}

collection.Update(findRule, bson.M{"$set": bson.M{"actions": []string{toremain}}})

return true
}

func (acm *AuthConfigManager) UpdateCache() {
// 更新
authz.CH <- 1
}

func (acm *AuthConfigManager) QueryDetail(user string) [][]string {
// detail 格式如下所示
/* [
Expand Down
2 changes: 1 addition & 1 deletion auth_server/server/manager/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
func init() {
beego.Router("/", &controllers.ListController{})
beego.Router("/query", &controllers.DetailController{})
beego.Router("/modify", &controllers.ModifyController{})
beego.Router("/modify", &controllers.ModifyController{}, "get,post:DoModify")
}
134 changes: 134 additions & 0 deletions auth_server/server/manager/static/js/detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
String.prototype.startWith = function(str) {
if (str == null || str== "" || this.length == 0 || str.length > this.length) {
return false;
}

if (this.substr(0, str.length) == str) {
return true;
} else {
return false;
}
}

$(document).ready(function() {
// 修改按钮事件绑定
$(".modifybtn").bind({
click: function() {
var btn_id = $(this).attr("id");
var lio = btn_id.lastIndexOf("_");
var idx = btn_id.substring(lio + 1);
if ($(this).hasClass("modifybtn")) {
// 隐藏的label和button显示

// 1) pull text
var pull_text_id = "pull_text_" + idx;
if ($("#" + pull_text_id).hasClass("hidden")) {
$("#" + pull_text_id).removeClass("hidden");
}
// 2) pull btn
var pull_btn_id = "pull_btn_" + idx;
if ($("#" + pull_btn_id).hasClass("hidden")) {
$("#" + pull_btn_id).removeClass("hidden");
}
// 3) push text
var push_text_id = "push_text_" + idx;
if ($("#" + push_text_id).hasClass("hidden")) {
$("#" + push_text_id).removeClass("hidden");
}
// 4) push btn
var push_btn_id = "push_btn_" + idx;
if ($("#" + push_btn_id).hasClass("hidden")) {
$("#" + push_btn_id).removeClass("hidden");
}

// 不该显示的label和button隐藏

$(this).removeClass("modifybtn");
$(this).addClass("cancelbtn");

// 修改文本
$(this).html("取消");

return
} else if ($(this).hasClass("cancelbtn")) {
// 根据pull 和 push btn是btn-success还是btn-danger, 判断是要隐藏还是显示按钮
var pull_btn_id = "pull_btn_" + idx;
var push_btn_id = "push_btn_" + idx;

var pull_btn = $("#" + pull_btn_id);
if (pull_btn.hasClass("btn-success")) {
// 隐藏btn
pull_btn.addClass("hidden");
} else if (pull_btn.hasClass("btn-danger")) {
// 隐藏btn和隐藏label
pull_btn.addClass("hidden");
$("#" + "pull_text_" + idx).addClass("hidden");
} else {

}

var push_btn = $("#" + push_btn_id);
if (push_btn.hasClass("btn-success")) {
// 隐藏btn
push_btn.addClass("hidden");
} else if (push_btn.hasClass("btn-danger")) {
// 隐藏btn和隐藏label
push_btn.addClass("hidden");
$("#" + "push_text_" + idx).addClass("hidden");
} else {

}
$(this).removeClass("cancelbtn");
$(this).addClass("modifybtn");
$(this).html("修改");
}
}
});

$(".control").bind({
click: function() {
var btn_id = $(this).attr("id");
var lio = btn_id.lastIndexOf("_");
var idx = btn_id.substring(lio + 1);
// 获取镜像名称
var name = $("#img_" + idx).html();
if (name == "*") {
name = "";
}
// 获取用户名
var user = $("#user").html();
// 获取删除还是添加

var mtype;
if ($(this).hasClass("btn-success")) {
mtype = 1;
} else if ($(this).hasClass("btn-danger")) {
mtype = 2;
}

var ispull = btn_id.startWith("pull");
$.ajax({
method: "POST",
url: "/modify",
data: {"user": user, "name": name, "mtype": mtype, "ispull": ispull}
}).done(function(data){
// 处理
if (mtype == 1) { // 添加
// 添加按钮变成删除按钮
$("#" + btn_id).removeClass("btn-success");
$("#" + btn_id).addClass("btn-danger");
$("#" + btn_id).html('<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete');
} else { // 删除
// 删除按钮变成添加按钮
$("#" + btn_id).removeClass("btn-danger");
$("#" + btn_id).addClass("btn-success");
$("#" + btn_id).html('<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add');
}
}).fail(function(data){
// 处理
});

}
});

});
12 changes: 12 additions & 0 deletions auth_server/server/manager/static/js/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$(document).ready(function(){
$(".query").bind({
click: function(){
var query_id = $(this).attr("id");
var lio = query_id.lastIndexOf("_");
var idx = query_id.substring(lio + 1);
var user = $("#value_" + idx).html();
location.href = "query?user=" + user;
}
});
});

94 changes: 20 additions & 74 deletions auth_server/server/manager/views/detail.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,23 @@
<link rel="stylesheet" href="/static/css/custom.css" type="text/css" />
<script type="text/javascript" src="/static/js/jquery-2.1.4.min.js" ></script>
<script type="text/javascript" src="/static/js/bootstrap.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
// 修改按钮事件绑定
$(".modifybtn").bind({
click: function() {
var btn_id = $(this).attr("id");
var lio = btn_id.lastIndexOf("_");
var idx = btn_id.substring(lio + 1);
// 隐藏的label和button显示
// 1) pull text
var pull_text_id = "pull_text_" + idx;
if ($("#" + pull_text_id).hasClass("hidden")) {
$("#" + pull_text_id).removeClass("hidden");
}
// 2) pull btn
var pull_btn_id = "pull_btn_" + idx;
if ($("#" + pull_btn_id).hasClass("hidden")) {
$("#" + pull_btn_id).removeClass("hidden");
}
// 3) push text
var push_text_id = "push_text_" + idx;
if ($("#" + push_text_id).hasClass("hidden")) {
$("#" + push_text_id).removeClass("hidden");
}
// 4) push btn
var push_btn_id = "push_btn_" + idx;
if ($("#" + push_btn_id).hasClass("hidden")) {
$("#" + push_btn_id).removeClass("hidden");
}
alert(idx);
// 不该显示的label和button隐藏
$(this).removeClass(modifybtn)
$(this).addClass(cancelbtn)
}
});
$(".cancelbtn").bind({
click: function() {
var btn_id = $(this).attr("id");
var lio = btn_id.lastIndexOf("_");
var idx = btn_id.substring(lio + 1);
// 根据pull 和 push btn是btn-success还是btn-danger, 判断是要隐藏还是显示按钮
}
});
});
<script type="text/javascript" src="/static/js/detail.js"></script>
</script>
</head>

<body>

<div class="panel panel-default">
<div class="panel panel-primary">
<!-- Default panel contents -->
<div class="panel-heading">{{.user}}</div>
<div class="panel-body">
<pre>该面板中列出了当前用户对各个镜像的权限.
1. 如果镜像名称为*, 表示该用户对所有镜像拥有某个权限
2. 如果镜像名不为*, 表示该用户对特定的某个镜像拥有相应的权限
3. 拉取权限为PULL, 推送权限为PUSH
4. 用户可以点击操作按钮, 对该用户的权限做操作
</pre>
<div class="panel-heading" id="user">{{.user}}</div>
<div class="panel-body lead">
该面板中列出了当前用户对各个镜像的权限.
<ol>
<li>如果镜像名称为*, 表示该用户对所有镜像拥有某个权限</li>
<li>如果镜像名不为*, 表示该用户对特定的某个镜像拥有相应的权限</li>
<li>拉取权限为PULL, 推送权限为PUSH</li>
<li>用户可以点击操作按钮, 对该用户的权限做操作</li>
</ol>
</div>

<!-- Table -->
Expand All @@ -92,50 +39,50 @@
{{range $idx, $value := $.detail}}
<tr>
<td>{{$idx}}</td>
<td>{{index $value 0}}</td>
<td id="img_{{$idx}}">{{index $value 0}}</td>
<td>
{{if eq "3" (index $value 1)}}
<!-- 显示 -->
<span class="label label-primary btn-xs" id="pull_text_{{$idx}}">&nbspPull&nbsp</span>
<button type="button" class="btn btn-danger btn-xs hidden" id="pull_btn_{{$idx}}">
<button type="button" class="btn btn-danger btn-xs hidden control" id="pull_btn_{{$idx}}">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
</button>
<!-- 显示 -->
<span class="label label-success btn-xs" id="push_text_{{$idx}}">&nbspPush&nbsp</span>
<button type="button" class="btn btn-danger btn-xs hidden" id="push_btn_{{$idx}}">
<button type="button" class="btn btn-danger btn-xs hidden control" id="push_btn_{{$idx}}">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
</button>
{{else if eq "2" (index $value 1)}}
<!-- 隐藏 -->
<span class="label label-primary btn-xs hidden" id="pull_text_{{$idx}}">&nbspPull&nbsp</span>
<button type="button" class="btn btn-success btn-xs hidden" id="pull_btn_{{$idx}}">
<button type="button" class="btn btn-success btn-xs hidden control" id="pull_btn_{{$idx}}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add
</button>
<!-- 显示-->
<span class="label label-success btn-xs" id="push_text_{{$idx}}">&nbspPush&nbsp</span>
<button type="button" class="btn btn-danger btn-xs hidden" id="push_btn_{{$idx}}">
<button type="button" class="btn btn-danger btn-xs hidden control" id="push_btn_{{$idx}}">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
</button>
{{else if eq "1" (index $value 1)}}
<!-- 显示-->
<span class="label label-primary btn-xs" id="pull_text_{{$idx}}">&nbspPull&nbsp</span>
<button type="button" class="btn btn-danger btn-xs hidden" id="pull_btn_{{$idx}}">
<button type="button" class="btn btn-danger btn-xs hidden control" id="pull_btn_{{$idx}}">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
</button>
<!-- 隐藏-->
<span class="label label-success btn-xs hidden" id="push_text_{{$idx}}">&nbspPush&nbsp</span>
<button type="button" class="btn btn-success btn-xs hidden" id="push_btn_{{$idx}}">
<button type="button" class="btn btn-success btn-xs hidden control" id="push_btn_{{$idx}}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add
</button>
{{else}}
<!-- 隐藏-->
<span class="label label-primary btn-xs hidden" id="pull_text_{{$idx}}">&nbspPull&nbsp</span>
<button type="button" class="btn btn-success btn-xs hidden" id="pull_btn_{{$idx}}">
<button type="button" class="btn btn-success btn-xs hidden control" id="pull_btn_{{$idx}}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add
</button>
<!-- 隐藏-->
<span class="label label-success btn-xs hidden" id="push_text_{{$idx}}">&nbspPush&nbsp</span>
<button type="button" class="btn btn-success btn-xs hidden" id="push_btn_{{$idx}}">
<button type="button" class="btn btn-success btn-xs hidden control" id="push_btn_{{$idx}}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add
</button>
{{end}}
Expand All @@ -155,6 +102,5 @@
{{end}}
</table>
</div>

</body>
</html>
Loading

0 comments on commit a8dd5f9

Please sign in to comment.