03ea72595d
* Initial Commit for OAuth API This builds and run and return the right error. Need to test it and then adding all users as possible client * Added mising dependency * just compile already... * Fixing template test * Imrpovements Moved db stuff in models Added some tests Added form in modpanel to add/update a client Added controllers for add/update of client * Added Forms + speed improvements Controller oauth client listing + html Controller oauth client delete + messages Messages on comment delete New ES config that disable ES if set to false. Improve load speed on local development Fix a load config bug Fix index admin & translation string sign_out broken by @ewhal * Sanitize empty strig in form array + css Multiple empty array of strings are sanitized for the oauth client create form Added some css for the form display * Upload and Create form works * Fix splitting response types * Removing required on secret when updating * fix travis error * Fix travis template test * Update dependency * Moved to jinzhu instead of azhao * randomizen secret on creation * Final touch on oath api improved display name fix grant form csrf fix login csrf on oauth * Fix gorm test * fix template test * Fixing deleted dependency issue * Make travis faster * Fix typo * Fix csrf for api calls * This shouldn't be exempt * Removing hard coded hash @ewhal Don't forget to replace the hash in tokens.go with another one * Added an example on how to use OAuth middleware * Renamed fosite utils to oauth2 utils
63 lignes
1,9 Kio
Go
63 lignes
1,9 Kio
Go
package gorm
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// Define callbacks for deleting
|
|
func init() {
|
|
DefaultCallback.Delete().Register("gorm:begin_transaction", beginTransactionCallback)
|
|
DefaultCallback.Delete().Register("gorm:before_delete", beforeDeleteCallback)
|
|
DefaultCallback.Delete().Register("gorm:delete", deleteCallback)
|
|
DefaultCallback.Delete().Register("gorm:after_delete", afterDeleteCallback)
|
|
DefaultCallback.Delete().Register("gorm:commit_or_rollback_transaction", commitOrRollbackTransactionCallback)
|
|
}
|
|
|
|
// beforeDeleteCallback will invoke `BeforeDelete` method before deleting
|
|
func beforeDeleteCallback(scope *Scope) {
|
|
if scope.DB().HasBlockGlobalUpdate() && !scope.hasConditions() {
|
|
scope.Err(errors.New("Missing WHERE clause while deleting"))
|
|
return
|
|
}
|
|
if !scope.HasError() {
|
|
scope.CallMethod("BeforeDelete")
|
|
}
|
|
}
|
|
|
|
// deleteCallback used to delete data from database or set deleted_at to current time (when using with soft delete)
|
|
func deleteCallback(scope *Scope) {
|
|
if !scope.HasError() {
|
|
var extraOption string
|
|
if str, ok := scope.Get("gorm:delete_option"); ok {
|
|
extraOption = fmt.Sprint(str)
|
|
}
|
|
|
|
deletedAtField, hasDeletedAtField := scope.FieldByName("DeletedAt")
|
|
|
|
if !scope.Search.Unscoped && hasDeletedAtField {
|
|
scope.Raw(fmt.Sprintf(
|
|
"UPDATE %v SET %v=%v%v%v",
|
|
scope.QuotedTableName(),
|
|
scope.Quote(deletedAtField.DBName),
|
|
scope.AddToVars(NowFunc()),
|
|
addExtraSpaceIfExist(scope.CombinedConditionSql()),
|
|
addExtraSpaceIfExist(extraOption),
|
|
)).Exec()
|
|
} else {
|
|
scope.Raw(fmt.Sprintf(
|
|
"DELETE FROM %v%v%v",
|
|
scope.QuotedTableName(),
|
|
addExtraSpaceIfExist(scope.CombinedConditionSql()),
|
|
addExtraSpaceIfExist(extraOption),
|
|
)).Exec()
|
|
}
|
|
}
|
|
}
|
|
|
|
// afterDeleteCallback will invoke `AfterDelete` method after deleting
|
|
func afterDeleteCallback(scope *Scope) {
|
|
if !scope.HasError() {
|
|
scope.CallMethod("AfterDelete")
|
|
}
|
|
}
|