@@ 1966-2125 (lines=160) @@ | ||
1963 | api2.save(content2) |
|
1964 | transaction.commit() |
|
1965 | ||
1966 | def test_archive_unarchive(self): |
|
1967 | uapi = UserApi( |
|
1968 | session=self.session, |
|
1969 | config=self.app_config, |
|
1970 | current_user=None, |
|
1971 | ) |
|
1972 | group_api = GroupApi( |
|
1973 | current_user=None, |
|
1974 | session=self.session, |
|
1975 | config=self.app_config, |
|
1976 | ) |
|
1977 | groups = [group_api.get_one(Group.TIM_USER), |
|
1978 | group_api.get_one(Group.TIM_MANAGER), |
|
1979 | group_api.get_one(Group.TIM_ADMIN)] |
|
1980 | ||
1981 | user1 = uapi.create_minimal_user( |
|
1982 | email='this.is@user', |
|
1983 | groups=groups, |
|
1984 | save_now=True |
|
1985 | ) |
|
1986 | u1id = user1.user_id |
|
1987 | ||
1988 | workspace_api = WorkspaceApi( |
|
1989 | current_user=user1, |
|
1990 | session=self.session, |
|
1991 | config=self.app_config, |
|
1992 | ) |
|
1993 | workspace = workspace_api.create_workspace( |
|
1994 | 'test workspace', |
|
1995 | save_now=True |
|
1996 | ) |
|
1997 | wid = workspace.workspace_id |
|
1998 | ||
1999 | user2 = uapi.create_minimal_user('[email protected]') |
|
2000 | uapi.save(user2) |
|
2001 | ||
2002 | RoleApi( |
|
2003 | current_user=user1, |
|
2004 | session=self.session, |
|
2005 | config=self.app_config, |
|
2006 | ).create_one( |
|
2007 | user2, |
|
2008 | workspace, |
|
2009 | UserRoleInWorkspace.CONTENT_MANAGER, |
|
2010 | with_notif=True, |
|
2011 | flush=True |
|
2012 | ) |
|
2013 | ||
2014 | # show archived is used at the top end of the test |
|
2015 | api = ContentApi( |
|
2016 | current_user=user1, |
|
2017 | session=self.session, |
|
2018 | show_archived=True, |
|
2019 | config=self.app_config, |
|
2020 | ) |
|
2021 | p = api.create( |
|
2022 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2023 | workspace=workspace, |
|
2024 | parent=None, |
|
2025 | label='this_is_a_page', |
|
2026 | do_save=True |
|
2027 | ) |
|
2028 | ||
2029 | u1id = user1.user_id |
|
2030 | u2id = user2.user_id |
|
2031 | pcid = p.content_id |
|
2032 | poid = p.owner_id |
|
2033 | ||
2034 | transaction.commit() |
|
2035 | ||
2036 | #### |
|
2037 | ||
2038 | # refresh after commit |
|
2039 | user1 = UserApi( |
|
2040 | current_user=None, |
|
2041 | config=self.app_config, |
|
2042 | session=self.session |
|
2043 | ).get_one(u1id) |
|
2044 | workspace = WorkspaceApi( |
|
2045 | current_user=user1, |
|
2046 | session=self.session, |
|
2047 | config=self.app_config, |
|
2048 | ).get_one(wid) |
|
2049 | ||
2050 | content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2051 | eq_(u1id, content.owner_id) |
|
2052 | eq_(poid, content.owner_id) |
|
2053 | ||
2054 | u2api = UserApi( |
|
2055 | session=self.session, |
|
2056 | config=self.app_config, |
|
2057 | current_user=None, |
|
2058 | ) |
|
2059 | u2 = u2api.get_one(u2id) |
|
2060 | api2 = ContentApi( |
|
2061 | current_user=u2, |
|
2062 | session=self.session, |
|
2063 | config=self.app_config, |
|
2064 | show_archived=True, |
|
2065 | ) |
|
2066 | content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2067 | with new_revision( |
|
2068 | session=self.session, |
|
2069 | tm=transaction.manager, |
|
2070 | content=content2, |
|
2071 | ): |
|
2072 | api2.archive(content2) |
|
2073 | api2.save(content2) |
|
2074 | transaction.commit() |
|
2075 | ||
2076 | # refresh after commit |
|
2077 | user1 = UserApi( |
|
2078 | current_user=None, |
|
2079 | session=self.session, |
|
2080 | config=self.app_config, |
|
2081 | ).get_one(u1id) |
|
2082 | workspace = WorkspaceApi( |
|
2083 | current_user=user1, |
|
2084 | session=self.session, |
|
2085 | config=self.app_config, |
|
2086 | ).get_one(wid) |
|
2087 | u2 = UserApi( |
|
2088 | current_user=None, |
|
2089 | session=self.session, |
|
2090 | config=self.app_config, |
|
2091 | ).get_one(u2id) |
|
2092 | api = ContentApi( |
|
2093 | current_user=user1, |
|
2094 | session=self.session, |
|
2095 | config=self.app_config, |
|
2096 | show_archived=True, |
|
2097 | ) |
|
2098 | api2 = ContentApi( |
|
2099 | current_user=u2, |
|
2100 | session=self.session, |
|
2101 | config=self.app_config, |
|
2102 | show_archived=True, |
|
2103 | ) |
|
2104 | ||
2105 | updated = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2106 | eq_(u2id, updated.owner_id, |
|
2107 | 'the owner id should be {} (found {})'.format(u2id, |
|
2108 | updated.owner_id)) |
|
2109 | eq_(True, updated.is_archived) |
|
2110 | eq_(ActionDescription.ARCHIVING, updated.revision_type) |
|
2111 | ||
2112 | #### |
|
2113 | ||
2114 | updated2 = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2115 | with new_revision( |
|
2116 | session=self.session, |
|
2117 | tm=transaction.manager, |
|
2118 | content=updated, |
|
2119 | ||
2120 | ): |
|
2121 | api.unarchive(updated) |
|
2122 | api.save(updated2) |
|
2123 | eq_(False, updated2.is_archived) |
|
2124 | eq_(ActionDescription.UNARCHIVING, updated2.revision_type) |
|
2125 | eq_(u1id, updated2.owner_id) |
|
2126 | ||
2127 | def test_delete_undelete(self): |
|
2128 | uapi = UserApi( |
|
@@ 2127-2284 (lines=158) @@ | ||
2124 | eq_(ActionDescription.UNARCHIVING, updated2.revision_type) |
|
2125 | eq_(u1id, updated2.owner_id) |
|
2126 | ||
2127 | def test_delete_undelete(self): |
|
2128 | uapi = UserApi( |
|
2129 | session=self.session, |
|
2130 | config=self.app_config, |
|
2131 | current_user=None, |
|
2132 | ) |
|
2133 | group_api = GroupApi( |
|
2134 | current_user=None, |
|
2135 | session=self.session, |
|
2136 | config=self.app_config, |
|
2137 | ) |
|
2138 | groups = [group_api.get_one(Group.TIM_USER), |
|
2139 | group_api.get_one(Group.TIM_MANAGER), |
|
2140 | group_api.get_one(Group.TIM_ADMIN)] |
|
2141 | ||
2142 | user1 = uapi.create_minimal_user( |
|
2143 | email='this.is@user', |
|
2144 | groups=groups, |
|
2145 | save_now=True |
|
2146 | ) |
|
2147 | u1id = user1.user_id |
|
2148 | ||
2149 | workspace_api = WorkspaceApi( |
|
2150 | current_user=user1, |
|
2151 | session=self.session, |
|
2152 | config=self.app_config, |
|
2153 | ) |
|
2154 | workspace = workspace_api.create_workspace( |
|
2155 | 'test workspace', |
|
2156 | save_now=True |
|
2157 | ) |
|
2158 | wid = workspace.workspace_id |
|
2159 | ||
2160 | user2 = uapi.create_minimal_user('[email protected]') |
|
2161 | uapi.save(user2) |
|
2162 | ||
2163 | RoleApi( |
|
2164 | current_user=user1, |
|
2165 | session=self.session, |
|
2166 | config=self.app_config, |
|
2167 | ).create_one( |
|
2168 | user2, |
|
2169 | workspace, |
|
2170 | UserRoleInWorkspace.CONTENT_MANAGER, |
|
2171 | with_notif=True, |
|
2172 | flush=True |
|
2173 | ) |
|
2174 | ||
2175 | # show archived is used at the top end of the test |
|
2176 | api = ContentApi( |
|
2177 | current_user=user1, |
|
2178 | session=self.session, |
|
2179 | config=self.app_config, |
|
2180 | show_deleted=True, |
|
2181 | ) |
|
2182 | p = api.create( |
|
2183 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2184 | workspace=workspace, |
|
2185 | parent=None, |
|
2186 | label='this_is_a_page', |
|
2187 | do_save=True |
|
2188 | ) |
|
2189 | ||
2190 | u1id = user1.user_id |
|
2191 | u2id = user2.user_id |
|
2192 | pcid = p.content_id |
|
2193 | poid = p.owner_id |
|
2194 | ||
2195 | transaction.commit() |
|
2196 | ||
2197 | #### |
|
2198 | user1 = UserApi( |
|
2199 | current_user=None, |
|
2200 | session=self.session, |
|
2201 | config=self.app_config, |
|
2202 | ).get_one(u1id) |
|
2203 | workspace = WorkspaceApi( |
|
2204 | current_user=user1, |
|
2205 | session=self.session, |
|
2206 | config=self.app_config, |
|
2207 | ).get_one(wid) |
|
2208 | ||
2209 | content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2210 | eq_(u1id, content.owner_id) |
|
2211 | eq_(poid, content.owner_id) |
|
2212 | ||
2213 | u2 = UserApi( |
|
2214 | current_user=None, |
|
2215 | session=self.session, |
|
2216 | config=self.app_config, |
|
2217 | ).get_one(u2id) |
|
2218 | api2 = ContentApi( |
|
2219 | current_user=u2, |
|
2220 | session=self.session, |
|
2221 | config=self.app_config, |
|
2222 | show_deleted=True, |
|
2223 | ) |
|
2224 | content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2225 | with new_revision( |
|
2226 | session=self.session, |
|
2227 | tm=transaction.manager, |
|
2228 | content=content2, |
|
2229 | ): |
|
2230 | api2.delete(content2) |
|
2231 | api2.save(content2) |
|
2232 | transaction.commit() |
|
2233 | ||
2234 | #### |
|
2235 | ||
2236 | user1 = UserApi( |
|
2237 | current_user=None, |
|
2238 | session=self.session, |
|
2239 | config=self.app_config, |
|
2240 | ).get_one(u1id) |
|
2241 | workspace = WorkspaceApi( |
|
2242 | current_user=user1, |
|
2243 | session=self.session, |
|
2244 | config=self.app_config, |
|
2245 | ).get_one(wid) |
|
2246 | # show archived is used at the top end of the test |
|
2247 | api = ContentApi( |
|
2248 | current_user=user1, |
|
2249 | session=self.session, |
|
2250 | config=self.app_config, |
|
2251 | show_deleted=True, |
|
2252 | ) |
|
2253 | u2 = UserApi( |
|
2254 | current_user=None, |
|
2255 | session=self.session, |
|
2256 | config=self.app_config, |
|
2257 | ).get_one(u2id) |
|
2258 | api2 = ContentApi( |
|
2259 | current_user=u2, |
|
2260 | session=self.session, |
|
2261 | config=self.app_config, |
|
2262 | show_deleted=True |
|
2263 | ) |
|
2264 | ||
2265 | updated = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2266 | eq_(u2id, updated.owner_id, |
|
2267 | 'the owner id should be {} (found {})'.format(u2id, |
|
2268 | updated.owner_id)) |
|
2269 | eq_(True, updated.is_deleted) |
|
2270 | eq_(ActionDescription.DELETION, updated.revision_type) |
|
2271 | ||
2272 | #### |
|
2273 | ||
2274 | updated2 = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
|
2275 | with new_revision( |
|
2276 | tm=transaction.manager, |
|
2277 | session=self.session, |
|
2278 | content=updated2, |
|
2279 | ): |
|
2280 | api.undelete(updated2) |
|
2281 | api.save(updated2) |
|
2282 | eq_(False, updated2.is_deleted) |
|
2283 | eq_(ActionDescription.UNDELETION, updated2.revision_type) |
|
2284 | eq_(u1id, updated2.owner_id) |
|
2285 | ||
2286 | def test_unit__get_last_active__ok__nominal_case(self): |
|
2287 | uapi = UserApi( |