golint refactor for model

This commit is contained in:
yinw 2016-02-26 10:15:01 +08:00
parent d5442b3298
commit 4a0b069994
26 changed files with 256 additions and 256 deletions

View File

@ -52,7 +52,7 @@ func (b *BaseAPI) ValidateUser() int {
b.CustomAbort(http.StatusUnauthorized, "") b.CustomAbort(http.StatusUnauthorized, "")
} }
userID := sessionUserID.(int) userID := sessionUserID.(int)
u, err := dao.GetUser(models.User{UserId: userID}) u, err := dao.GetUser(models.User{UserID: userID})
if err != nil { if err != nil {
beego.Error("Error occurred in GetUser:", err) beego.Error("Error occurred in GetUser:", err)
b.CustomAbort(http.StatusInternalServerError, "Internal error.") b.CustomAbort(http.StatusInternalServerError, "Internal error.")

View File

@ -72,7 +72,7 @@ func (pma *ProjectMemberAPI) Prepare() {
} }
func (pma *ProjectMemberAPI) Get() { func (pma *ProjectMemberAPI) Get() {
pid := pma.project.ProjectId pid := pma.project.ProjectID
if !CheckProjectPermission(pma.currentUserID, pid) { if !CheckProjectPermission(pma.currentUserID, pid) {
beego.Warning("Current user, user id :", pma.currentUserID, "does not have permission for project, id:", pid) beego.Warning("Current user, user id :", pma.currentUserID, "does not have permission for project, id:", pid)
pma.RenderError(http.StatusForbidden, "") pma.RenderError(http.StatusForbidden, "")
@ -89,14 +89,14 @@ func (pma *ProjectMemberAPI) Get() {
} }
pma.Data["json"] = userList pma.Data["json"] = userList
} else { //return detail of a member } else { //return detail of a member
roleList, err := dao.GetUserProjectRoles(models.User{UserId: pma.memberID}, pid) roleList, err := dao.GetUserProjectRoles(models.User{UserID: pma.memberID}, pid)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUserProjectRoles:", err) beego.Error("Error occurred in GetUserProjectRoles:", err)
pma.CustomAbort(http.StatusInternalServerError, "Internal error.") pma.CustomAbort(http.StatusInternalServerError, "Internal error.")
} }
//return empty role list to indicate if a user is not a member //return empty role list to indicate if a user is not a member
result := make(map[string]interface{}) result := make(map[string]interface{})
user, err := dao.GetUser(models.User{UserId: pma.memberID}) user, err := dao.GetUser(models.User{UserID: pma.memberID})
if err != nil { if err != nil {
beego.Error("Error occurred in GetUser:", err) beego.Error("Error occurred in GetUser:", err)
pma.CustomAbort(http.StatusInternalServerError, "Internal error.") pma.CustomAbort(http.StatusInternalServerError, "Internal error.")
@ -110,8 +110,8 @@ func (pma *ProjectMemberAPI) Get() {
} }
func (pma *ProjectMemberAPI) Post() { func (pma *ProjectMemberAPI) Post() {
pid := pma.project.ProjectId pid := pma.project.ProjectID
userQuery := models.User{UserId: pma.currentUserID, RoleId: models.PROJECTADMIN} userQuery := models.User{UserID: pma.currentUserID, RoleID: models.PROJECTADMIN}
rolelist, err := dao.GetUserProjectRoles(userQuery, pid) rolelist, err := dao.GetUserProjectRoles(userQuery, pid)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUserProjectRoles:", err) beego.Error("Error occurred in GetUserProjectRoles:", err)
@ -131,7 +131,7 @@ func (pma *ProjectMemberAPI) Post() {
pma.RenderError(http.StatusNotFound, "User does not exist") pma.RenderError(http.StatusNotFound, "User does not exist")
return return
} }
rolelist, err = dao.GetUserProjectRoles(models.User{UserId: userID}, pid) rolelist, err = dao.GetUserProjectRoles(models.User{UserID: userID}, pid)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUserProjectRoles:", err) beego.Error("Error occurred in GetUserProjectRoles:", err)
pma.CustomAbort(http.StatusInternalServerError, "Internal error.") pma.CustomAbort(http.StatusInternalServerError, "Internal error.")
@ -153,9 +153,9 @@ func (pma *ProjectMemberAPI) Post() {
} }
func (pma *ProjectMemberAPI) Put() { func (pma *ProjectMemberAPI) Put() {
pid := pma.project.ProjectId pid := pma.project.ProjectID
mid := pma.memberID mid := pma.memberID
userQuery := models.User{UserId: pma.currentUserID, RoleId: models.PROJECTADMIN} userQuery := models.User{UserID: pma.currentUserID, RoleID: models.PROJECTADMIN}
rolelist, err := dao.GetUserProjectRoles(userQuery, pid) rolelist, err := dao.GetUserProjectRoles(userQuery, pid)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUserProjectRoles:", err) beego.Error("Error occurred in GetUserProjectRoles:", err)
@ -168,7 +168,7 @@ func (pma *ProjectMemberAPI) Put() {
} }
var req memberReq var req memberReq
pma.DecodeJSONReq(&req) pma.DecodeJSONReq(&req)
roleList, err := dao.GetUserProjectRoles(models.User{UserId: mid}, pid) roleList, err := dao.GetUserProjectRoles(models.User{UserID: mid}, pid)
if len(roleList) == 0 { if len(roleList) == 0 {
beego.Warning("User is not in project, user id:", mid, ", project id:", pid) beego.Warning("User is not in project, user id:", mid, ", project id:", pid)
pma.RenderError(http.StatusNotFound, "user not exist in project") pma.RenderError(http.StatusNotFound, "user not exist in project")
@ -194,9 +194,9 @@ func (pma *ProjectMemberAPI) Put() {
} }
func (pma *ProjectMemberAPI) Delete() { func (pma *ProjectMemberAPI) Delete() {
pid := pma.project.ProjectId pid := pma.project.ProjectID
mid := pma.memberID mid := pma.memberID
userQuery := models.User{UserId: pma.currentUserID, RoleId: models.PROJECTADMIN} userQuery := models.User{UserID: pma.currentUserID, RoleID: models.PROJECTADMIN}
rolelist, err := dao.GetUserProjectRoles(userQuery, pid) rolelist, err := dao.GetUserProjectRoles(userQuery, pid)
if len(rolelist) == 0 { if len(rolelist) == 0 {
beego.Warning("Current user, id:", pma.currentUserID, ", does not have project admin role for project, id:", pid) beego.Warning("Current user, id:", pma.currentUserID, ", does not have project admin role for project, id:", pid)

View File

@ -84,7 +84,7 @@ func (p *ProjectAPI) Post() {
p.RenderError(http.StatusConflict, "") p.RenderError(http.StatusConflict, "")
return return
} }
project := models.Project{OwnerId: p.userID, Name: projectName, CreationTime: time.Now(), Public: public} project := models.Project{OwnerID: p.userID, Name: projectName, CreationTime: time.Now(), Public: public}
err = dao.AddProject(project) err = dao.AddProject(project)
if err != nil { if err != nil {
beego.Error("Failed to add project, error: %v", err) beego.Error("Failed to add project, error: %v", err)
@ -107,7 +107,7 @@ func (p *ProjectAPI) Head() {
} }
func (p *ProjectAPI) Get() { func (p *ProjectAPI) Get() {
queryProject := models.Project{UserId: p.userID} queryProject := models.Project{UserID: p.userID}
projectName := p.GetString("project_name") projectName := p.GetString("project_name")
if len(projectName) > 0 { if len(projectName) > 0 {
queryProject.Name = "%" + projectName + "%" queryProject.Name = "%" + projectName + "%"
@ -121,7 +121,7 @@ func (p *ProjectAPI) Get() {
p.CustomAbort(http.StatusInternalServerError, "Internal error.") p.CustomAbort(http.StatusInternalServerError, "Internal error.")
} }
for i := 0; i < len(projectList); i++ { for i := 0; i < len(projectList); i++ {
if isProjectAdmin(p.userID, projectList[i].ProjectId) { if isProjectAdmin(p.userID, projectList[i].ProjectID) {
projectList[i].Togglable = true projectList[i].Togglable = true
} }
} }
@ -167,7 +167,7 @@ func (p *ProjectAPI) FilterAccessLog() {
beginTime := time.Unix(filter.BeginTimestamp, 0) beginTime := time.Unix(filter.BeginTimestamp, 0)
endTime := time.Unix(filter.EndTimestamp, 0) endTime := time.Unix(filter.EndTimestamp, 0)
query := models.AccessLog{ProjectId: p.projectID, Username: "%" + username + "%", Keywords: keywords, BeginTime: beginTime, BeginTimestamp: filter.BeginTimestamp, EndTime: endTime, EndTimestamp: filter.EndTimestamp} query := models.AccessLog{ProjectID: p.projectID, Username: "%" + username + "%", Keywords: keywords, BeginTime: beginTime, BeginTimestamp: filter.BeginTimestamp, EndTime: endTime, EndTimestamp: filter.EndTimestamp}
log.Printf("Query AccessLog: begin: %v, end: %v, keywords: %s", query.BeginTime, query.EndTime, query.Keywords) log.Printf("Query AccessLog: begin: %v, end: %v, keywords: %s", query.BeginTime, query.EndTime, query.Keywords)
@ -181,7 +181,7 @@ func (p *ProjectAPI) FilterAccessLog() {
} }
func isProjectAdmin(userID int, pid int64) bool { func isProjectAdmin(userID int, pid int64) bool {
userQuery := models.User{UserId: userID, RoleId: models.PROJECTADMIN} userQuery := models.User{UserID: userID, RoleID: models.PROJECTADMIN}
rolelist, err := dao.GetUserProjectRoles(userQuery, pid) rolelist, err := dao.GetUserProjectRoles(userQuery, pid)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUserProjectRoles:", err, ", returning false") beego.Error("Error occurred in GetUserProjectRoles:", err, ", returning false")

View File

@ -57,7 +57,7 @@ func (n *SearchAPI) Get() {
} }
if match { if match {
entry := make(map[string]interface{}) entry := make(map[string]interface{})
entry["id"] = p.ProjectId entry["id"] = p.ProjectID
entry["name"] = p.Name entry["name"] = p.Name
entry["public"] = p.Public entry["public"] = p.Public
projectResult = append(projectResult, entry) projectResult = append(projectResult, entry)
@ -93,7 +93,7 @@ func filterRepositories(repositories []string, projects []models.Project, keywor
entry := make(map[string]interface{}) entry := make(map[string]interface{})
entry["repository_name"] = r.Name entry["repository_name"] = r.Name
entry["project_name"] = projects[j].Name entry["project_name"] = projects[j].Name
entry["project_id"] = projects[j].ProjectId entry["project_id"] = projects[j].ProjectID
entry["project_public"] = projects[j].Public entry["project_public"] = projects[j].Public
result = append(result, entry) result = append(result, entry)
} else { } else {

View File

@ -43,7 +43,7 @@ func (ua *UserAPI) Prepare() {
beego.Error("Invalid user id, error:", err) beego.Error("Invalid user id, error:", err)
ua.CustomAbort(http.StatusBadRequest, "Invalid user Id") ua.CustomAbort(http.StatusBadRequest, "Invalid user Id")
} }
userQuery := models.User{UserId: ua.userID} userQuery := models.User{UserID: ua.userID}
u, err := dao.GetUser(userQuery) u, err := dao.GetUser(userQuery)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUser:", err) beego.Error("Error occurred in GetUser:", err)
@ -83,7 +83,7 @@ func (ua *UserAPI) Get() {
ua.Data["json"] = userList ua.Data["json"] = userList
} else if ua.userID == ua.currentUserID || exist { } else if ua.userID == ua.currentUserID || exist {
userQuery := models.User{UserId: ua.userID} userQuery := models.User{UserID: ua.userID}
u, err := dao.GetUser(userQuery) u, err := dao.GetUser(userQuery)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUser:", err) beego.Error("Error occurred in GetUser:", err)
@ -109,7 +109,7 @@ func (ua *UserAPI) Put() { //currently only for toggle admin, so no request body
ua.RenderError(http.StatusForbidden, "User does not have admin role") ua.RenderError(http.StatusForbidden, "User does not have admin role")
return return
} }
userQuery := models.User{UserId: ua.userID} userQuery := models.User{UserID: ua.userID}
dao.ToggleUserAdminRole(userQuery) dao.ToggleUserAdminRole(userQuery)
} }

View File

@ -30,7 +30,7 @@ func CheckProjectPermission(userID int, projectID int64) bool {
if exist { if exist {
return true return true
} }
roleList, err := dao.GetUserProjectRoles(models.User{UserId: userID}, projectID) roleList, err := dao.GetUserProjectRoles(models.User{UserID: userID}, projectID)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUserProjectRoles:", err) beego.Error("Error occurred in GetUserProjectRoles:", err)
return false return false
@ -45,7 +45,7 @@ func CheckUserExists(name string) int {
return 0 return 0
} }
if u != nil { if u != nil {
return u.UserId return u.UserID
} }
return 0 return 0
} }

View File

@ -107,7 +107,7 @@ func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
u.UserId = currentUser.UserId u.UserID = currentUser.UserID
} else { } else {
u.Password = "12345678AbC" u.Password = "12345678AbC"
u.Comment = "registered from LDAP." u.Comment = "registered from LDAP."
@ -115,7 +115,7 @@ func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
u.UserId = int(userID) u.UserID = int(userID)
} }
return &u, nil return &u, nil
} }

View File

@ -63,7 +63,7 @@ func (idc *ItemDetailController) Get() {
idc.Data["Username"] = idc.GetSession("username") idc.Data["Username"] = idc.GetSession("username")
idc.Data["UserId"] = sessionUserID.(int) idc.Data["UserId"] = sessionUserID.(int)
roleList, err := dao.GetUserProjectRoles(models.User{UserId: sessionUserID.(int)}, projectID) roleList, err := dao.GetUserProjectRoles(models.User{UserID: sessionUserID.(int)}, projectID)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUserProjectRoles:", err) beego.Error("Error occurred in GetUserProjectRoles:", err)
idc.CustomAbort(http.StatusInternalServerError, "Internal error.") idc.CustomAbort(http.StatusInternalServerError, "Internal error.")
@ -75,14 +75,14 @@ func (idc *ItemDetailController) Get() {
} }
if len(roleList) > 0 { if len(roleList) > 0 {
idc.Data["RoleId"] = roleList[0].RoleId idc.Data["RoleId"] = roleList[0].RoleID
} }
} }
idc.Data["ProjectId"] = project.ProjectId idc.Data["ProjectId"] = project.ProjectID
idc.Data["ProjectName"] = project.Name idc.Data["ProjectName"] = project.Name
idc.Data["OwnerName"] = project.OwnerName idc.Data["OwnerName"] = project.OwnerName
idc.Data["OwnerId"] = project.OwnerId idc.Data["OwnerId"] = project.OwnerID
idc.Data["HarborRegUrl"] = os.Getenv("HARBOR_REG_URL") idc.Data["HarborRegUrl"] = os.Getenv("HARBOR_REG_URL")
idc.Data["RepoName"] = idc.GetString("repo_name") idc.Data["RepoName"] = idc.GetString("repo_name")

View File

@ -54,7 +54,7 @@ func (c *CommonController) Login() {
c.CustomAbort(http.StatusUnauthorized, "") c.CustomAbort(http.StatusUnauthorized, "")
} }
c.SetSession("userId", user.UserId) c.SetSession("userId", user.UserID)
c.SetSession("username", user.Username) c.SetSession("username", user.Username)
} }

View File

@ -57,7 +57,7 @@ func (cc *CommonController) UpdatePassword() {
cc.CustomAbort(http.StatusBadRequest, "Old password is blank") cc.CustomAbort(http.StatusBadRequest, "Old password is blank")
} }
queryUser := models.User{UserId: sessionUserID.(int), Password: oldPassword} queryUser := models.User{UserID: sessionUserID.(int), Password: oldPassword}
user, err := dao.CheckUserPassword(queryUser) user, err := dao.CheckUserPassword(queryUser)
if err != nil { if err != nil {
beego.Error("Error occurred in CheckUserPassword:", err) beego.Error("Error occurred in CheckUserPassword:", err)
@ -71,7 +71,7 @@ func (cc *CommonController) UpdatePassword() {
password := cc.GetString("password") password := cc.GetString("password")
if password != "" { if password != "" {
updateUser := models.User{UserId: sessionUserID.(int), Password: password, Salt: user.Salt} updateUser := models.User{UserID: sessionUserID.(int), Password: password, Salt: user.Salt}
err = dao.ChangeUserPassword(updateUser, oldPassword) err = dao.ChangeUserPassword(updateUser, oldPassword)
if err != nil { if err != nil {
beego.Error("Error occurred in ChangeUserPassword:", err) beego.Error("Error occurred in ChangeUserPassword:", err)
@ -163,7 +163,7 @@ func (cc *CommonController) SendEmail() {
cc.CustomAbort(http.StatusInternalServerError, "send_email_failed") cc.CustomAbort(http.StatusInternalServerError, "send_email_failed")
} }
user := models.User{ResetUuid: uuid, Email: email} user := models.User{ResetUUID: uuid, Email: email}
dao.UpdateUserResetUuid(user) dao.UpdateUserResetUuid(user)
} }
@ -183,7 +183,7 @@ func (rpc *ResetPasswordController) Get() {
return return
} }
queryUser := models.User{ResetUuid: resetUUID} queryUser := models.User{ResetUUID: resetUUID}
user, err := dao.GetUser(queryUser) user, err := dao.GetUser(queryUser)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUser:", err) beego.Error("Error occurred in GetUser:", err)
@ -191,7 +191,7 @@ func (rpc *ResetPasswordController) Get() {
} }
if user != nil { if user != nil {
rpc.Data["ResetUuid"] = user.ResetUuid rpc.Data["ResetUuid"] = user.ResetUUID
rpc.ForwardTo("page_title_reset_password", "reset-password") rpc.ForwardTo("page_title_reset_password", "reset-password")
} else { } else {
rpc.Redirect("/", http.StatusFound) rpc.Redirect("/", http.StatusFound)
@ -205,7 +205,7 @@ func (cc *CommonController) ResetPassword() {
cc.CustomAbort(http.StatusBadRequest, "Reset uuid is blank.") cc.CustomAbort(http.StatusBadRequest, "Reset uuid is blank.")
} }
queryUser := models.User{ResetUuid: resetUUID} queryUser := models.User{ResetUUID: resetUUID}
user, err := dao.GetUser(queryUser) user, err := dao.GetUser(queryUser)
if err != nil { if err != nil {
beego.Error("Error occurred in GetUser:", err) beego.Error("Error occurred in GetUser:", err)

View File

@ -32,7 +32,7 @@ func AddAccessLog(accessLog models.AccessLog) error {
} }
defer p.Close() defer p.Close()
_, err = p.Exec(accessLog.UserId, accessLog.ProjectId, accessLog.RepoName, accessLog.Guid, accessLog.Operation) _, err = p.Exec(accessLog.UserID, accessLog.ProjectID, accessLog.RepoName, accessLog.GUID, accessLog.Operation)
return err return err
} }
@ -44,11 +44,11 @@ func GetAccessLogs(accessLog models.AccessLog) ([]models.AccessLog, error) {
from access_log a left join user u on a.user_id = u.user_id from access_log a left join user u on a.user_id = u.user_id
where a.project_id = ? ` where a.project_id = ? `
queryParam := make([]interface{}, 1) queryParam := make([]interface{}, 1)
queryParam = append(queryParam, accessLog.ProjectId) queryParam = append(queryParam, accessLog.ProjectID)
if accessLog.UserId != 0 { if accessLog.UserID != 0 {
sql += ` and a.user_id = ? ` sql += ` and a.user_id = ? `
queryParam = append(queryParam, accessLog.UserId) queryParam = append(queryParam, accessLog.UserID)
} }
if accessLog.Operation != "" { if accessLog.Operation != "" {
sql += ` and a.operation = ? ` sql += ` and a.operation = ? `

View File

@ -266,12 +266,12 @@ func TestResetUserPassword(t *testing.T) {
t.Errorf("Error occurred in GenerateRandomString: %v", err) t.Errorf("Error occurred in GenerateRandomString: %v", err)
} }
err = UpdateUserResetUuid(models.User{ResetUuid: uuid, Email: currentUser.Email}) err = UpdateUserResetUuid(models.User{ResetUUID: uuid, Email: currentUser.Email})
if err != nil { if err != nil {
t.Errorf("Error occurred in UpdateUserResetUuid: %v", err) t.Errorf("Error occurred in UpdateUserResetUuid: %v", err)
} }
err = ResetUserPassword(models.User{UserId: currentUser.UserId, Password: "HarborTester12345", ResetUuid: uuid, Salt: currentUser.Salt}) err = ResetUserPassword(models.User{UserID: currentUser.UserID, Password: "HarborTester12345", ResetUUID: uuid, Salt: currentUser.Salt})
if err != nil { if err != nil {
t.Errorf("Error occurred in ResetUserPassword: %v", err) t.Errorf("Error occurred in ResetUserPassword: %v", err)
} }
@ -287,7 +287,7 @@ func TestResetUserPassword(t *testing.T) {
} }
func TestChangeUserPassword(t *testing.T) { func TestChangeUserPassword(t *testing.T) {
err := ChangeUserPassword(models.User{UserId: currentUser.UserId, Password: "NewHarborTester12345", Salt: currentUser.Salt}) err := ChangeUserPassword(models.User{UserID: currentUser.UserID, Password: "NewHarborTester12345", Salt: currentUser.Salt})
if err != nil { if err != nil {
t.Errorf("Error occurred in ChangeUserPassword: %v", err) t.Errorf("Error occurred in ChangeUserPassword: %v", err)
} }
@ -303,7 +303,7 @@ func TestChangeUserPassword(t *testing.T) {
} }
func TestChangeUserPasswordWithOldPassword(t *testing.T) { func TestChangeUserPasswordWithOldPassword(t *testing.T) {
err := ChangeUserPassword(models.User{UserId: currentUser.UserId, Password: "NewerHarborTester12345", Salt: currentUser.Salt}, "NewHarborTester12345") err := ChangeUserPassword(models.User{UserID: currentUser.UserID, Password: "NewerHarborTester12345", Salt: currentUser.Salt}, "NewHarborTester12345")
if err != nil { if err != nil {
t.Errorf("Error occurred in ChangeUserPassword: %v", err) t.Errorf("Error occurred in ChangeUserPassword: %v", err)
} }
@ -317,7 +317,7 @@ func TestChangeUserPasswordWithOldPassword(t *testing.T) {
} }
func TestChangeUserPasswordWithIncorrectOldPassword(t *testing.T) { func TestChangeUserPasswordWithIncorrectOldPassword(t *testing.T) {
err := ChangeUserPassword(models.User{UserId: currentUser.UserId, Password: "NNewerHarborTester12345", Salt: currentUser.Salt}, "WrongNewerHarborTester12345") err := ChangeUserPassword(models.User{UserID: currentUser.UserID, Password: "NNewerHarborTester12345", Salt: currentUser.Salt}, "WrongNewerHarborTester12345")
if err == nil { if err == nil {
t.Errorf("Error does not occurred due to old password is incorrect.") t.Errorf("Error does not occurred due to old password is incorrect.")
} }
@ -331,7 +331,7 @@ func TestChangeUserPasswordWithIncorrectOldPassword(t *testing.T) {
} }
func TestQueryRelevantProjectsWhenNoProjectAdded(t *testing.T) { func TestQueryRelevantProjectsWhenNoProjectAdded(t *testing.T) {
projects, err := QueryRelevantProjects(currentUser.UserId) projects, err := QueryRelevantProjects(currentUser.UserID)
if err != nil { if err != nil {
t.Errorf("Error occurred in QueryRelevantProjects: %v", err) t.Errorf("Error occurred in QueryRelevantProjects: %v", err)
} }
@ -346,7 +346,7 @@ func TestQueryRelevantProjectsWhenNoProjectAdded(t *testing.T) {
func TestAddProject(t *testing.T) { func TestAddProject(t *testing.T) {
project := models.Project{ project := models.Project{
OwnerId: currentUser.UserId, OwnerID: currentUser.UserID,
Name: PROJECT_NAME, Name: PROJECT_NAME,
CreationTime: time.Now(), CreationTime: time.Now(),
OwnerName: currentUser.Username, OwnerName: currentUser.Username,
@ -396,12 +396,12 @@ func getProjectRole(projectId int64) []models.Role {
} }
func TestCheckProjectRoles(t *testing.T) { func TestCheckProjectRoles(t *testing.T) {
r := getProjectRole(currentProject.ProjectId) r := getProjectRole(currentProject.ProjectID)
if len(r) != 3 { if len(r) != 3 {
t.Errorf("The length of project roles is not 3") t.Errorf("The length of project roles is not 3")
} }
if r[1].RoleId != 3 { if r[1].RoleID != 3 {
t.Errorf("The role id does not match, expected: 3, acutal: %d", r[1].RoleId) t.Errorf("The role id does not match, expected: 3, acutal: %d", r[1].RoleID)
} }
if r[1].Name != "developer" { if r[1].Name != "developer" {
t.Errorf("The name of role id: 3 should be developer, actual:%s", r[1].Name) t.Errorf("The name of role id: 3 should be developer, actual:%s", r[1].Name)
@ -410,8 +410,8 @@ func TestCheckProjectRoles(t *testing.T) {
func TestGetAccessLog(t *testing.T) { func TestGetAccessLog(t *testing.T) {
queryAccessLog := models.AccessLog{ queryAccessLog := models.AccessLog{
UserId: currentUser.UserId, UserID: currentUser.UserID,
ProjectId: currentProject.ProjectId, ProjectID: currentProject.ProjectID,
} }
accessLogs, err := GetAccessLogs(queryAccessLog) accessLogs, err := GetAccessLogs(queryAccessLog)
if err != nil { if err != nil {
@ -428,12 +428,12 @@ func TestGetAccessLog(t *testing.T) {
func TestProjectExists(t *testing.T) { func TestProjectExists(t *testing.T) {
var exists bool var exists bool
var err error var err error
exists, err = ProjectExists(currentProject.ProjectId) exists, err = ProjectExists(currentProject.ProjectID)
if err != nil { if err != nil {
t.Errorf("Error occurred in ProjectExists: %v", err) t.Errorf("Error occurred in ProjectExists: %v", err)
} }
if !exists { if !exists {
t.Errorf("The project with id: %d, does not exist", currentProject.ProjectId) t.Errorf("The project with id: %d, does not exist", currentProject.ProjectID)
} }
exists, err = ProjectExists(currentProject.Name) exists, err = ProjectExists(currentProject.Name)
if err != nil { if err != nil {
@ -445,7 +445,7 @@ func TestProjectExists(t *testing.T) {
} }
func TestGetProjectById(t *testing.T) { func TestGetProjectById(t *testing.T) {
id := currentProject.ProjectId id := currentProject.ProjectID
p, err := GetProjectById(id) p, err := GetProjectById(id)
if err != nil { if err != nil {
t.Errorf("Error in GetProjectById: %v, id: %d", err, id) t.Errorf("Error in GetProjectById: %v, id: %d", err, id)
@ -456,7 +456,7 @@ func TestGetProjectById(t *testing.T) {
} }
func TestGetUserByProject(t *testing.T) { func TestGetUserByProject(t *testing.T) {
pid := currentProject.ProjectId pid := currentProject.ProjectID
u1 := models.User{ u1 := models.User{
Username: "%%Tester%%", Username: "%%Tester%%",
} }
@ -481,7 +481,7 @@ func TestGetUserByProject(t *testing.T) {
} }
func TestToggleProjectPublicity(t *testing.T) { func TestToggleProjectPublicity(t *testing.T) {
err := ToggleProjectPublicity(currentProject.ProjectId, PUBLICITY_ON) err := ToggleProjectPublicity(currentProject.ProjectID, PUBLICITY_ON)
if err != nil { if err != nil {
t.Errorf("Error occurred in ToggleProjectPublicity: %v", err) t.Errorf("Error occurred in ToggleProjectPublicity: %v", err)
} }
@ -491,9 +491,9 @@ func TestToggleProjectPublicity(t *testing.T) {
t.Errorf("Error occurred in GetProjectByName: %v", err) t.Errorf("Error occurred in GetProjectByName: %v", err)
} }
if currentProject.Public != PUBLICITY_ON { if currentProject.Public != PUBLICITY_ON {
t.Errorf("project, id: %d, its publicity is not on", currentProject.ProjectId) t.Errorf("project, id: %d, its publicity is not on", currentProject.ProjectID)
} }
err = ToggleProjectPublicity(currentProject.ProjectId, PUBLICITY_OFF) err = ToggleProjectPublicity(currentProject.ProjectID, PUBLICITY_OFF)
if err != nil { if err != nil {
t.Errorf("Error occurred in ToggleProjectPublicity: %v", err) t.Errorf("Error occurred in ToggleProjectPublicity: %v", err)
} }
@ -504,7 +504,7 @@ func TestToggleProjectPublicity(t *testing.T) {
} }
if currentProject.Public != PUBLICITY_OFF { if currentProject.Public != PUBLICITY_OFF {
t.Errorf("project, id: %d, its publicity is not off", currentProject.ProjectId) t.Errorf("project, id: %d, its publicity is not off", currentProject.ProjectID)
} }
} }
@ -512,13 +512,13 @@ func TestToggleProjectPublicity(t *testing.T) {
func TestIsProjectPublic(t *testing.T) { func TestIsProjectPublic(t *testing.T) {
if isPublic := IsProjectPublic(PROJECT_NAME); isPublic { if isPublic := IsProjectPublic(PROJECT_NAME); isPublic {
t.Errorf("project, id: %d, its publicity is not false after turning off", currentProject.ProjectId) t.Errorf("project, id: %d, its publicity is not false after turning off", currentProject.ProjectID)
} }
} }
func TestQueryProject(t *testing.T) { func TestQueryProject(t *testing.T) {
query1 := models.Project{ query1 := models.Project{
UserId: 1, UserID: 1,
} }
projects, err := QueryProject(query1) projects, err := QueryProject(query1)
if err != nil { if err != nil {
@ -538,7 +538,7 @@ func TestQueryProject(t *testing.T) {
t.Errorf("Expecting get 1 project, but actual: %d, the list: %+v", len(projects), projects) t.Errorf("Expecting get 1 project, but actual: %d, the list: %+v", len(projects), projects)
} }
query3 := models.Project{ query3 := models.Project{
UserId: 9, UserID: 9,
} }
projects, err = QueryProject(query3) projects, err = QueryProject(query3)
if err != nil { if err != nil {
@ -565,28 +565,28 @@ func getUserProjectRole(projectId int64, userId int) []models.Role {
func TestGetUserProjectRoles(t *testing.T) { func TestGetUserProjectRoles(t *testing.T) {
user := *currentUser user := *currentUser
r, err := GetUserProjectRoles(user, currentProject.ProjectId) r, err := GetUserProjectRoles(user, currentProject.ProjectID)
if err != nil { if err != nil {
t.Errorf("Error happened in GetUserProjectRole: %v, user: %+v, project Id: %d", err, user, currentProject.ProjectId) t.Errorf("Error happened in GetUserProjectRole: %v, user: %+v, project Id: %d", err, user, currentProject.ProjectID)
} }
//Get the size of current user project role. //Get the size of current user project role.
if len(r) != 1 { if len(r) != 1 {
t.Errorf("The user, id: %d, should only have one role in project, id: %d, but actual: %d", currentUser.UserId, currentProject.ProjectId, len(r)) t.Errorf("The user, id: %d, should only have one role in project, id: %d, but actual: %d", currentUser.UserID, currentProject.ProjectID, len(r))
} }
if r[0].Name != "projectAdmin" { if r[0].Name != "projectAdmin" {
t.Errorf("the expected rolename is: projectAdmin, actual: %s", r[0].Name) t.Errorf("the expected rolename is: projectAdmin, actual: %s", r[0].Name)
} }
user.RoleId = 1 user.RoleID = 1
r, err = GetUserProjectRoles(user, currentProject.ProjectId) r, err = GetUserProjectRoles(user, currentProject.ProjectID)
if err != nil { if err != nil {
t.Errorf("Error happened in GetUserProjectRole: %v, user: %+v, project Id: %d", err, user, currentProject.ProjectId) t.Errorf("Error happened in GetUserProjectRole: %v, user: %+v, project Id: %d", err, user, currentProject.ProjectID)
} }
//Get the size of current user project role. //Get the size of current user project role.
if len(r) != 0 { if len(r) != 0 {
t.Errorf("The user, id: %d, should not have role id: 1 in project id: %d, actual role list: %v", currentUser.UserId, currentProject.ProjectId, r) t.Errorf("The user, id: %d, should not have role id: 1 in project id: %d, actual role list: %v", currentUser.UserID, currentProject.ProjectID, r)
} }
} }
@ -601,7 +601,7 @@ func TestProjectPermission(t *testing.T) {
} }
func TestQueryRelevantProjects(t *testing.T) { func TestQueryRelevantProjects(t *testing.T) {
projects, err := QueryRelevantProjects(currentUser.UserId) projects, err := QueryRelevantProjects(currentUser.UserID)
if err != nil { if err != nil {
t.Errorf("Error occurred in QueryRelevantProjects: %v", err) t.Errorf("Error occurred in QueryRelevantProjects: %v", err)
} }
@ -614,30 +614,30 @@ func TestQueryRelevantProjects(t *testing.T) {
} }
func TestAssignUserProjectRole(t *testing.T) { func TestAssignUserProjectRole(t *testing.T) {
err := AddUserProjectRole(currentUser.UserId, currentProject.ProjectId, DEVELOPER) err := AddUserProjectRole(currentUser.UserID, currentProject.ProjectID, DEVELOPER)
if err != nil { if err != nil {
t.Errorf("Error occurred in AddUserProjectRole: %v", err) t.Errorf("Error occurred in AddUserProjectRole: %v", err)
} }
r := getUserProjectRole(currentProject.ProjectId, currentUser.UserId) r := getUserProjectRole(currentProject.ProjectID, currentUser.UserID)
//Get the size of current user project role info. //Get the size of current user project role info.
if len(r) != 2 { if len(r) != 2 {
t.Errorf("Expected length of role list is 2, actual: %d", len(r)) t.Errorf("Expected length of role list is 2, actual: %d", len(r))
} }
if r[1].RoleId != 3 { if r[1].RoleID != 3 {
t.Errorf("Expected role id of the second role in list is 3, actual: %d", r[1].RoleId) t.Errorf("Expected role id of the second role in list is 3, actual: %d", r[1].RoleID)
} }
} }
func TestDeleteUserProjectRole(t *testing.T) { func TestDeleteUserProjectRole(t *testing.T) {
err := DeleteUserProjectRoles(currentUser.UserId, currentProject.ProjectId) err := DeleteUserProjectRoles(currentUser.UserID, currentProject.ProjectID)
if err != nil { if err != nil {
t.Errorf("Error occurred in DeleteUserProjectRoles: %v", err) t.Errorf("Error occurred in DeleteUserProjectRoles: %v", err)
} }
r := getUserProjectRole(currentProject.ProjectId, currentUser.UserId) r := getUserProjectRole(currentProject.ProjectID, currentUser.UserID)
//Get the size of current user project role. //Get the size of current user project role.
if len(r) != 0 { if len(r) != 0 {
t.Errorf("Expected role list length is 0, actual: %d, role list: %+v", len(r), r) t.Errorf("Expected role list length is 0, actual: %d, role list: %+v", len(r), r)
@ -649,28 +649,28 @@ func TestToggleAdminRole(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Error in toggle ToggleUserAdmin role: %v, user: %+v", err, currentUser) t.Errorf("Error in toggle ToggleUserAdmin role: %v, user: %+v", err, currentUser)
} }
isAdmin, err := IsAdminRole(currentUser.UserId) isAdmin, err := IsAdminRole(currentUser.UserID)
if err != nil { if err != nil {
t.Errorf("Error in IsAdminRole: %v, user id: %d", err, currentUser.UserId) t.Errorf("Error in IsAdminRole: %v, user id: %d", err, currentUser.UserID)
} }
if !isAdmin { if !isAdmin {
t.Errorf("User is not admin after toggled, user id: %d", currentUser.UserId) t.Errorf("User is not admin after toggled, user id: %d", currentUser.UserID)
} }
err = ToggleUserAdminRole(*currentUser) err = ToggleUserAdminRole(*currentUser)
if err != nil { if err != nil {
t.Errorf("Error in toggle ToggleUserAdmin role: %v, user: %+v", err, currentUser) t.Errorf("Error in toggle ToggleUserAdmin role: %v, user: %+v", err, currentUser)
} }
isAdmin, err = IsAdminRole(currentUser.UserId) isAdmin, err = IsAdminRole(currentUser.UserID)
if err != nil { if err != nil {
t.Errorf("Error in IsAdminRole: %v, user id: %d", err, currentUser.UserId) t.Errorf("Error in IsAdminRole: %v, user id: %d", err, currentUser.UserID)
} }
if isAdmin { if isAdmin {
t.Errorf("User is still admin after toggled, user id: %d", currentUser.UserId) t.Errorf("User is still admin after toggled, user id: %d", currentUser.UserID)
} }
} }
func TestDeleteUser(t *testing.T) { func TestDeleteUser(t *testing.T) {
err := DeleteUser(currentUser.UserId) err := DeleteUser(currentUser.UserID)
if err != nil { if err != nil {
t.Errorf("Error occurred in DeleteUser: %v", err) t.Errorf("Error occurred in DeleteUser: %v", err)
} }

View File

@ -42,7 +42,7 @@ func AddProject(project models.Project) error {
return err return err
} }
r, err := p.Exec(project.OwnerId, project.Name, project.Deleted, project.Public) r, err := p.Exec(project.OwnerID, project.Name, project.Deleted, project.Public)
if err != nil { if err != nil {
return err return err
} }
@ -52,31 +52,31 @@ func AddProject(project models.Project) error {
return err return err
} }
projectAdminRole := models.ProjectRole{ProjectId: projectId, RoleId: models.PROJECTADMIN} projectAdminRole := models.ProjectRole{ProjectID: projectId, RoleID: models.PROJECTADMIN}
_, err = AddProjectRole(projectAdminRole) _, err = AddProjectRole(projectAdminRole)
if err != nil { if err != nil {
return err return err
} }
projectDeveloperRole := models.ProjectRole{ProjectId: projectId, RoleId: models.DEVELOPER} projectDeveloperRole := models.ProjectRole{ProjectID: projectId, RoleID: models.DEVELOPER}
_, err = AddProjectRole(projectDeveloperRole) _, err = AddProjectRole(projectDeveloperRole)
if err != nil { if err != nil {
return err return err
} }
projectGuestRole := models.ProjectRole{ProjectId: projectId, RoleId: models.GUEST} projectGuestRole := models.ProjectRole{ProjectID: projectId, RoleID: models.GUEST}
_, err = AddProjectRole(projectGuestRole) _, err = AddProjectRole(projectGuestRole)
if err != nil { if err != nil {
return err return err
} }
//Add all project roles, after that when assigning a user to a project just update the upr table //Add all project roles, after that when assigning a user to a project just update the upr table
err = AddUserProjectRole(project.OwnerId, projectId, models.PROJECTADMIN) err = AddUserProjectRole(project.OwnerID, projectId, models.PROJECTADMIN)
if err != nil { if err != nil {
return err return err
} }
accessLog := models.AccessLog{UserId: project.OwnerId, ProjectId: projectId, RepoName: project.Name + "/", Guid: "N/A", Operation: "create", OpTime: time.Now()} accessLog := models.AccessLog{UserID: project.OwnerID, ProjectID: projectId, RepoName: project.Name + "/", GUID: "N/A", Operation: "create", OpTime: time.Now()}
err = AddAccessLog(accessLog) err = AddAccessLog(accessLog)
return err return err
@ -111,10 +111,10 @@ func QueryProject(query models.Project) ([]models.Project, error) {
if query.Public == 1 { if query.Public == 1 {
sql += ` and p.public = ?` sql += ` and p.public = ?`
queryParam = append(queryParam, query.Public) queryParam = append(queryParam, query.Public)
} else if isAdmin, _ := IsAdminRole(query.UserId); isAdmin == false { } else if isAdmin, _ := IsAdminRole(query.UserID); isAdmin == false {
sql += ` and (p.owner_id = ? or u.user_id = ?) ` sql += ` and (p.owner_id = ? or u.user_id = ?) `
queryParam = append(queryParam, query.UserId) queryParam = append(queryParam, query.UserID)
queryParam = append(queryParam, query.UserId) queryParam = append(queryParam, query.UserID)
} }
if query.Name != "" { if query.Name != "" {

View File

@ -27,7 +27,7 @@ func AddProjectRole(projectRole models.ProjectRole) (int64, error) {
return 0, err return 0, err
} }
defer p.Close() defer p.Close()
r, err := p.Exec(projectRole.ProjectId, projectRole.RoleId) r, err := p.Exec(projectRole.ProjectID, projectRole.RoleID)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -65,7 +65,7 @@ func AddUserProjectRole(userId int, projectId int64, roleId int) error {
} }
prId = int(id) prId = int(id)
} else if n > 0 { } else if n > 0 {
prId = pr[0].PrId prId = pr[0].PrID
} }
p, err := o.Raw("insert into user_project_role (user_id, pr_id) values (?, ?)").Prepare() p, err := o.Raw("insert into user_project_role (user_id, pr_id) values (?, ?)").Prepare()
if err != nil { if err != nil {

View File

@ -32,15 +32,15 @@ func GetUserProjectRoles(userQuery models.User, projectId int64) ([]models.Role,
where u.deleted = 0 where u.deleted = 0
and u.user_id = ? ` and u.user_id = ? `
queryParam := make([]interface{}, 1) queryParam := make([]interface{}, 1)
queryParam = append(queryParam, userQuery.UserId) queryParam = append(queryParam, userQuery.UserID)
if projectId > 0 { if projectId > 0 {
sql += ` and pr.project_id = ? ` sql += ` and pr.project_id = ? `
queryParam = append(queryParam, projectId) queryParam = append(queryParam, projectId)
} }
if userQuery.RoleId > 0 { if userQuery.RoleID > 0 {
sql += ` and r.role_id = ? ` sql += ` and r.role_id = ? `
queryParam = append(queryParam, userQuery.RoleId) queryParam = append(queryParam, userQuery.RoleID)
} }
var roleList []models.Role var roleList []models.Role
@ -54,7 +54,7 @@ func GetUserProjectRoles(userQuery models.User, projectId int64) ([]models.Role,
func IsAdminRole(userId int) (bool, error) { func IsAdminRole(userId int) (bool, error) {
//role_id == 1 means the user is system admin //role_id == 1 means the user is system admin
userQuery := models.User{UserId: userId, RoleId: models.SYSADMIN} userQuery := models.User{UserID: userId, RoleID: models.SYSADMIN}
adminRoleList, err := GetUserProjectRoles(userQuery, 0) adminRoleList, err := GetUserProjectRoles(userQuery, 0)
if err != nil { if err != nil {
return false, err return false, err

View File

@ -38,9 +38,9 @@ func GetUser(query models.User) (*models.User, error) {
from user u from user u
where deleted = 0 ` where deleted = 0 `
queryParam := make([]interface{}, 1) queryParam := make([]interface{}, 1)
if query.UserId != 0 { if query.UserID != 0 {
sql += ` and user_id = ? ` sql += ` and user_id = ? `
queryParam = append(queryParam, query.UserId) queryParam = append(queryParam, query.UserID)
} }
if query.Username != "" { if query.Username != "" {
@ -48,9 +48,9 @@ func GetUser(query models.User) (*models.User, error) {
queryParam = append(queryParam, query.Username) queryParam = append(queryParam, query.Username)
} }
if query.ResetUuid != "" { if query.ResetUUID != "" {
sql += ` and reset_uuid = ? ` sql += ` and reset_uuid = ? `
queryParam = append(queryParam, query.ResetUuid) queryParam = append(queryParam, query.ResetUUID)
} }
var u []models.User var u []models.User
@ -108,13 +108,13 @@ func ListUsers(query models.User) ([]models.User, error) {
func ToggleUserAdminRole(u models.User) error { func ToggleUserAdminRole(u models.User) error {
projectRole := models.ProjectRole{PrId: 1} //admin project role projectRole := models.ProjectRole{PrID: 1} //admin project role
o := orm.NewOrm() o := orm.NewOrm()
var pr []models.ProjectRole var pr []models.ProjectRole
n, err := o.Raw(`select user_id from user_project_role where user_id = ? and pr_id = ? `, u.UserId, projectRole.PrId).QueryRows(&pr) n, err := o.Raw(`select user_id from user_project_role where user_id = ? and pr_id = ? `, u.UserID, projectRole.PrID).QueryRows(&pr)
if err != nil { if err != nil {
return err return err
} }
@ -131,7 +131,7 @@ func ToggleUserAdminRole(u models.User) error {
return err return err
} }
defer p.Close() defer p.Close()
_, err = p.Exec(u.UserId, projectRole.PrId) _, err = p.Exec(u.UserID, projectRole.PrID)
return err return err
} }
@ -142,9 +142,9 @@ func ChangeUserPassword(u models.User, oldPassword ...string) error {
var r sql.Result var r sql.Result
if len(oldPassword) == 0 { if len(oldPassword) == 0 {
//In some cases, it may no need to check old password, just as Linux change password policies. //In some cases, it may no need to check old password, just as Linux change password policies.
_, err = o.Raw(`update user set password=?, salt=? where user_id=?`, utils.Encrypt(u.Password, u.Salt), u.Salt, u.UserId).Exec() _, err = o.Raw(`update user set password=?, salt=? where user_id=?`, utils.Encrypt(u.Password, u.Salt), u.Salt, u.UserID).Exec()
} else if len(oldPassword) == 1 { } else if len(oldPassword) == 1 {
r, err = o.Raw(`update user set password=?, salt=? where user_id=? and password = ?`, utils.Encrypt(u.Password, u.Salt), u.Salt, u.UserId, utils.Encrypt(oldPassword[0], u.Salt)).Exec() r, err = o.Raw(`update user set password=?, salt=? where user_id=? and password = ?`, utils.Encrypt(u.Password, u.Salt), u.Salt, u.UserID, utils.Encrypt(oldPassword[0], u.Salt)).Exec()
if err != nil { if err != nil {
return err return err
} }
@ -163,7 +163,7 @@ func ChangeUserPassword(u models.User, oldPassword ...string) error {
func ResetUserPassword(u models.User) error { func ResetUserPassword(u models.User) error {
o := orm.NewOrm() o := orm.NewOrm()
r, err := o.Raw(`update user set password=?, reset_uuid=? where reset_uuid=?`, utils.Encrypt(u.Password, u.Salt), "", u.ResetUuid).Exec() r, err := o.Raw(`update user set password=?, reset_uuid=? where reset_uuid=?`, utils.Encrypt(u.Password, u.Salt), "", u.ResetUUID).Exec()
if err != nil { if err != nil {
return err return err
} }
@ -179,7 +179,7 @@ func ResetUserPassword(u models.User) error {
func UpdateUserResetUuid(u models.User) error { func UpdateUserResetUuid(u models.User) error {
o := orm.NewOrm() o := orm.NewOrm()
_, err := o.Raw(`update user set reset_uuid=? where email=?`, u.ResetUuid, u.Email).Exec() _, err := o.Raw(`update user set reset_uuid=? where email=?`, u.ResetUUID, u.Email).Exec()
return err return err
} }
@ -199,10 +199,10 @@ func CheckUserPassword(query models.User) (*models.User, error) {
queryParam := make([]interface{}, 1) queryParam := make([]interface{}, 1)
if query.UserId != 0 { if query.UserID != 0 {
sql += ` and password = ? and user_id = ?` sql += ` and password = ? and user_id = ?`
queryParam = append(queryParam, utils.Encrypt(query.Password, currentUser.Salt)) queryParam = append(queryParam, utils.Encrypt(query.Password, currentUser.Salt))
queryParam = append(queryParam, query.UserId) queryParam = append(queryParam, query.UserID)
} else { } else {
sql += ` and username = ? and password = ?` sql += ` and username = ? and password = ?`
queryParam = append(queryParam, currentUser.Username) queryParam = append(queryParam, currentUser.Username)

View File

@ -34,7 +34,7 @@ const (
) )
func updateInitPassword(userID int, password string) error { func updateInitPassword(userID int, password string) error {
queryUser := models.User{UserId: userID} queryUser := models.User{UserID: userID}
user, err := dao.GetUser(queryUser) user, err := dao.GetUser(queryUser)
if err != nil { if err != nil {
log.Println("Failed to get user, userID:", userID) log.Println("Failed to get user, userID:", userID)

View File

@ -19,13 +19,13 @@ import (
) )
type AccessLog struct { type AccessLog struct {
LogId int LogID int `orm:"column(log_id)"`
UserId int UserID int `orm:"column(user_id)"`
ProjectId int64 ProjectID int64 `orm:"column(project_id)"`
RepoName string RepoName string `orm:"column(repo_name)"`
Guid string GUID string `orm:"column(GUID)"`
Operation string Operation string `orm:"column(operation)"`
OpTime time.Time OpTime time.Time `orm:"column(op_time)"`
Username string Username string
Keywords string Keywords string

View File

@ -1,16 +1,16 @@
/* /*
Copyright (c) 2016 VMware, Inc. All Rights Reserved. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package models package models
@ -23,7 +23,7 @@ type Notification struct {
} }
type Event struct { type Event struct {
Id string ID string
TimeStamp time.Time TimeStamp time.Time
Action string Action string
Target *Target Target *Target
@ -35,7 +35,7 @@ type Target struct {
MediaType string MediaType string
Digest string Digest string
Repository string Repository string
Url string URL string
} }
type Actor struct { type Actor struct {
@ -43,7 +43,7 @@ type Actor struct {
} }
type Request struct { type Request struct {
Id string ID string
Method string Method string
UserAgent string UserAgent string
} }

View File

@ -1,16 +1,16 @@
/* /*
Copyright (c) 2016 VMware, Inc. All Rights Reserved. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package models package models
@ -19,15 +19,15 @@ import (
) )
type Project struct { type Project struct {
ProjectId int64 ProjectID int64 `orm:"column(project_id)"`
OwnerId int OwnerID int `orm:"column(owner_id)"`
Name string Name string `orm:"column(name)"`
CreationTime time.Time CreationTime time.Time `orm:"column(creation_time)"`
CreationTimeStr string CreationTimeStr string
Deleted int Deleted int `orm:"column(deleted)"`
UserId int UserID int
OwnerName string OwnerName string
Public int Public int `orm:"column(public)"`
//This field does not have correspondent column in DB, this is just for UI to disable button //This field does not have correspondent column in DB, this is just for UI to disable button
Togglable bool Togglable bool
} }

View File

@ -1,21 +1,21 @@
/* /*
Copyright (c) 2016 VMware, Inc. All Rights Reserved. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package models package models
type ProjectRole struct { type ProjectRole struct {
PrId int PrID int `orm:"column(pr_id)"`
ProjectId int64 ProjectID int64 `orm:"column(project_id)"`
RoleId int RoleID int `orm:"column(role_id)"`
} }

View File

@ -1,16 +1,16 @@
/* /*
Copyright (c) 2016 VMware, Inc. All Rights Reserved. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package models package models
@ -19,14 +19,14 @@ import (
) )
type RepoItem struct { type RepoItem struct {
Id string `json:"Id"` ID string `json:"Id"`
Parent string `json:"Parent"` Parent string `json:"Parent"`
Created time.Time `json:"Created"` Created time.Time `json:"Created"`
CreatedStr string `json:"CreatedStr"` CreatedStr string `json:"CreatedStr"`
DurationDays string `json:"Duration Days"` DurationDays string `json:"Duration Days"`
Author string `json:"Author"` Author string `json:"Author"`
Architecture string `json:"Architecture"` Architecture string `json:"Architecture"`
Docker_version string `json:"Docker Version"` DockerVersion string `json:"Docker Version"`
Os string `json:"OS"` Os string `json:"OS"`
//Size int `json:"Size"` //Size int `json:"Size"`
} }

View File

@ -1,16 +1,16 @@
/* /*
Copyright (c) 2016 VMware, Inc. All Rights Reserved. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package models package models
@ -22,7 +22,7 @@ const (
) )
type Role struct { type Role struct {
RoleId int `json:"role_id"` RoleID int `json:"role_id", orm:"column(role_id)"`
RoleCode string `json:"role_code"` RoleCode string `json:"role_code, orm:"column(role_code)""`
Name string `json:"role_name"` Name string `json:"role_name", orm:"column(name)"`
} }

View File

@ -1,20 +1,20 @@
/* /*
Copyright (c) 2016 VMware, Inc. All Rights Reserved. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package models package models
type Tag struct { type Tag struct {
Version string `json:version` Version string `json:version`
ImageId string `json:image_id` ImageID string `json:image_id`
} }

View File

@ -1,31 +1,31 @@
/* /*
Copyright (c) 2016 VMware, Inc. All Rights Reserved. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package models package models
type User struct { type User struct {
UserId int UserID int `orm:"column(user_id)"`
Username string Username string `orm:"column(username)"`
Email string Email string `orm:"column(email)"`
Password string Password string `orm:"column(password)"`
Realname string Realname string `orm:"column(realname)"`
Comment string Comment string `orm:"column(comment)"`
Deleted int Deleted int `orm:"column(deleted)"`
Rolename string Rolename string
RoleId int RoleID int
RoleList []Role RoleList []Role
HasAdminRole int HasAdminRole int
ResetUuid string ResetUUID string `orm:"column(reset_uuid)"`
Salt string Salt string `orm:"column(salt)"`
} }

View File

@ -1,21 +1,21 @@
/* /*
Copyright (c) 2016 VMware, Inc. All Rights Reserved. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package models package models
type UserProjectRole struct { type UserProjectRole struct {
UprId int UprID int `orm:"column(upr_id)"`
UserId int UserID int `orm:"column(user_id)"`
PrId int64 PrID int64 `orm:"column(pr_id)"`
} }