Skip to content

Commit 43c1f46

Browse files
committed
ci: remove duplicate CI workflow from fork; switch README badge to upstream 'Swift CI (Swift 6)'
1 parent 3047562 commit 43c1f46

File tree

19 files changed

+285
-666
lines changed

19 files changed

+285
-666
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SwiftCasbin
22
====
33

4-
[![CI](https://github.com/wendylabsinc/SwiftCasbin/actions/workflows/ci.yml/badge.svg)](https://github.com/wendylabsinc/SwiftCasbin/actions/workflows/ci.yml)
4+
[![CI](https://github.com/casbin/SwiftCasbin/actions/workflows/swift.yml/badge.svg)](https://github.com/casbin/SwiftCasbin/actions/workflows/swift.yml)
55
![Swift 6.0](https://img.shields.io/badge/Swift-6.0-orange)
66
![iOS 18+](https://img.shields.io/badge/iOS-18%2B-blue)
77
![macOS 15+](https://img.shields.io/badge/macOS-15%2B-blue)

Sources/Casbin/API/CoreAPI.swift

Lines changed: 0 additions & 66 deletions
This file was deleted.

Sources/Casbin/API/InternalAPI.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
extension CoreAPI {
15+
extension Enforcer {
1616
//MARK: InternalApi
1717
func addPolicyInternal(sec: String, ptype: String, rule: [String]) async throws -> Bool {
1818
let _bool = try await adapter.addPolicy(sec: sec, ptype: ptype, rule: rule)
@@ -21,7 +21,7 @@ extension CoreAPI {
2121
}
2222
let ruleAdded = model.addPolicy(sec: sec, ptype: ptype, rule: rule)
2323
let eventData = EventData.AddPolicy(sec, ptype, rule)
24-
return try afterOperatePolicy(sec: sec, oped: ruleAdded, d: eventData, t: ruleAdded)
24+
return try await afterOperatePolicy(sec: sec, oped: ruleAdded, d: eventData, t: ruleAdded)
2525
}
2626

2727
func addPoliciesInternal(sec: String, ptype: String, rules: [[String]]) async throws -> Bool {
@@ -31,7 +31,7 @@ extension CoreAPI {
3131
}
3232
let rulesAdded = model.addPolicies(sec: sec, ptype: ptype, rules: rules)
3333
let eventData = EventData.AddPolicies(sec, ptype, rules)
34-
return try afterOperatePolicy(sec: sec, oped: rulesAdded, d: eventData, t: rulesAdded)
34+
return try await afterOperatePolicy(sec: sec, oped: rulesAdded, d: eventData, t: rulesAdded)
3535
}
3636

3737
func removePolicyInternal(sec: String, ptype: String, rule: [String]) async throws -> Bool {
@@ -41,7 +41,7 @@ extension CoreAPI {
4141
}
4242
let ruleRemoved = model.removePolicy(sec: sec, ptype: ptype, rule: rule)
4343
let eventData = EventData.RemovePolicy(sec, ptype, rule)
44-
return try afterOperatePolicy(sec: sec, oped: ruleRemoved, d: eventData, t: ruleRemoved)
44+
return try await afterOperatePolicy(sec: sec, oped: ruleRemoved, d: eventData, t: ruleRemoved)
4545
}
4646

4747
func removePoliciesInternal(sec: String, ptype: String, rules: [[String]]) async throws -> Bool {
@@ -51,7 +51,7 @@ extension CoreAPI {
5151
}
5252
let rulesRemoved = model.removePolicies(sec: sec, ptype: ptype, rules: rules)
5353
let eventData = EventData.RemovePolicies(sec, ptype, rules)
54-
return try afterOperatePolicy(sec: sec, oped: rulesRemoved, d: eventData, t: rulesRemoved)
54+
return try await afterOperatePolicy(sec: sec, oped: rulesRemoved, d: eventData, t: rulesRemoved)
5555
}
5656

5757
func removeFilteredPolicyInternal(sec: String, ptype: String, fieldIndex: Int, fieldValues: [String]) async throws -> (Bool,[[String]]) {
@@ -61,19 +61,17 @@ extension CoreAPI {
6161
}
6262
let (rolesRemoved, rules) = model.removeFilteredPolicy(sec: sec, ptype: ptype, fieldIndex: fieldIndex, fieldValues: fieldValues)
6363
let eventData = EventData.RemoveFilteredPolicy(sec, ptype, rules)
64-
return try afterOperatePolicy(sec: sec, oped: rolesRemoved, d: eventData, t: (rolesRemoved, rules))
64+
return try await afterOperatePolicy(sec: sec, oped: rolesRemoved, d: eventData, t: (rolesRemoved, rules))
6565
}
6666

67-
private func afterOperatePolicy<T>(sec: String, oped: Bool, d: EventData, t: T) throws -> T {
67+
private func afterOperatePolicy<T>(sec: String, oped: Bool, d: EventData, t: T) async throws -> T {
6868
if oped {
69-
emit(e: Event.PolicyChange, d: d)
70-
emit(e: Event.ClearCache, d: EventData.ClearCache)
71-
}
72-
if sec != "g" || !hasAutoBuildRoleLinksEnabled() {
73-
return t
69+
await emit(e: Event.PolicyChange, d: d)
70+
await emit(e: Event.ClearCache, d: EventData.ClearCache)
7471
}
72+
let needsBuild = hasAutoBuildRoleLinksEnabled()
73+
if sec != "g" || !needsBuild { return t }
7574
try buildIncrementalRoleLinks(eventData: d).get()
7675
return t
7776
}
7877
}
79-

Sources/Casbin/API/ManagementAPI.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
public extension CoreAPI {
15+
public extension Enforcer {
1616
//MARK: ManagementAPI
1717
func addNamedPolicy(ptype: String, params: [String]) async throws -> Bool {
1818
try await addPolicyInternal(sec: "p", ptype: ptype, rule: params)
@@ -111,7 +111,7 @@ public extension CoreAPI {
111111

112112
}
113113

114-
public extension CoreAPI {
114+
public extension Enforcer {
115115
func addPolicy(params: [String]) async throws -> Bool {
116116
try await addNamedPolicy(ptype: "p", params: params)
117117
}
@@ -176,4 +176,3 @@ public extension CoreAPI {
176176
}
177177

178178
}
179-

Sources/Casbin/API/RBACAPI.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
public extension CoreAPI {
15+
public extension Enforcer {
1616
func addPermission(for user: String, permission: [String]) async throws -> Bool {
1717
var perm = permission
1818
perm.insert(user, at: 0)
@@ -53,17 +53,10 @@ public extension CoreAPI {
5353
return try await removeFilteredGroupingPolicy(fieldIndex: 0, fieldValues: params)
5454
}
5555
func getRoles(for name:String,domain:String?) -> [String] {
56-
var roles:[String] = []
57-
if let ast = model.getModel()["g"]?["g"] {
58-
roles = ast.rm.getRoles(name: name, domain: domain)
59-
}
60-
return roles
56+
getRoleManager().getRoles(name: name, domain: domain)
6157
}
6258
func getUsers(for name:String,domain:String?) -> [String] {
63-
if let ast = model.getModel()["g"]?["g"] {
64-
return ast.rm.getUsers(name: name, domain: domain)
65-
}
66-
return []
59+
getRoleManager().getUsers(name: name, domain: domain)
6760
}
6861
func hasRole(for name:String,role:String,domain:String?) -> Bool {
6962
getRoles(for: name, domain: domain).contains(role)

Sources/Casbin/Adapter/MemoryAdapter.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ extension MemoryAdapter: Adapter {
3232
for line in policySet {
3333
let sec = line[0]
3434
let ptype = line[1]
35-
let rule = Array(line[1...])
36-
if let ast = m.getModel()[sec]?[ptype] {
37-
ast.policy.append(rule)
38-
}
35+
let ruleValues = Array(line.dropFirst(2))
36+
_ = m.addPolicy(sec: sec, ptype: ptype, rule: ruleValues)
3937
}
4038
}
4139
}
@@ -62,9 +60,8 @@ extension MemoryAdapter: Adapter {
6260
}
6361
}
6462
if !isFiltered {
65-
if let ast = m.getModel()[sec]?[ptype] {
66-
ast.policy.append(rule)
67-
}
63+
let ruleValues = Array(rule.dropFirst())
64+
_ = m.addPolicy(sec: sec, ptype: ptype, rule: ruleValues)
6865
} else {
6966
filtered.withLock { $0 = true }
7067
}

0 commit comments

Comments
 (0)